小言_互联网的博客

Elastic:如何使用 Ansible自动化部署 Elastic Stack - Kibana(三)

481人阅读  评论(0)

在之前的文章 “如何使用 Ansible自动化部署 Elastic Stack () 及 ()”,我分别描述了如何使用 Ansible 来自动部署一个 Webserver 及 Elasticsearch。在今天的教程中,我来介绍如何安装 Kibana。如果你还没做完之前的练习,请先做那些练习。

 

部署 Kibana

和之前的安装部署步骤一样,我们先创建一个叫做 kibana 的角色:


  
  1. $ pwd
  2. /Users/liuxg/ansible/elasticsearch/roles
  3. $ ansible-galaxy init kibana
  4. - Role kibana was created successfully

如果你从来还没有安装过 Kibana,请参考我之前的文章  “如何在 Linux,MacOS 及 Windows 上安装 Elastic 栈中的 Kibana” 进行本地安装。你可以把 Kibana 安装到一个本地的目录中。这个安装的目的是为了拷贝它的 config/kibana.yml 文件。我们将以这个文件为蓝本进行对部署的 Kibana 进行个性化的配置。我们把 kibana.yml 文件拷入到 kibana/template 目录下:

我最原始的 kibana.yml 文件如下:

templates/kibana.yml


  
  1. # Kibana is served by a back end server. This setting specifies the port to use.
  2. server.port: 5601
  3. # Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
  4. # The default is 'localhost', which usually means remote machines will not be able to connect.
  5. # To allow connections from remote users, set this parameter to a non-loopback address.
  6. server.host: "0.0.0.0"
  7. # Enables you to specify a path to mount Kibana at if you are running behind a proxy.
  8. # Use the `server.rewriteBasePath` setting to tell Kibana if it should remove the basePath
  9. # from requests it receives, and to prevent a deprecation warning at startup.
  10. # This setting cannot end in a slash.
  11. #server.basePath: ""
  12. # Specifies whether Kibana should rewrite requests that are prefixed with
  13. # `server.basePath` or require that they are rewritten by your reverse proxy.
  14. # This setting was effectively always `false` before Kibana 6.3 and will
  15. # default to `true` starting in Kibana 7.0.
  16. #server.rewriteBasePath: false
  17. # The maximum payload size in bytes for incoming server requests.
  18. #server.maxPayloadBytes: 1048576
  19. # The Kibana server's name. This is used for display purposes.
  20. server.name: "demo-kibana"
  21. # The URLs of the Elasticsearch instances to use for all your queries.
  22. elasticsearch.hosts: [ "http://localhost:9200"]
  23. # Kibana uses an index in Elasticsearch to store saved searches, visualizations and
  24. # dashboards. Kibana creates a new index if the index doesn't already exist.
  25. #kibana.index: ".kibana"
  26. # The default application to load.
  27. #kibana.defaultAppId: "home"
  28. # If your Elasticsearch is protected with basic authentication, these settings provide
  29. # the username and password that the Kibana server uses to perform maintenance on the Kibana
  30. # index at startup. Your Kibana users still need to authenticate with Elasticsearch, which
  31. # is proxied through the Kibana server.
  32. elasticsearch.username: "kibana_system"
  33. elasticsearch.password: "password"
  34. # Enables SSL and paths to the PEM-format SSL certificate and SSL key files, respectively.
  35. # These settings enable SSL for outgoing requests from the Kibana server to the browser.
  36. #server.ssl.enabled: false
  37. #server.ssl.certificate: /path/to/your/server.crt
  38. #server.ssl.key: /path/to/your/server.key
  39. # Optional settings that provide the paths to the PEM-format SSL certificate and key files.
  40. # These files are used to verify the identity of Kibana to Elasticsearch and are required when
  41. # xpack.security.http.ssl.client_authentication in Elasticsearch is set to required.
  42. #elasticsearch.ssl.certificate: /path/to/your/client.crt
  43. #elasticsearch.ssl.key: /path/to/your/client.key
  44. # Optional setting that enables you to specify a path to the PEM file for the certificate
  45. # authority for your Elasticsearch instance.
  46. #elasticsearch.ssl.certificateAuthorities: [ "/path/to/your/CA.pem" ]
  47. # To disregard the validity of SSL certificates, change this setting's value to 'none'.
  48. #elasticsearch.ssl.verificationMode: full
  49. # Time in milliseconds to wait for Elasticsearch to respond to pings. Defaults to the value of
  50. # the elasticsearch.requestTimeout setting.
  51. #elasticsearch.pingTimeout: 1500
  52. # Time in milliseconds to wait for responses from the back end or Elasticsearch. This value
  53. # must be a positive integer.
  54. #elasticsearch.requestTimeout: 30000
  55. # List of Kibana client-side headers to send to Elasticsearch. To send *no* client-side
  56. # headers, set this value to [] (an empty list).
  57. #elasticsearch.requestHeadersWhitelist: [ authorization ]
  58. # Header names and values that are sent to Elasticsearch. Any custom headers cannot be overwritten
  59. # by client-side headers, regardless of the elasticsearch.requestHeadersWhitelist configuration.
  60. #elasticsearch.customHeaders: {}
  61. # Time in milliseconds for Elasticsearch to wait for responses from shards. Set to 0 to disable.
  62. #elasticsearch.shardTimeout: 30000
  63. # Logs queries sent to Elasticsearch. Requires logging.verbose set to true.
  64. #elasticsearch.logQueries: false
  65. # Specifies the path where Kibana creates the process ID file.
  66. #pid.file: /var/run/kibana.pid
  67. # Enables you to specify a file where Kibana stores log output.
  68. #logging.dest: stdout
  69. # Set the value of this setting to true to suppress all logging output.
  70. #logging.silent: false
  71. # Set the value of this setting to true to suppress all logging output other than error messages.
  72. #logging.quiet: false
  73. # Set the value of this setting to true to log all events, including system usage information
  74. # and all requests.
  75. #logging.verbose: false
  76. # Set the interval in milliseconds to sample system and process performance
  77. # metrics. Minimum is 100ms. Defaults to 5000.
  78. #ops.interval: 5000
  79. # Specifies locale to be used for all localizable strings, dates and number formats.
  80. # Supported languages are the following: English - en , by default , Chinese - zh-CN .
  81. #i18n.locale: "en"

