es系统初始化

1、vim /etc/security/limits.conf

*   soft    nofile     65536
*   hard   nofile     65536

#number of threads

*   soft     nproc     64000
*   hard    nproc    64000

vim /etc/security/limits.d/20-nproc.conf

(处理max number of threads [3885] for user [elk] is too low, increase to at least [4096])

*     soft  nproc   10240
*     hard  nproc   10240

2、关闭交换分区

swapoff -a

注释掉/etc/fstab中有swap的一行,

或者在/etc/sysctl.conf中添加 vm.swappiness=1。

3、Enable bootstrap.memory_lock

vim $ES_HOME/config/elasticsearch.yml

bootstrap.memory_lock: true

添加/etc/security/limits.conf

* hard memlock unlimited * soft memlock unlimited

vim /etc/systemd/system.conf

DefaultLimitNOFILE=65536 DefaultLimitNPROC=32000 DefaultLimitMEMLOCK=infinity

/bin/systemctl daemon-reload

4、虚拟内存的配置

sysctl -w vm.max_map_count=262144

并在/etc/sysctl.conf中添加

echo  "vm.max_map_count=262144">>/etc/sysctl.conf

sysctl -p

常见报错:

ERROR: [2] bootstrap checks failed

[1]: max file descriptors [65535] for elasticsearch process is too low, increase to at least [65536]

[2]: memory locking requested for elasticsearch process but memory is not locked

vim /etc/security/limits.conf

*   soft    nofile     65536
*   hard   nofile     65536

vim /etc/security/limits.conf

* soft memlock unlimited
* hard memlock unlimited

elastic 系统初始化脚本

#!/bin/bash
#elasticsearch安装系统配置初始化脚本
esuser=elasitc
create_user() {
if ! grep "^$esuser:" /etc/passwd ; then
	useradd $esuser
	echo "$esuser" | passwd "$esuser" --stdin &>/dev/null
	check_ok
else
	echo $esuser already exist!
fi
}


set_system() {
cat >> /etc/security/limits.conf << EOF
#max open files
*   soft    nofile     65536
*   hard    nofile     65536
#number of threads	
*   soft    nproc    64000
*   hard    nproc    64000
*   soft    memlock unlimited
*   hard    memlock unlimited
EOF

# 配置最大虚拟内存
cat >> /etc/sysctl.conf << EOF
vm.max_map_count=262144
EOF
# 生效
sysctl -p


cat >> /etc/systemd/system.conf << EOF
DefaultLimitNOFILE=65536
DefaultLimitNPROC=32000
DefaultLimitMEMLOCK=infinity
EOF
/bin/systemctl daemon-reload

#关闭swap
swapoff -a
sed -i 's/^[^#].*swap/#&/' /etc/fstab

}


create_user
set_system