elasticsearch centos7集群部署案例
安排3台集群,分别是
192.168.1.21
192.168.1.22
192.168.1.23
这些ip根据自己实际ip设置
确定是否存在java8和已安装的elasticsearch
如果存在已安装的先卸载
elasticsearch卸载方法:
# yum -y remove elasticsearch
# find / -name "elasticsearch" -exec rm -rf {} \;
开始集群安装和部署
1. 导入官方PGP-Key
~]#rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
2. 建立下载rpm包的repo
~]# vim /etc/yum.repos.d/elk.repo
[elasticsearch-5.x]
name=Elasticsearch repository for 5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
保存后退出;
3. 安装elasticsearch包
~]#yum install elasticsearch
4. 编辑配置文件
新建存储和日志文件夹
# mkdir -pv /data/elasticsearch/{data,logs}
# chown -R elasticsearch.elasticsearch /data/elasticsearch
~]# vim /etc/elasticsearch/elasticsearch.yml
注意要修改 elasticsearch.yml data和logs的存储路径
path.data:/data/elasticsearch/data
path.logs:/data/elasticsearch/logs
保存,退出;
5. 启动服务
~]# systemctl daemon-reload
~]# systemctl start elasticsearch
~]# systemctl status elasticsearch
~]#systemctl enable elasticsearch //加入开机启动
6. 查看端口状态
~]#ss -tnl
至此,节点es-1配置完成。
7.配置集群中的另外节点es-2 和 es-3
配置同es-1,修改一下配置文件里的节点名和地址即可,不再赘述。
如果通过win os浏览器访问centos elasticsearch请在centos 放开防火墙端口
# firewall-cmd --zone=public --add-port=9200/tcp --permanent # firewall-cmd --reload
8. es集群的相关查询
注意:Elasticsearch 5.x版本不再支持相关插件:如 “elasticsearch-head”...,解释可以访问官网,实在需要,可以独立运行(此处跳过)。
Elasticseach 1.x 2.x仍可支持,请查看:http://mobz.github.io/elasticsearch-head/
查询集群状态方法①
~]# curl -XGET 'http://192.168.1.21:9200/_cat/nodes' //随意一台es中可执行,也可更换其中的 ip(这里可22或23)
~]# curl -XGET 'http://192.168.1.21:9200/_cat/nodes?v' //同上在后面添加 ?v ,表示详细显示
查询集群状态方法②
~]# curl -XGET 'http://192.168.1.21:9200/_cluster/state/nodes?pretty'
查询集群中的master
~]# curl -XGET 'http://192.168.1.21:9200/_cluster/state/master_node?pretty'
或
~]# curl -XGET 'http://192.168.1.21:9200/_cat/master?v'
查询集群的健康状态
~]# curl -XGET 'http://192.168.1.21:9200/_cat/health?v'
或
~]# curl -XGET 'http://192.168.1.21:9200/_cluster/health?pretty'