[在单台centos7服务器上搭建elasticsearch集群]
本次集群部署在单台服务器,正式环境中不可这么干,因为起不到作用。
本次环境使用的es版本均为:elasticsearch-7.2.0.tar
下载地址为:https://www.elastic.co/cn/downloads/past-releases/elasticsearch-7-2-0
环境搭建
系统配置:
修改/etc/hosts增加
127.0.0.1 node01
127.0.0.1 node02
127.0.0.1 node03
修改/etc/sysctl.conf增加配置,然后执行sysctl -p立即生效
vm.max_map_count=655360
修改 /etc/security/limits.conf 增加配置:
* soft nofile 65536
* hard nofile 65536
修改 /etc/security/limits.d/20-nproc.conf 增加配置:
* soft nproc 4096
* hard nproc 4096
用到的软件包:
elasticsearch-7.2.0.tar.gz
创建安装目录
mkdir /usr/local/elasticsearch-cluster/
将es上传到安装目录后,解压
tar -xvf elasticsearch-7.2.0.tar.gz
为了操作方便,修改下软件目录名
cp -rp elasticsearch-7.2.0/ elasticsearch-cluster/elasticsearch-node1
cp -rp elasticsearch-7.2.0/ elasticsearch-cluster/elasticsearch-node2
mv elasticsearch-7.2.0/ elasticsearch-cluster/elasticsearch-node3
elasticsearch-node1配置修改
修改es配置如下(config/elasticsearch.yml)
cluster.name: es-cluster
node.name: node1
node.master: true
node.data: true
path.data: /usr/local/elasticsearch-cluster/elasticsearch-node1/data
path.logs: /usr/local/elasticsearch-cluster/elasticsearch-node1/logs
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
network.host: 0.0.0.0
http.port: 9201
transport.tcp.port: 9301
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
cluster.initial_master_nodes: ["node1"]
discovery.zen.minimum_master_nodes: 1
http.cors.enabled: true
http.cors.allow-origin: "*"
elasticsearch-node2配置修改
修改es配置如下(config/elasticsearch.yml)
cluster.name: es-cluster
node.name: node2
node.master: false
node.data: true
path.data: /usr/local/elasticsearch-cluster/elasticsearch-node2/data
path.logs: /usr/local/elasticsearch-cluster/elasticsearch-node2/logs
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
network.host: 0.0.0.0
http.port: 9202
transport.tcp.port: 9302
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
cluster.initial_master_nodes: ["node1"]
discovery.zen.minimum_master_nodes: 1
elasticsearch-node3配置修改
修改es配置如下(config/elasticsearch.yml)
cluster.name: es-cluster
node.name: node3
node.master: false
node.data: true
path.data: /usr/local/elasticsearch-cluster/elasticsearch-node3/data
path.logs: /usr/local/elasticsearch-cluster/elasticsearch-node3/logs
bootstrap.memory_lock: false
bootstrap.system_call_filter: false
network.host: 0.0.0.0
http.port: 9203
transport.tcp.port: 9303
discovery.zen.ping.unicast.hosts: ["127.0.0.1:9301","127.0.0.1:9302","127.0.0.1:9303"]
cluster.initial_master_nodes: ["node1"]
discovery.zen.minimum_master_nodes: 1
启动
然后分别启动node01/02/03即可
bin/elasticsearch -d 后台启动
健康检查
查看集群状态
curl http://ES_IP:9201/_cat/health?v
查看节点状态
curl http://ES_IP:9201/_cat/nodes?v