<返回更多

Dokcer安装elasticsearch集群

2021-07-03    运维蚂蚁
加入收藏

一、环境准备

1.1、环境列表

节点名称

系统

ip地址

es-node1

centos7.6

192.168.10.128

es-node2

centos7.6

192.168.10.129

es-node3

centos7.6

192.168.10.130

1.2、修改主机名

#分别到主机执行
hostnamectl set-hostname es-node1
hostnamectl set-hostname es-node2
hostnamectl set-hostname es-node3

1.3、系统init

yum -y install wget vim lrzsz net-tools ntp
#修改yum源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo_bak
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo 
yum clean all
yum -y update

# 关闭 防火墙
systemctl stop firewalld
systemctl disable firewalld

# 关闭 Selinux
setenforce 0
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config

#时间同步
rm -f /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
systemctl start chronyd.service && systemctl enable chronyd.service

二、安装Docker

# 卸载旧版本
yum remove -y docker 
docker-client 
docker-client-latest 
docker-common 
docker-latest 
docker-latest-logrotate 
docker-logrotate 
docker-selinux 
docker-engine-selinux 
docker-engine

# 设置 yum repository
yum install -y yum-utils nfs-utils gfs2-utils glusterfs-fuse 
device-mApper-persistent-data 
lvm2
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

#镜像加速,请更换为自己公司的
mkdir -p /etc/docker /data/docker
tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://17i90p15.mirror.aliyuncs.com"],
  "insecure-registries": ["192.168.10.45"],
  "graph": "/data/docker"
}
EOF

# 安装并启动 docker
yum install -y docker-ce-18.09.7 docker-ce-cli-18.09.7 containerd.io
systemctl enable docker
systemctl start docker

三、操作系统限制修改

#文件包含限制一个进程可以拥有的VMA(虚拟内存区域)的数量
echo "vm.max_map_count=655360" >> /etc/sysctl.conf
sysctl -p

四、elasticsearch配置

4.1、创建目录

[root@es-node1 ~]# mkdir -p /data/elasticsearch/{data,logs,plugins}

4.2、配置文件

es-node1:

[root@es-node1 ~]# cd /data/elasticsearch/
[root@es-node1 elasticsearch]# cat > elasticsearch.yml <<  EOF
cluster.name: elasticsearch-cluster
node.name: es-node1
network.bind_host: 0.0.0.0
network.publish_host: 192.168.10.128
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true 
node.data: true  
discovery.zen.ping.unicast.hosts: ["192.168.10.128:9300","192.168.10.129:9300","192.168.10.130:9300"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.fd.ping_timeout: 1m
discovery.zen.fd.ping_retries: 5
cluster.initial_master_nodes: ["192.168.10.128:9300","192.168.10.129:9300","192.168.10.130:9300"]
EOF

es-node2:

[root@es-node1 ~]# cd /data/elasticsearch/
[root@es-node1 elasticsearch]# cat > elasticsearch.yml <<  EOF
cluster.name: elasticsearch-cluster
node.name: es-node2
network.bind_host: 0.0.0.0
network.publish_host: 192.168.10.129
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true 
node.data: true  
discovery.zen.ping.unicast.hosts: ["192.168.10.128:9300","192.168.10.129:9300","192.168.10.130:9300"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.fd.ping_timeout: 1m
discovery.zen.fd.ping_retries: 5
cluster.initial_master_nodes: ["192.168.10.128:9300","192.168.10.129:9300","192.168.10.130:9300"]
EOF

es-node3:

[root@es-node1 ~]# cd /data/elasticsearch/
[root@es-node1 elasticsearch]# cat > elasticsearch.yml <<  EOF
cluster.name: elasticsearch-cluster
node.name: es-node3
network.bind_host: 0.0.0.0
network.publish_host: 192.168.10.130
http.port: 9200
transport.tcp.port: 9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true 
node.data: true  
discovery.zen.ping.unicast.hosts: ["192.168.10.128:9300","192.168.10.129:9300","192.168.10.130:9300"]
discovery.zen.minimum_master_nodes: 2
discovery.zen.fd.ping_timeout: 1m
discovery.zen.fd.ping_retries: 5
cluster.initial_master_nodes: ["192.168.10.128:9300","192.168.10.129:9300","192.168.10.130:9300"]
EOF

五、启动

#es-node1:
[root@es-node1 ~]# docker run -d --name es-node1  --network=host --privileged=true  
-e ES_JAVA_OPTS="-Xms6144m -Xmx6144m"  
-e TAKE_FILE_OWNERSHIP=true 
-v /data/elasticsearch/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml 
-v /data/elasticsearch/data:/usr/share/elasticsearch/data 
-v /data/elasticsearch/logs:/usr/share/elasticsearch/logs 
-v /data/elasticsearch/plugins:/usr/share/elasticsearch/plugins 
elasticsearch:7.12.0

#es-node2:
[root@es-node2 ~]# docker run -d --name es-node2  --network=host --privileged=true  
-e ES_JAVA_OPTS="-Xms6144m -Xmx6144m"  
-e TAKE_FILE_OWNERSHIP=true 
-v /data/elasticsearch/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml 
-v /data/elasticsearch/data:/usr/share/elasticsearch/data 
-v /data/elasticsearch/logs:/usr/share/elasticsearch/logs 
-v /data/elasticsearch/plugins:/usr/share/elasticsearch/plugins 
elasticsearch:7.12.0

#es-node3:
[root@es-node3 ~]# docker run -d --name es-node3  --network=host --privileged=true  
-e ES_JAVA_OPTS="-Xms6144m -Xmx6144m"  
-e TAKE_FILE_OWNERSHIP=true 
-v /data/elasticsearch/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml 
-v /data/elasticsearch/data:/usr/share/elasticsearch/data 
-v /data/elasticsearch/logs:/usr/share/elasticsearch/logs 
-v /data/elasticsearch/plugins:/usr/share/elasticsearch/plugins 
elasticsearch:7.12.0

六、elasticsearch-head安装

[root@es-node1 ~]# docker run -d --name es-head -p 9100:9100 mobz/elasticsearch-head:5

打开
http://192.168.10.128:9100 ,输入连接http://192.168.10.128:9200/,或者上面任意一个节点

声明:本站部分内容来自互联网,如有版权侵犯或其他问题请与我们联系,我们将立即删除或处理。
▍相关推荐
更多资讯 >>>