显然在上面的配置中,有很多都是固定的值。我们可以把我们需要配置的项挑出来,并在 defaults/main.yml 中做相应的变量定义:

有了上面的变量的定义,我们可以修改我们的 templates/main.yml 如下:

templates/main.yml


  
  1. # Kibana is served by a back end server. This setting specifies the port to use.
  2. server.port: {{ server_port }}
  3. # Specifies the address to which the Kibana server will bind. IP addresses and host names are both valid values.
  4. # The default is 'localhost', which usually means remote machines will not be able to connect.
  5. # To allow connections from remote users, set this parameter to a non-loopback address.
  6. server.host: "{{ server_host }}"
  7. # Enables you to specify a path to mount Kibana at if you are running behind a proxy.
  8. # Use the `server.rewriteBasePath` setting to tell Kibana if it should remove the basePath
  9. # from requests it receives, and to prevent a deprecation warning at startup.
  10. # This setting cannot end in a slash.
  11. #server.basePath: ""
  12. # Specifies whether Kibana should rewrite requests that are prefixed with
  13. # `server.basePath` or require that they are rewritten by your reverse proxy.
  14. # This setting was effectively always `false` before Kibana 6.3 and will
  15. # default to `true` starting in Kibana 7.0.
  16. #server.rewriteBasePath: false
  17. # The maximum payload size in bytes for incoming server requests.
  18. #server.maxPayloadBytes: 1048576
  19. # The Kibana server's name. This is used for display purposes.
  20. server.name: "{{ server_name }}"
  21. # The URLs of the Elasticsearch instances to use for all your queries.
  22. elasticsearch.hosts: [ "{{ elasticsearch_host }}"]
  23. # Kibana uses an index in Elasticsearch to store saved searches, visualizations and
  24. # dashboards. Kibana creates a new index if the index doesn't already exist.
  25. #kibana.index: ".kibana"
  26. # The default application to load.
  27. #kibana.defaultAppId: "home"
  28. # If your Elasticsearch is protected with basic authentication, these settings provide
  29. # the username and password that the Kibana server uses to perform maintenance on the Kibana
  30. # index at startup. Your Kibana users still need to authenticate with Elasticsearch, which
  31. # is proxied through the Kibana server.
  32. elasticsearch.username: "kibana_system"
  33. elasticsearch.password: "password"
  34. # Enables SSL and paths to the PEM-format SSL certificate and SSL key files, respectively.
  35. # These settings enable SSL for outgoing requests from the Kibana server to the browser.
  36. #server.ssl.enabled: false
  37. #server.ssl.certificate: /path/to/your/server.crt
  38. #server.ssl.key: /path/to/your/server.key
  39. # Optional settings that provide the paths to the PEM-format SSL certificate and key files.
  40. # These files are used to verify the identity of Kibana to Elasticsearch and are required when
  41. # xpack.security.http.ssl.client_authentication in Elasticsearch is set to required.
  42. #elasticsearch.ssl.certificate: /path/to/your/client.crt
  43. #elasticsearch.ssl.key: /path/to/your/client.key
  44. # Optional setting that enables you to specify a path to the PEM file for the certificate
  45. # authority for your Elasticsearch instance.
  46. #elasticsearch.ssl.certificateAuthorities: [ "/path/to/your/CA.pem" ]
  47. # To disregard the validity of SSL certificates, change this setting's value to 'none'.
  48. #elasticsearch.ssl.verificationMode: full
  49. # Time in milliseconds to wait for Elasticsearch to respond to pings. Defaults to the value of
  50. # the elasticsearch.requestTimeout setting.
  51. #elasticsearch.pingTimeout: 1500
  52. # Time in milliseconds to wait for responses from the back end or Elasticsearch. This value
  53. # must be a positive integer.
  54. #elasticsearch.requestTimeout: 30000
  55. # List of Kibana client-side headers to send to Elasticsearch. To send *no* client-side
  56. # headers, set this value to [] (an empty list).
  57. #elasticsearch.requestHeadersWhitelist: [ authorization ]
  58. # Header names and values that are sent to Elasticsearch. Any custom headers cannot be overwritten
  59. # by client-side headers, regardless of the elasticsearch.requestHeadersWhitelist configuration.
  60. #elasticsearch.customHeaders: {}
  61. # Time in milliseconds for Elasticsearch to wait for responses from shards. Set to 0 to disable.
  62. #elasticsearch.shardTimeout: 30000
  63. # Logs queries sent to Elasticsearch. Requires logging.verbose set to true.
  64. #elasticsearch.logQueries: false
  65. # Specifies the path where Kibana creates the process ID file.
  66. #pid.file: /var/run/kibana.pid
  67. # Enables you to specify a file where Kibana stores log output.
  68. #logging.dest: stdout
  69. # Set the value of this setting to true to suppress all logging output.
  70. #logging.silent: false
  71. # Set the value of this setting to true to suppress all logging output other than error messages.
  72. #logging.quiet: false
  73. # Set the value of this setting to true to log all events, including system usage information
  74. # and all requests.
  75. #logging.verbose: false
  76. # Set the interval in milliseconds to sample system and process performance
  77. # metrics. Minimum is 100ms. Defaults to 5000.
  78. #ops.interval: 5000
  79. # Specifies locale to be used for all localizable strings, dates and number formats.
  80. # Supported languages are the following: English - en , by default , Chinese - zh-CN .
  81. #i18n.locale: "en"

