CentOS 7/8 部署Elasticsearch集群
首先要安装JDK,参考 https://www.cnblogs.com/dotqin/p/13560419.html
环境说明:三台百度云服务器,内网IP分别为: 192.168.32.36、192.168.32.37、192.168.32.38, 不开放公网IP访问
分别在三台服务器上执行以下操作:
1.创建目录及下载解压(下载速度很慢)
cd /usr/local/ mkdir elasticsearch cd elasticsearch wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.1-linux-x86_64.tar.gz wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.9.1-linux-x86_64.tar.gz.sha512 yum install perl-Digest-SHA shasum -a 512 -c elasticsearch-7.9.1-linux-x86_64.tar.gz.sha512 tar -xzf elasticsearch-7.9.1-linux-x86_64.tar.gz mkdir -p /data/elasticsearch/data mkdir -p /data/elasticsearch/logs
2.设置用户和权限
groupadd elasticsearch useradd elasticsearch -g elasticsearch chown -R elasticsearch:elasticsearch /usr/local/elasticsearch/ chown -R elasticsearch:elasticsearch /data/elasticsearch/
3.编辑配置文件
cd /usr/local/elasticsearch/elasticsearch-7.9.1/config vim elasticsearch.yml # 添加或修改以下内容 cluster.name: elsearch-cluster node.name: node-1 # 每台不一样 path.data: /data/elasticsearch/data path.logs: /data/elasticsearch/logs bootstrap.memory_lock: true network.host: 192.168.32.36 # 每台不一样 http.port: 9200 discovery.seed_hosts: ["192.168.32.36", "192.168.32.37", "192.168.32.38"] cluster.initial_master_nodes: ["node-1", "node-2", "node-3"] vim jvm.options # 修改以下内容 建议为服务器内存的一半 -Xms8g -Xmx8g
4.设置一些其他参数
echo "elasticsearch - nofile 65535" >> /etc/security/limits.conf echo "elasticsearch soft memlock unlimited" >> /etc/security/limits.conf echo "elasticsearch hard memlock unlimited" >> /etc/security/limits.conf echo "vm.swappiness=1" >> /etc/sysctl.conf echo "vm.max_map_count=262144" >> /etc/sysctl.conf 设置完成后需要重启
5.添加到服务管理
vim /usr/lib/systemd/system/elasticsearch.service # 添加以下内容 [Unit] Description=elasticsearch-7.9.1 service After=syslog.target network.target [Service]
Restart=always
RestartSec=1 Type=forking TimeoutSec=120 User=elasticsearch Environment=JAVA_HOME=/usr/local/java/jdk1.8.0_261 LimitMEMLOCK=infinity ExecStart=/usr/local/elasticsearch/elasticsearch-7.9.1/bin/elasticsearch -d -p /usr/local/elasticsearch/elasticsearch-7.9.1/elsearch.pid ExecStop=/usr/bin/pkill -F /usr/local/elasticsearch/elasticsearch-7.9.1/elsearch.pid [Install] WantedBy=multi-user.target
6.设置服务生效及开机自启动
systemctl daemon-reload
systemctl enable elasticsearch.service
7.启动elasticsearch
systemctl start elasticsearch
systemctl status elasticsearch