ansible 部署 elk 集群
Posted 开拓者云计算实验室
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ansible 部署 elk 集群相关的知识,希望对你有一定的参考价值。
一、安装ansible 1) 配置自己的yum 源 [root@node-4 ~]# cat /etc/yum.repos.d/local.repo [centos] name=centos baseurl= http://192.168.100.20/openstack/centos gpgcheck=0 enabeld=1 [ansible] name=ansible gpgcheck=0 enabled=1 baseurl= http://192.168.100.20/openstack/ansible 2) 下载ansible 修改配置 [root@node-4 ~]# vi /etc/ansible/hosts [node_1] node1 node_name=node1 [node_2] node2 node_name=node2 [node_3] node3 node_name=node3 [root@node-4 ~]# ansible all -m ping node2 | SUCCESS => "ansible_facts": "discovered_interpreter_python": "/usr/bin/python" , "changed": false, "ping": "pong" node3 | SUCCESS => "ansible_facts": "discovered_interpreter_python": "/usr/bin/python" , "changed": false, "ping": "pong" node1 | SUCCESS => "ansible_facts": "discovered_interpreter_python": "/usr/bin/python" , "changed": false, "ping": "pong" 3) 创建部署的目录 [root@node-4 ~]# mkdir install_elk [root@node-4 ~]# cd install_elk/ [root@node-4 install_elk]# mkdir -p roles/elk,kibana,logstash/tasks,files,templates,vars 二、编写role 1) 搭建elasticserch [root@node-4 install_elk]# tree roles/ roles/ ├── elk │ ├── files │ │ ├── elasticsearch-6.0.0.rpm │ │ ├── hosts │ │ ├── limits.conf │ │ ├── local.repo │ │ └── sysctl.conf │ ├── tasks │ │ └── main.yaml │ ├── templates │ │ └── elasticsearch.yml.j2 │ └── vars ├── kibana │ ├── files │ │ ├── kibana-6.0.0-x86_64.rpm │ │ └── kibana.yml │ ├── tasks │ │ └── main.yaml │ ├── templates │ └── vars └── logstash ├── files │ ├── logstash-6.0.0.rpm │ ├── logstash.service │ ├── logstash.yml │ └── test.conf ├── tasks │ └── main.yaml ├── templates └── vars 15 directories, 15 files root@node-4 ~]# cd install_elk/roles/elk/files/ [root@node-4 files]# cp /etc/hosts . [root@node-4 files]# cp /etc/yum.repos.d/local.repo . [root@node-4 files]# cp /etc/security/limits.conf . [root@node-4 files]# cp /etc/sysctl.conf . [root@node-4 files]# cp /root/elasticsearch-6.0.0.rpm . [root@node-4 files]# ls elasticsearch-6.0.0.rpm hosts limits.conf local.repo sysctl.conf #这里 我提前下载了 下 elastcisearch 的包 [root@node-4 files]# mv /etc/elasticsearch/elasticsearch.yml ../templates/elasticsearch.yml.j2 [root@node-4 roles]# cat elk/templates/elasticsearch.yml.j2 cluster.name: my-application node.name: node_name path.data: /var/lib/elasticsearch path.logs: /var/log/elasticsearch network.host: 0.0.0.0 http.port: 9200 discovery.zen.ping.unicast.hosts: ["node1","node2","node3"] discovery.zen.minimum_master_nodes: 2 [root@node-4 elk]# vi tasks/main.yaml [root@node-4 elk]# vi tasks/main.yaml - name: stop selinux shell: setenforce 0 - name: rm repo shell: rm -rf /etc/yum.repos.d/* - name: cp hosts copy: src=hosts dest=/etc - name: cp local.repo copy: src=local.repo dest=/etc/yum.repos.d/ - name: cp limit.conf copy: src=limit.conf dest=/etc/security/ - name: cp sysctl.con copy: src=sysctl.conf dest=/etc/ - name: shell sysctl shell: sysctl -p - name: yum java shell: yum -y install java-1.8.0-openjdk java-1.8.0-openjdk-devel - name: cp elk copy: src=elasticsearch-6.0.0.rpm dest=/root/ - name: yum elk yum: name=/root/elasticsearch-6.0.0.rpm - name: copy elk.conf template: src=elasticsearch.yml.j2 dest=/etc/elasticsearch/elasticsearch.yml - name: start elk shell: systemctl restart elasticsearch [root@node-4 install_elk]# cat roles/elk/files/limits.conf * soft nofile 65536 #这里仅显示最后部分 (在最后添加 这两个) * hard nofile 65536 [root@node-4 files]# cat sysctl.conf # sysctl settings are defined through files in # /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/. # # Vendors settings live in /usr/lib/sysctl.d/. # To override a whole file, create a new file with the same in # /etc/sysctl.d/ and put new settings there. To override # only specific settings, add a file with a lexically later # name in /etc/sysctl.d/ and put new settings there. # # For more information, see sysctl.conf(5) and sysctl.d(5). vm.max_map_count = 262144 2) 编写logstash [root@node-4 roles]# cat logstash/files/logstash.service [Unit] Description=logstash [Service] ExecStart=/usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/ ExecReload=/bin/kill -HUP $MAINPID KillMode=process #Restart=on-failure [Install] WantedBy=multi-user.target [root@node-4 roles]# cat logstash/files/logstash.yml pipeline: batch: size: 125 delay: 5 path.data: /var/lib/logstash path.config: /etc/logstash/conf.d/*.conf http.host: "0.0.0.0" http.port: 9600-9700 log.level: info path.logs: /var/log/logstash [root@node-4 roles]# cat logstash/files/test.conf # 注意缩进 [root@node-4 roles]# cat logstash/files/test.conf input file path => "/var/log/messages" start_position => "beginning" output elasticsearch hosts => ["177.16.1.113:9200"] index => "amessage-%+YYYY.MM.dd" [root@node-4 roles]# cat logstash/tasks/main.yaml - name: cp logstash copy: src=logstash-6.0.0.rpm dest=/root/ - name: yum logstash-6.0.0.rpm yum: name=/root/logstash-6.0.0.rpm - name: cp test.conf copy: src=test.conf dest=/etc/logstash/conf.d/ - name: cp logstash.yml copy: src=logstash.yml dest=/etc/logstash/ - name: cp service copy: src=logstash.service dest=/etc/systemd/system/ - name: start logstash shell: systemctl daemon-reload && systemctl restart logstash 3) 编写kibana [root@node-4 roles]# cat kibana/files/kibana.yml server.port: 5601 server.host: "0.0.0.0" elasticsearch.url: "http://177.16.1.113:9200" [root@node-4 roles]# cat kibana/tasks/main.yaml - name: cp kibana-6.0.0-x86_64.rpm copy: src=kibana-6.0.0-x86_64.rpm dest=/root - name: yum kibana-6.0.0-x86_64.rpm yum: name=kibana-6.0.0-x86_64.rpm - name: cp kibana.yml copy: src=kibana.yml dest=/etc/kibana/ - name: start kibana shell: systemctl restart kibana 三、编写出口加运行结果 [root@node-4 install_elk]# vi install_elk.yaml --- - hosts: all remote_user: root roles: - elk - hosts: node_1 remote_user: root roles: - kibana - hosts: node_2 remote_user: root roles: - logstash [root@node-4 install_elk]# ansible-playbook install_elk.yaml PLAY [all] ********************************************************************* TASK [Gathering Facts] ********************************************************* ok: [node2] ok: [node3] ok: [node1] TASK [elk : stop selinux] ****************************************************** changed: [node2] changed: [node3] changed: [node1] TASK [elk : rm repo] ********************************************************** changed: [node2] changed: [node3] changed: [node1] TASK [elk : cp hosts] ********************************************************** ok: [node2] ok: [node3] ok: [node1] TASK [elk : cp local.repo] ***************************************************** changed: [node2] changed: [node1] changed: [node3] TASK [elk : cp limits.conf] **************************************************** ok: [node2] ok: [node3] ok: [node1] TASK [elk : cp sysctl.con] ***************************************************** ok: [node2] ok: [node3] ok: [node1] TASK [elk : shell sysctl] ****************************************************** changed: [node3] changed: [node2] changed: [node1] TASK [elk : yum java] ********************************************************** changed: [node2] changed: [node3] changed: [node1] TASK [cp elk] ****************************************************************** ok: [node2] ok: [node3] ok: [node1] TASK [yum elk] ***************************************************************** ok: [node2] ok: [node1] ok: [node3] TASK [copy elk.conf] *********************************************************** ok: [node2] ok: [node3] ok: [node1] TASK [start elk] *************************************************************** changed: [node3] changed: [node1] changed: [node2] PLAY [node_1] ****************************************************************** TASK [Gathering Facts] ********************************************************* ok: [node1] TASK [cp kibana-6.0.0-x86_64.rpm] ********************************************** ok: [node1] TASK [yum kibana-6.0.0-x86_64.rpm] ********************************************* ok: [node1] TASK [cp kibana.yml] *********************************************************** ok: [node1] TASK [start kibana] ************************************************************ changed: [node1] PLAY [node_2] ****************************************************************** TASK [Gathering Facts] ********************************************************* ok: [node2] TASK [cp logstash] ************************************************************* ok: [node2] TASK [yum logstash-6.0.0.rpm] ************************************************** ok: [node2] TASK [logstash : cp test.conf] ************************************************* ok: [node2] TASK [cp logstash.yml] ********************************************************* ok: [node2] TASK [logstash : cp service] *************************************************** ok: [node2] TASK [start logstash] ********************************************************** changed: [node2] PLAY RECAP ********************************************************************* node1 : ok=18 changed=7 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 node2 : ok=20 changed=7 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0 node3 : ok=13 changed=6 unreachable=0 failed=0 skipped=0 rescued=0 ignored=0到这里就结束了 感谢大家的观看 你们的点赞是我们最大的动力
编辑:开拓者-陈果
审核:开拓者-少伟
以上是关于ansible 部署 elk 集群的主要内容,如果未能解决你的问题,请参考以下文章
ELFK Filebeat+ELK 部署 zookeeper集群+kafka集群 部署