Centos7 搭建Elasticsearch 5.6 集群
目前ES最新的版本,6系列为6.4.0,5系列最新为5.6.11,5.6相对成熟,周边系统兼容性要好些,所以本文以5.6为例进行介绍。
1. 准备
1.1 节点规划
|IP|cluster.name|node.name |------ |192.168.1.24|es_log|es_1| |192.168.1.25|es_log|es_2| |192.168.1.26|es_log|es_3|
1.2 安装Java运行环境JRE
#下载Server Jre上传到tmp目录
mkdir /usr/java;\
tar xf /tmp/server-jre-8u181-linux-x64.tar.gz -C /usr/java;\
ln -s /usr/java/jdk1.8.0_181 //usr/java/default;\
tee -a /etc/profile << 'EOF'
export JAVA_HOME=/usr/java/default
export PATH=$JAVA_HOME/bin:$PATH
EOF
2. 安装
2.1 导入yum库
rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch;\
tee /etc/yum.repos.d/elasticsearch.repo << 'EOF'
[elasticsearch-5.x]
name=Elasticsearch repository for 5.x packages
baseurl=https://artifacts.elastic.co/packages/5.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
type=rpm-md
EOF
2.2 安装
yum install elasticsearch -y
2.3 配置Limit
开启内存锁定
最大进程数,系统支持的最大进程数:32768
查看系统最大支持进程数:`cat /proc/sys/kernel/pid_max`
打开文件数,系统默认最大文件描述符:791020
查看系统最大文件描述符:`cat /proc/sys/fs/file-max`
mkdir /etc/systemd/system/elasticsearch.service.d;\
tee /etc/systemd/system/elasticsearch.service.d/override.conf << 'EOF'
[Service]
Environment=JAVA_HOME=/usr/java/default
LimitMEMLOCK=infinity
LimitNOFILE=204800
LimitNPROC=4096
EOF
2.4 配置JVM(可选)
- 默认是2G
Lucene 能很好利用文件系统的缓存,它是通过系统内核管理的。如果没有足够的文件系统缓存空间,性能会受到影响。 此外,专用于堆的内存越多意味着其他所有使用 doc values 的字段内存越少
如果堆大小小于 32 GB,JVM 可以利用指针压缩,这可以大大降低内存的使用:每个指针 4 字节而不是 8 字节
如果堆大小小于 32 GB,JVM 可以利用指针压缩,这可以大大降低内存的使用:每个指针 4 字节而不是 8 字节
sed -i '/-Xms2g/c\-Xms3g' /etc/elasticsearch/jvm.options;\
sed -i '/-Xmx2g/c\-Xmx3g' /etc/elasticsearch/jvm.options
2.5 配置elasticsearch.yml
mkdir -p /home/elasticsearch/data /home/elasticsearch/plugins /home/elasticsearch/logs;\
chown -R elasticsearch. /home/elasticsearch;\
sed -i '/cluster.name/c\cluster.name: es_log' /etc/elasticsearch/elasticsearch.yml;\
sed -i '/node.name/c\node.name: es_1' /etc/elasticsearch/elasticsearch.yml;\
sed -i '/network.host/c\network.host: 0.0.0.0' /etc/elasticsearch/elasticsearch.yml;\
sed -i '/path.data/c\path.data: /home/elasticsearch/data' /etc/elasticsearch/elasticsearch.yml;\
sed -i '/path.plugins/c\path.plugins: /home/elasticsearch/plugins' /etc/elasticsearch/elasticsearch.yml;\
sed -i '/path.logs/c\path.logs: /home/elasticsearch/logs' /etc/elasticsearch/elasticsearch.yml;\
sed -i '/discovery.zen.ping.unicast.hosts/c\discovery.zen.ping.unicast.hosts: ["192.168.1.24","192.168.1.25","192.168.1.26"]' /etc/elasticsearch/elasticsearch.yml
2.6 启动
systemctl enable elasticsearch;\
systemctl daemon-reload;\
systemctl start elasticsearch;\
systemctl status elasticsearch
2.7 配置防火墙
firewall-cmd --add-port=9200/tcp --permanent;\
firewall-cmd --add-port=9300/tcp --permanent;\
firewall-cmd --reload
3. 查询
#查看节点信息
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