Elasticsearch 6.7集群的搭建
环境如下
系统:Centos7
一、准备
1.1 节点规划
IP cluster.name node.name
192.168.1.11 es_log es_1
192.168.1.12 es_log es_2
192.168.1.13 es_log es_3
1.2 安装Java运行环境JRE
链接:https://pan.baidu.com/s/1_iEoJoSez3vNpAxf88KADQ
提取码:wiaz
mkdir /usr/java;\
tar -xf /tmp/jdk-8u191-linux-x64.tar.gz -C /usr/java/;\
rm -rf /usr/java/default;\
ln -s /usr/java/jdk1.8.0_191/bin/java /usr/bin/java;\
tee -a /usr/local/profile << 'EOF'
#set java environment
export JAVA_HOME=/usr/java/jdk1.8.0_191
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/jre/lib/rt.jar
export PATH=$PATH:$JAVA_HOME/bin
1.3 下载elasticsearch软件:
https://github.com/elastic/elasticsearch/archive/v6.7.1.tar.gz
二、安装软件
mv elasticsearch-6.7.1.tar.gz /usr/local/
cd /usr/local/
tar -xf elasticsearch-6.7.1.tar.gz
mv elasticsearch-6.7.1 elasticsearch
三、配置
3.1 配置Limit
LimitMEMLOCK
关闭防火墙和selinux
# systemctl stop firewalld && systemctl disable firewalld
# sed -i 's/=enforcing/=disabled/g' /etc/selinux/config && setenforce 0
# vim /etc/security/limits.conf 配置运行elk用户限制
elk soft nofile 65536
elk hard nofile 131072
elk soft nproc 2048
elk hard nproc 4096
# vim /etc/sysctl.conf
vm.max_map_count=655360
# sysctl -p
3.2 开启内存锁定
LimitNPROC
3.3 最大进程数,系统支持的最大进程数:32768
查看系统最大支持进程数:cat /proc/sys/kernel/pid_max
LimitNOFILE
打开文件数,系统默认最大文件描述符:791020
3.4 查看系统最大文件描述符:cat /proc/sys/fs/file-max
mkdir /usr/local/systemd/system/elasticsearch.service.d;\
cat > /usr/local/systemd/system/elasticsearch.service.d/override.conf << 'EOF'
[Service]
Environment=JAVA_HOME=/usr/java/default
LimitMEMLOCK=infinity
LimitNOFILE=204800
LimitNPROC=4096
EOF
3.5 配置JVM(可选)
默认是1G
不要超过可用 RAM 的 50%
Lucene 能很好利用文件系统的缓存,它是通过系统内核管理的。如果没有足够的文件系统缓存空间,性能会受到影响。 此外,专用于堆的内存越多意味着其他所有使用 doc values 的字段内存越少
不要超过 32 GB
如果堆大小小于 32 GB,JVM 可以利用指针压缩,这可以大大降低内存的使用:每个指针 4 字节而不是 8 字节
sed -i '/-Xms1g/c\-Xms3g' /usr/local/elasticsearch/jvm.options;\
sed -i '/-Xmx1g/c\-Xmx3g' /usr/local/elasticsearch/jvm.options
3.6 配置elasticsearch.yml
cluster.name
集群名称,默认是elasticsearch,建议修改为更明确的名称,比如es_log
node.name
节点名,默认随机指定一个name列表中名字,建议修改为明确的名称,比如es_1,es_2,es_3
network.host
主机IP
path.data
数据目录
path.logs
日志目录
discovery.zen.ping.unicast.hosts
节点发现
3.7 所有节点执行相同的命令
mkdir -p /data/elasticsearch/data /data/elasticsearch/logs;\
chown -R elasticsearch. /data/elasticsearch;\
sed -i '/cluster.name/c\cluster.name: es_log' /usr/local/elasticsearch/elasticsearch.yml;\
sed -i '/network.host/c\network.host: 0.0.0.0' /usr/local/elasticsearch/elasticsearch.yml;\
sed -i '/path.data/c\path.data: /data/elasticsearch/data' /usr/local/elasticsearch/elasticsearch.yml;\
sed -i '/path.logs/c\path.logs: /data/elasticsearch/logs' /usr/local/elasticsearch/elasticsearch.yml;\
sed -i '/discovery.zen.ping.unicast.hosts/c\discovery.zen.ping.unicast.hosts: ["192.168.1.11","192.168.1.12","192.168.1.13"]' /usr/local/elasticsearch/elasticsearch.yml
3.8 各个节点执行对应的命令
#节点-1
sed -i '/node.name/c\node.name: es_1' /usr/local/elasticsearch/elasticsearch.yml
#节点-2
sed -i '/node.name/c\node.name: es_2' /usr/local/elasticsearch/elasticsearch.yml
#节点-3
sed -i '/node.name/c\node.name: es_3' /usr/local/elasticsearch/elasticsearch.yml
3.9 启动
systemctl enable elasticsearch;\
systemctl daemon-reload;\
systemctl start elasticsearch;\
systemctl status elasticsearch
3.10 配置防火墙(关闭防火墙的忽略)
firewall-cmd --add-port=9200/tcp --permanent;\
firewall-cmd --add-port=9300/tcp --permanent;\
firewall-cmd --reload
四、安装中文分词插件(可选)
#查看已安装插件
/usr/share/elasticsearch/bin/elasticsearch-plugin list
#安装IK
/usr/share/elasticsearch/bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.7.0/elasticsearch-analysis-ik-6.7.0.zip
五、查询
#查看节点信息
curl -X GET http://localhost:9200/_nodes
#打开文件数信息
curl -X GET http://localhost:9200/_nodes/stats/process?filter_path=**.max_file_descriptors
#集群健康状态
curl -X GET http://localhost:9200/_cat/health?v
#查看集群索引数
curl -X GET http://localhost:9200/_cat/indices?v
#查看磁盘分配情况
curl -X GET http://localhost:9200/_cat/allocation?v
#查看集群节点
curl -X GET http://localhost:9200/_cat/nodes?v
#查看集群其他信息
curl -X GET http://localhost:9200/_cat