部署 ES 集群
Elasticsearch的可以用 docker 镜像部署,其base镜像是 centos:7,所有镜像版本在www.docker.elastic.co.
系统配置
-
创建 elasticsearch 用户(容器启动后的用户是 elasticsearch,在系统创建相应的用户是为了容器挂载卷时能够有权限操作相关文件,否则会报错)
-
配置最大文件打开数为至少为65536
centos 配置如下
root@sit-server:~# tail /etc/security/limits.conf
* hard nofile 1024000
* soft nofile 1024000
* soft memlock unlimited
* hard memlock unlimited
ubuntu 配置需要注释/etc/pam.d/su 文件的如下这段话 ,然后在进行和 如上和 centos 相同的配置
# session required pam_limits.so
- 禁用 swap 分区
root@sit-server:~# swapoff -a
- 虚拟内存设置
Elasticsearch 默认用 mmapfs存储 indices,默认的操作系统对 mmapfs的内存太低,可能导致内存溢出,linux 中可这样设置
$ grep vm.max_map_count /etc/sysctl.conf
vm.max_map_count=262144
- 线程数只是设置为4096
root@sit-server:~# ulimit -u 4096
root@sit-server:~# tail /etc/security/limits.conf
* hard nproc 100000
* soft nproc 100000
docker-compose 文件如下
version: '2.2'
networks:
esnet:
driver: bridge
services:
es1:
image: docker.elastic.co/elasticsearch/elasticsearch:6.5.4
container_name: es1
hostname: es1
volumes:
- /app/esdata/es1:/usr/share/elasticsearch/data #数据卷挂载(注:挂载卷的系统文件夹需要修改属主属组为 elasticsearch)
- /home/elasticsearch/elk/esconfig/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml #配置文件挂载
- /etc/localtime:/etc/localtime #时区同步
environment:
- TZ="Asia/Shanghai"
- "ES_JAVA_OPTS=-Xms1g -Xmx1g" #设置 heap size,通常设置为物理内存的一半,我这里机器是8G 内存,部署 3 个ES设置为 1g
ulimits: #固定内存,保证性能
memlock:
soft: -1
hard: -1
ports:
- "9201:9201"
- "9301:9301"
networks:
- esnet
es2:
image: docker.elastic.co/elasticsearch/elasticsearch:6.5.4
container_name: es2
hostname: es2
volumes:
- /app/esdata/es2:/usr/share/elasticsearch/data
- /home/elasticsearch/elk/esconfig/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- /etc/localtime:/etc/localtime
environment:
- TZ="Asia/Shanghai"
-