ES集群搭建
实验搭建思路:
-
首先在自己的宿主机下载好相关安装包,利用ftp服务搭建好网络yum源。 虚拟机搭建yum源的时候指向宿主机网络yum源。 利用自己创建的虚拟机后端模板,创建5台虚拟机。分别配置好ip,主机名。
-
先在192.168.5.21安装第一台ES服务器,为了提高部署速度。
-
然后在192.168.5.21安装ansible批量工具,利用ansible编写playbook批量部署ES集群。
-
利用copy,yum模块即可。编写playbook格式可借助ansible-doc。修改要点即可 编写的时候注意缩进,和空格。
-
查找copy,yum格式:ansible-doc yum ansible-doc copy
第1台主机ES环境准备
操作思路
- 设置主机名称和ip对应关系,,
- 设置/etc/hosts文件
- 安装软件包
- 修改配置文件
- 启动服务
- 检查服务
对应的ip和主机名,设置/etc/hosts文件(每台主机都需要)
192.168.5.21 es1
192.168.5.22 es2
192.168.5.23 es3
192.168.5.24 es4
192.168.5.25 es5
[root@es1 ~]# yum list |grep jdk
java-1.8.0-openjdk.x86_64
[root@es1 ~]# yum -y install java-1.8.0-openjdk.x86_64
[root@es1 ~]# yum -y install elasticsearch
[root@es1 ~]# vim /etc/elasticsearch/elasticsearch.yml
17 cluster.name: testcluster #集群名称
23 node.name: es1 #本机的名字
54 network.host: 0.0.0.0 #网络,可以通过网络访问你,添写本机ip,0.0.0.0也可以。
68 discovery.zen.ping.unicast.hosts: [“es1”, “es2”, “es3”, ] #集群成员
:wq
[root@es1 ~]# systemctl restart elasticsearch
[root@es1 ~]#ss -nutlp
users:((“java”,pid=7721,fd=215)) :::9200
users:((“java”,pid=7721,fd=92)) :::9300
为了提高部署速度。
然后在192.168.5.21安装ansible批量工具,利用ansible编写playbook批量部署ES集群。
也不用按照这方法,单独一台一台安装也可以
2.1配置yum源,装包
[root@es1 ~]#yum -y install ansible
[root@es1 ~]# ansible --version
ansible 2.4.2.0
2.2编辑配置文件
[root@es1 ~]# vim /etc/ansible/ansible.cfg #去掉两个注释即可
14 inventory = /etc/ansible/hosts
61 host_key_checking = False #关闭输入yes, 未开启的就会傻傻的等.
2.3 检查编辑结果
[root@es1 ~]#grep -Ev “^(#|$)” /etc/ansible/ansible.cfg #查看输出状态
[defaults]
inventory = /etc/ansible/hosts
roles_path = /etc/ansible/roles:/usr/share/ansible/roles
2.4定义主机
[root@es1 ~]# vim /etc/ansible/hosts
[es]
es[2:5] ansible_ssh_user=“root” ansible_ssh_pass="123456"hosts
#定义成员
#此处设置了就不用输入密码了
[root@e1 ~]# ansible es -m ping #有绿色代表成功了,只拿单个输出做代表
2.5创建批量部署yum,安装java环境,elasticsearch软件包。 拷贝本机的elasticsearch配置文件
[root@es1 ~]# mkdir /es && cd /es
[root@es1 es]# vim yum.yml #批量部署yum,安装java环境,elasticsearch软件包。
[root@es1 es]# vim peizhi.yml #拷贝本机的elasticsearch配置文件给其他机器
[root@es1 ~]# ansible-playbook yum.yml #批量部署yum,安装java环境,elasticsearch软件包。
[root@es1 ~]# ansible-playbook peizhi.yml #拷贝本机的elasticsearch配置文件给其他机器
[root@es1 ~]#ansible es -m shell -a 'sed -ri "s/(node.name).*/\1: ${HOSTNAME}/" /etc/elasticsearch/elasticsearch.yml' #批量修改配置文件node.name: 为本机名字。
[root@es1 ~]#ansible es -m shell -a “systemctl restart elasticsearch” #批量重起服务
测试:
验证集群是否创建成功
http://192.168.5.21:9200/_cluster/health?pretty
在主机192.168.5.21安装对应的3个插件
[root@es1 ~]# cd /usr/share/elasticsearch/bin/
[root@es1 bin]# ./plugin install file:/root/bigdesk-master.zip
[root@es1 bin]# ./plugin install file:/root/elasticsearch-head-master.zip
[root@es1 bin]# ./plugin install file:/root/elasticsearch-kopf-master.zip
安装插件后测试访问:
http://192.168.5.21:9200/_plugin/bigdesk/
http://192.168.5.21:9200/_plugin/head/
http://192.168.5.21:9200/_plugin/kopf/
安装后登陆界面
http://192.168.5.21:9200/_plugin/bigdesk/
http://192.168.5.21:9200/_plugin/head/
http://192.168.5.21:9200/_plugin/kopf
安装kibana
[root@es1 ~]# yum -y install kibana.x86_64.0.4.5.2-1
[root@es1 ~]# vim /opt/kibana/config/kibana.yml #默认安装目录opt
[root@es1 ~]# systemctl restart kibana
[root@es1 ~]# systemctl enable kibana
users:((“master”,pid=808,fd=13))
tcp LISTEN 0 128 *:5601
测试:是否安装成功
在浏览器地址栏输入:http://192.168.5.21:5601/status
第一次发表文章,多多指教。