本文基于Docker镜像搭建Elasticsearch集群,集群搭建完成后设置集群用户密码,主要包含以下内容:
- 修改系统参数
- 安装docker和docker-compose
- 编写yml配置文件
- 获取集群证书
- 修改yml配置文件
- 启动ES集群并修改密码
- 配置kibana
(一)修改系统参数
(1) virtual memory
默认情况下,Elasticsearch使用mmapfs目录存储其索引,mmap计数的默认操作系统限制可能太低,这可能会导致内存不足,需要将其调至262144。在 /etc/sysctl.conf 添加一行 :
vm.max_map_count=262144
运行 sysctl -p 使其生效。
(2)disable swap file
通常,Elasticsearch的内存使用由JVM选项控制。不需要启用交换。Linux系统可执行 swapoff -a 不启用。为了避免每次开机都需要手动执行,可将其写入开机执行文件 /etc/rc.local,开机自动执行。
(3)ulimit -n
系统默认设置1024。Elasticsearch使用了很多文件描述符,文件描述符用完可能是灾难性的,并且很可能导致数据丢失。因此运行Elasticsearch之前需要将文件描述符的数量限制增加到65536或更高。在 /etc/security/limits.conf 末尾追加以下内容:
root soft nofile 65536
root hard nofile 65536
* soft nofile 65536
* hard nofile 65536
* soft memlock unlimited
* hard memlock unlimited
如果是Ubuntu系统,追加上述内容后,ulimit -n可能并没有从1024变为65536,还需要在 /etc/systemd/user.conf和 /etc/systemd/system.conf 中追加
DefaultLimitNOFILE=65535
注意:修改后重启机器
(二)安装docker和docker-compose
(1)安装docker
Ubuntu和Debian可新建docker.sh,添加以下内容:
#!/bin/bash
OS_NAME=`cat /etc/os-release | grep NAME`
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common iptables
sudo apt-get remove docker docker-engine docker.io containerd runc
if [[ $OS_NAME =~ "Ubuntu" ]];then
sudo curl -fsSL