elasticsearch10节点部署
部署前各角色的分配
一、这里我们可以把elasticsearch的角色分为3种类型。
1.master节点
2.data(数据)节点
3.client(客户端、分发)节点
可以根据实际情况进行决定
二、根据流量或访问量配置client节点
三、elasticsearch部署集群时,master节点至少需要三台
注意:master节点需要为单数,否则第一个master节点不能进行选举,且master就作为主节点,不参与数据的保存的任务
部署elasticsearch
环境部署
系统 | ip | 节点 | 服务 |
---|---|---|---|
centos7 | 192.168.154.30:9200,192.168.154.40:9200,192.168.154.50:9200 | master | elasticsearch |
centos7 | 192.168.154.30:9201,192.168.154.30:9202,192.168.154.40:9201,192.168.154.40:9202,192.168.154.50:9201,192.168.154.50:9202 | date | elasticsearch |
centos7 | 192.168.154.30:9203,192.168.154.40:9203,192.168.154.50:9203 | client | elasticsearch |
使用shell脚本一键部署第一台master
echo "192.168.154.30 wu1" >> /etc/hosts
echo "192.168.154.40 wu2" >> /etc/hosts
echo "192.168.154.50 wu3" >> /etc/hosts
yum update -y
yum install -y java-1.8.0-openjdk-devel.x86_64
java -version
which java
wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.12.1-linux-x86_64.tar.gz
tar -zxvf elasticsearch-7.12.1-linux-x86_64.tar.gz
mkdir es
mv elasticsearch-7.12.1/ /opt/es/elasticsearch-master
groupadd es
useradd es -g es
mkdir -p /home/data/es1
mkdir -p /home/data/es2
mkdir -p /home/data/es3
mkdir -p /home/data/es4
mkdir -p /home/logs
chown -R es:es /opt/es/elasticsearch-master/
chown -R es:es /home/data/
chown -R es:es /home/logs
echo 'cluster.name: test-es
node.name: master-1
network.host: 0.0.0.0
http.port: 9200
node.master: true
node.data: false
transport.tcp.port: 9300
xpack.ml.enabled: false
cluster.initial_master_nodes: ["master-1","master-2","master-3"]
discovery.seed_hosts: ["192.168.154.30:9300","192.168.154.40:9300","192.168.154.50:9300,192.168.154.30:9301,192.168.154.30:9302,192.168.154.40:9301,192.168.154.40:9302,192.168.154.50:9301,192.168.154.50:9302,192.168.154.30:9303,192.168.154.40:9303,192.168.154.50:9303"]
path.data: /home/data/es1
path.logs: /home/logs
bootstrap.memory_lock: false
http.cors.enabled: true
http.cors.allow-origin: "*"' >> /opt/es/elasticsearch-master/config/elasticsearch.yml
echo '-Xms10g
-Xmx10g' >> /opt/es/elasticsearch-master/config/jvm.options
echo '#!/bin/bash
#chkconfig: 345 63 37
#description: elasticsearch
#processname: elasticsearch-7.12.1
# 这个目录是你Es所在文件夹的目录
export ES_HOME=/opt/es/elasticsearch-master/
case $1 in
start)
su es<<!
cd $ES_HOME
./bin/elasticsearch -d -p pid
exit
!
echo "elasticsearch is started"
;;
stop)
pid=`cat $ES_HOME/pid`
kill -9 $pid
echo "elasticsearch is stopped"
;;
restart)
pid=`cat $ES_HOME/pid`
kill -9 $pid
echo "elasticsearch is stopped"
sleep 1
su es<<!
cd $ES_HOME
./bin/elasticsearch -d -p pid
exit
!
echo "elasticsearch is started"
;;
*)
echo "start|stop|restart"
;;
esac
exit 0' >> /etc/init.d/elasticsearch
chmod 777 /etc/init.d/elasticsearch
echo "elasticsearch soft nofile 65536
elasticsearch hard nofile 65536
* hard nproc 4096">> /etc/security/limits.d/20-nproc.conf
echo 'elasticsearch soft nofile 65536
elasticsearch hard nofile 65536
'>> /etc/security/limits.conf
echo "vm.max_map_count = 655360" >> /etc/sysctl.conf
sysctl -p
# 添加系统服务
chkconfig --add elasticsearch
# 启动服务
service elasticsearch start
# 开启开机自动启动服务
chkconfig elasticsearch on
#安装kibana
tar -zxvf kibana-7.12.1-linux-x86_64.tar.gz -C /usr/local/
#--2--取消注释,Kiabana 服务的默认监听端口为5601
echo 'server.port: 5601
#--7--取消注释,设置 Kiabana 的监听地址,0.0.0.0代表所有地址
server.host: "0.0.0.0"
#--21--取消注释,设置和 Elasticsearch 建立连接的地址和端口
elasticsearch.url: "http://192.168.154.30:9200"
#--30--取消注释,设置在 elasticsearch 中添加.kibana索引
kibana.index: ".kibana"' >> /usr/local/kibana-7.10.1/config/kibana.yml
echo '[Unit]
Description=kibana
After=network.target
[Service]
Type=simple
User=elasticsearch
ExecStart=/usr/local/kibana-7.12.1/bin/kibana
PrivateTmp=true
[Install]
WantedBy=multi-user.target' >> /usr/lib/systemd/system/kibana.service
systemctl enable kibana.service
# 启动服务
systemctl start kibana.service
部署一台服务器上的其他三台elasticsearch
cd /usr/local/
cp -rp elasticsearch-master /opt/es/elasticsearch-node1
cp -rp elasticsearch-master /opt/es/elasticsearch-node2
cp -rp elasticsearch-master /opt/es/elasticsearch-client
echo 'cluster.name: test-es
node.name: node-1
network.host: 0.0.0.0
http.port: 9201
node.master: false
node.data: true
transport.tcp.port: 9301
xpack.ml.enabled: false
cluster.initial_master_nodes: ["master-1","master-2","master-3"]
discovery.seed_hosts: ["192.168.154.30:9300","192.168.154.40:9300","192.168.154.50:9300,192.168.154.30:9301,192.168.154.30:9302,192.168.154.40:9301,192.168.154.40:9302,192.168.154.50:9301,192.168.154.50:9302,192.168.154.30:9303,192.168.154.40:9303,192.168.154.50:9303"]
path.data: /home/elasticsearch/data/es2
path.logs: /home/elasticsearch/logs
bootstrap.memory_lock: false
http.cors.enabled: true
http.cors.allow-origin: "*"' >> /opt/es/elasticsearch-node1/config/elasticsearch.yml
##第二台node2
echo 'cluster.name: test-es
node.name: node-1
network.host: 0.0.0.0
http.port: 9202
node.master: false
node.data: true
transport.tcp.port: 9302
xpack.ml.enabled: false
cluster.initial_master_nodes: ["master-1","master-2","master-3"]
discovery.seed_hosts: ["192.168.154.30:9300","192.168.154.40:9300","192.168.154.50:9300,192.168.154.30:9301,192.168.154.30:9302,192.168.154.40:9301,192.168.154.40:9302,192.168.154.50:9301,192.168.154.50:9302,192.168.154.30:9303,192.168.154.40:9303,192.168.154.50:9303"]
path.data: /home/elasticsearch/data/es3
path.logs: /home/elasticsearch/logs
bootstrap.memory_lock: false
http.cors.enabled: true
http.cors.allow-origin: "*"' >> /opt/es/elasticsearch-node2/config/elasticsearch.yml
## 分发节点
echo 'cluster.name: test-es
node.name: client
network.host: 0.0.0.0
http.port: 9203
node.master: false
node.data: false
transport.tcp.port: 9303
xpack.ml.enabled: false
cluster.initial_master_nodes: ["master-1","master-2","master-3"]
discovery.seed_hosts: ["192.168.154.30:9300","192.168.154.40:9300","192.168.154.50:9300,192.168.154.30:9301,192.168.154.30:9302,192.168.154.40:9301,192.168.154.40:9302,192.168.154.50:9301,192.168.154.50:9302,192.168.154.30:9303,192.168.154.40:9303,192.168.154.50:9303"]
path.data: /home/elasticsearch/data/es4
path.logs: /home/elasticsearch/logs
bootstrap.memory_lock: false
http.cors.enabled: true
http.cors.allow-origin: "*"' >> /opt/es/elasticsearch-client/config/elasticsearch.yml
安装包地址
链接:https://pan.baidu.com/s/19bhIxiEFRXc094es9U8pnA
提取码:4bkc