接下来,我们在 tasks/main.yml 里创建我们的任务:

tasks/main.yml


  
  1. ---
  2. # tasks file for kibana
  3. # Installing Kibana
  4. - name: Installing Kibana with apt
  5. apt:
  6. name: kibana
  7. update_cache: yes
  8. # Replacing default kibana.yml with updated file
  9. - name: Replacing default kibana.yml with updated file
  10. template:
  11. src: kibana.yml
  12. dest: /etc/kibana/kibana.yml
  13. # Starting Kibana
  14. - name: Starting Kibana
  15. service:
  16. name: kibana
  17. state: started
  18. enabled: yes

我们接下来修改 deploy-demo.yml 文件:

playbooks/deploy-demo.yml


  
  1. ---
  2. # This playbook will deploy webserver
  3. - hosts: all
  4. become: yes
  5. roles:
  6. - ../roles/add-elastic-repo
  7. # This playbook will deploy ELK stack
  8. - hosts: elk
  9. become: yes
  10. roles:
  11. - ../roles/elasticsearch
  12. - ../roles/kibana

我们使用如下的命令来进行部署:

ansible-playbook -K -i inventory/hosts.yml playbooks/deploy-demo.yml

  
  1. $ pwd
  2. /Users/liuxg/ansible/elasticsearch
  3. $ ansible-playbook -K -i inventory/hosts.yml playbooks/deploy-demo.yml
  4. BECOME password:
  5. PLAY [all] **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** *
  6. TASK [Gathering Facts] *********************************************************
  7. ok: [192.168.0.4]
  8. TASK [../roles/add-elastic-repo : add elasticsearch public signing key] **** ****
  9. ok: [192.168.0.4]
  10. TASK [../roles/add-elastic-repo : Install apt-transport-https] **** **** **** **** *
  11. ok: [192.168.0.4]
  12. TASK [../roles/add-elastic-repo : Add elasticsearch repo definitions] **********
  13. ok: [192.168.0.4]
  14. TASK [../roles/add-elastic-repo : system update] ** **** **** **** **** **** **** *****
  15. changed: [192.168.0.4]
  16. PLAY [elk] **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** *
  17. TASK [Gathering Facts] *********************************************************
  18. ok: [192.168.0.4]
  19. TASK [../roles/elasticsearch : Installing Elasticsearch] **** **** **** **** **** ***
  20. ok: [192.168.0.4]
  21. TASK [../roles/elasticsearch : Replace default elasticsearch.yml] **************
  22. ok: [192.168.0.4]
  23. TASK [../roles/elasticsearch : service] ****************************************
  24. ok: [192.168.0.4]
  25. TASK [../roles/kibana : Installing Kibana with apt] ****************************
  26. ok: [192.168.0.4]
  27. TASK [../roles/kibana : Replacing default kibana.yml with updated file] ********
  28. changed: [192.168.0.4]
  29. TASK [../roles/kibana : Starting Kibana] ***************************************
  30. changed: [192.168.0.4]
  31. PLAY RECAP ** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ***
  32. 192.168.0.4 : ok=12 changed=3 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0

上面的输出结果显示我们的安装是成功的。我们在 MacOS 的浏览器中打入如下的地址 ubuntu:5601。

上面显示我们的安装是成功的。我们也可以到 Ubuntu 的机器上进入查看:

service kibana status

上面显示 kibana 服务已经被成功运行起来了。


转载:https://blog.csdn.net/UbuntuTouch/article/details/113132041
查看评论
* 以上用户言论只代表其个人观点,不代表本网站的观点或立场