CentOS7 部署 ElasticSearch7.0.1 集群


环境
  1. 主机名 IP 操作系统 ES 版本
  2. test1 172.16.6.30 CentOS7.3 7.0.1
  3. test2 172.16.6.31 CentOS7.3 7.0.1
  4. test3 172.16.6.32 CentOS7.3 7.0.1

下载:

wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.1-linux-x86_64.tar.gz 或者到官网自行下载:https://www.elastic.co/cn/downloads/elasticsearch

各节点初始配置各节点初始配置

关闭 selinux、防火墙
部署 java 运行环境
创建 elastic 用户
useradd -m elastic
创建数据目录
cd /var/lib
mkdir elasticsearch
chown elastic.elastic elasticsearch
创建日志目录
cd /var/log
mkdir -p elasticsearch
chown elastic.elastic elasticsearch
增加 /etc/sysctl.conf 配置,执行 sysctl -p 生效
vm.max_map_count = 262144
增加 /etc/security/limits.conf 配置
elastic soft nofile 65536
elastic hard nofile 65536
elastic soft memlock unlimited
elastic hard memlock unlimited

部署 ELASTICSEARCH

登陆 test1,下载 elasticsearch,解压至 /opt/ 下
修改 elasticsearch 目录的权限
chown -R elastic.elastic /opt/elasticsearch
修改 jvm 参数文件 /opt/elasticsearch/config/jvm.options
修改 /opt/elsaticsearch/config/elasticsearch.yml
cluster.name: TEST_ES_CLUSTER
node.name: test1
network.host: 192.168.1.2
cluster.initial_master_nodes: ["test1", "test2"]
path.data: /var/lib/elasticsearch
path.logs: /var/log/elasticsearch
bootstrap.memory_lock: true
discovery.zen.ping.unicast.hosts: ["192.168.1.2", "192.168.1.3", "192.168.1.4"]
discovery.zen.minimum_master_nodes: 2
gateway.recover_after_nodes: 2
打包 elasticsearch 目录,复制到 test2 和 test3 上,并修改 elasticsearch.yml
 test2
node.name: test2
network.host: 192.168.1.3
test3
node.name: test3
network.host: 192.168.1.4

启动集群(两种启动方式)

直接启动二进制
在每个节点上启动 elasticsearch 服务
su - elastic -c '/opt/elasticsearch/bin/elasticsearch -d'
systemd 启动
创建文件 /usr/lib/systemd/system/elasticsearch.service,内容如下
[Unit]
Description=ElasticSearch
Requires=network.service
After=network.service
[Service]
User=elastic
Group=elastic
LimitNOFILE=65536
LimitMEMLOCK=infinity
Environment=JAVA_HOME=/opt/jre
ExecStart=/opt/elasticsearch/bin/elasticsearch
SuccessExitStatus=143
[Install]
WantedBy=multi-user.target
启动 elasticsearch 服务
systemctl daemon-reload
systemctl start elasticsearch

查看集群状态

查看集群节点状态 查看节点状态 curl http://192.168.1.2:9200/_cat/nodes?pretty 查看集群状态 curl http://192.168.1.2:9200/_cluster/state?pretty