Bootstrap

ES(Elasticsearch)的docker安装部署教程

0、 服务器版本信息

Red Hat 4.8.5-44

CentOS Linux release 7.9.2009 (Core)

java version "1.8.0_281"

Docker version 20.10.6, build 370c289

1、ES部署

1.1  拉取docker镜像

docker pull elasticsearch:7.10.1

拉取成功的镜像,可以使用如下命令查看:

docker images

注:上图2年之前表示该elasticsearch的7.10.1镜像版本是2年前制作的。

1.2 创建es挂载目录

mkdir data

cd /data        

mkdir elasticsearch

cd /data/elasticsearch

1.3 桥接网络节点配置

ES集群安装要求桥接网络和一定的vm配置,执行./network.sh

sysctl -w vm.max_map_count=262144
docker network ls
docker network create --driver  bridge --subnet=172.18.12.0/16 --gateway=172.18.0.1 esnet

1.4 解压es证书配置文件

下载链接见:https://download.csdn.net/download/qq_33034733/88137295

tar -zxvf es-cfg.tar.gz cfg

1.5 创建ES主节点实例

给master.sh加执行权限:chmod u+x master.sh

执行./master.sh 直接创建2个主节点,

for port in $(seq 1 2); \
do \
mkdir -p /data/elasticsearch/master-${port}/config
cp -rf /data/elasticsearch/cfg/* /data/elasticsearch/master-${port}/config
mkdir -p /data/elasticsearch/master-${port}/data
mkdir -p /data/elasticsearch/master-${port}/logs
mkdir -p /data/elasticsearch/master-${port}/plugins
chmod -R 777 /data/elasticsearch/master-${port}
cat << EOF > /data/elasticsearch/master-${port}/config/elasticsearch.yml
cluster.name: imes-es  #集群的名称,同一个集群该值必须设置成相同的
node.name: es-master-${port}  #该节点的名字
node.master: true  #该节点有机会成为master节点
node.data: false #该节点可以存储数据
network.host: 0.0.0.0
http.host: 0.0.0.0   #所有http均可访问
http.port: 920${port}
transport.tcp.port: 930${port}
http.cors.enabled: true
http.cors.allow-origin: "*"
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate  
xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12   
xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12
discovery.zen.ping_timeout: 10s #设置集群中自动发现其他节点时ping连接的超时时间
discovery.seed_hosts: ["172.18.12.91:9301","172.18.12.92:9302"]
cluster.initial_master_nodes: ["es-master-1"] #新集群初始时的候选主节点,es7的新增配置
EOF
docker run --name es-master-${port} \
-p 920${port}:920${port} -p 930${port}:930${port} \
--privileged=true --network=esnet --ip 172.18.12.9${port} \
-e ES_JAVA_OPTS="-Xms512m -Xmx512m" \
-v /data/elasticsearch/master-${port}/config:/usr/share/elasticsearch/config  \
-v /data/elasticsearch/master-${port}/data:/usr/share/elasticsearch/data  \
-v /data/elasticsearch/master-${port}/logs:/usr/share/elasticsearch/logs  \
-v /data/elasticsearch/master-${port}/plugins:/usr/share/elasticsearch/plugins  \
-d elasticsearch:7.10.1
done

1.6 创建ES从节点实例

给slave.sh加执行权限:chmod u+x slave.sh

然后执行./slave.sh 直接创建3个从节点的实例

for port in $(seq 4 6); \
do \
mkdir -p /data/elasticsearch/node-${port}/config
cp -rf /data/elasticsearch/cfg/* /data/elasticsearch/node-${port}/config
mkdir -p /data/elasticsearch/node-${port}/data
mkdir -p /data/elasticsearch/node-${port}/logs
mkdir -p /data/elasticsearch/node-${port}/plugins
chmod -R 777 /data/elasticsearch/node-${port}
cat << EOF > /data/elasticsearch/node-${port}/config/elasticsearch.yml
cluster.name: imes-es  #集群的名称,同一个集群该值必须设置成相同的
node.name: es-node-${port}  #该节点的名字
node.master: false  #该节点有机会成为master节点
node.data: true #该节点可以存储数据
network.host: 0.0.0.0
http.host: 0.0.0.0   #所有http均可访问
http.port: 920${port}
transport.tcp.port: 930${port}
http.cors.enabled: true
http.cors.allow-origin: "*"
xpack.security.enabled: true
xpack.security.transport.ssl.enabled: true
xpack.security.transport.ssl.verification_mode: certificate  
xpack.security.transport.ssl.keystore.path: certs/elastic-certificates.p12   
xpack.security.transport.ssl.truststore.path: certs/elastic-certificates.p12
discovery.zen.ping_timeout: 10s #设置集群中自动发现其他节点时ping连接的超时时间
discovery.seed_hosts: ["172.18.12.91:9301","172.18.12.92:9302"]
cluster.initial_master_node
;