LINUX 安装docker 和ES完全详细过程。
(https://blog.csdn.net/weixin_45844208/article/details/140521002)
安装的docker版本为 26.1.0
https://download.docker.com/linux/static/stable/x86_64/
安装的docker-compose的版本为:2.28.1
https://github.com/docker/compose/releases/download
https://github.com/docker/compose/releases/download/v2.27.1/docker-compose-linux-x86_64
1:上传到服务器然后解压
sudo tar -zxvf docker-26.1.4-x86_64.tgz
2:给权限
sudo chmod 755 -R docker
3:复制到环境变量目录
sudo cp docker/* /usr/bin/
4:配置创建docker服务配置文件docker.service
sudo vim /etc/systemd/system/docker.service
添加如下内容
[Unit]
Description=Docker Application Container Engine
Documentation=https://docs.docker.com
After=network-online.target firewalld.service
Wants=network-online.target
[Service]
Type=notify
ExecStart=/usr/bin/dockerd
ExecReload=/bin/kill -s HUP $MAINPID
TimeoutSec=0
RestartSec=2
ExecStartPost=/usr/sbin/iptables -P FORWARD ACCEPT
Restart=always
TimeoutStartSec=0
LimitNOFILE=infinity
LimitNPROC=infinity
LimitCORE=infinity
Delegate=yes
KillMode=process
StartLimitBurst=3
StartLimitInterval=60s
[Install]
WantedBy=multi-user.target
5:# 赋予docker服务配置文件docker.service执行权限
sudo chmod +x /etc/systemd/system/docker.service
6:docker服务相关命令
加载systemctl配置
sudo systemctl daemon-reload
启用docker服务开机自启动
sudo systemctl enable docker.service
启动docker服务
sudo systemctl start docker
检查docker服务状态
sudo systemctl status docker
查看安装的docker版本
sudo docker -v
查看更改自定义后的docker服务信息
sudo docker info
二:安装docker-compose
复制docker-compose到/usr/local/bin/目录下
sudo cp -f docker-compose-linux-x86_64.v2.28.1 /usr/local/bin/docker-compose
赋予docker-compose可执行权限
sudo chmod +x /usr/local/bin/docker-compose
查看docker-compose版本
sudo docker-compose -v
三:安装部署ES集群
本次安装的ES版本为7.17.25
-1:本次为离线安装,首先需要在有线电脑下载镜像
docker pull docker.elastic.co/elasticsearch/elasticsearch:7.17.25
0:将镜像打包然后上传到服务器
docker save docker.elastic.co/elasticsearch/elasticsearch:7.17.25 -o elasticsearch-7.17.25.tar
0.1:然后在服务器上通过docker加载这个镜像
docker load -i elasticsearch-7.17.25.tar
0.2然后通过docker就可以看大这个镜像了
[root@a_pnw_nginx03 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
docker.elastic.co/elasticsearch/elasticsearch 7.17.25 2574569e84a1 5 weeks ago 634MB
- 创建Docker网络
为了让集群中的各个节点可以互相通信,我们需要先创建一个Docker网络:
docker network create es-network
2编写:docker-compose.yml 内容如下
注意:下面image 的内容就是上面展示镜像REPOSITORY的名字
services:
es01:
image: “docker.elastic.co/elasticsearch/elasticsearch:7.17.25”
container_name: es01
ports:
- “9200:9200”
- “9300:9300”
environment:
node.name: es01
discovery.seed_hosts: es01,es02,10.189.131.82:9300,10.189.131.82:9301
cluster.initial_master_nodes: es01,es02,10.189.131.82:9300,10.189.131.82:9301
cluster.name: myescluster
http.cors.enabled: true
http.cors.allow-origin: “"
ES_JAVA_OPTS: -Xms512m -Xmx512m
xpack.security.enabled: true
ELASTIC_PASSWORD: QAZ2@wsx
volumes:
- “/usr/local/es_cluster/node_1/data:/usr/share/elasticsearch/data”
- “/usr/local/es_cluster/node_1/logs:/usr/share/elasticsearch/logs”
- “/usr/local/es_cluster/node_1/plugins:/usr/share/elasticsearch/plugins”
networks:
- es-network
ulimits:
memlock:
soft: -1
hard: -1
es02:
image: “docker.elastic.co/elasticsearch/elasticsearch:7.17.25”
container_name: es02
ports:
- “9201:9200”
- “9301:9300”
environment:
node.name: es02
discovery.seed_hosts: es01,es02,10.189.131.82:9300,10.189.131.82:9301
cluster.initial_master_nodes: es01,es02,10.189.131.82:9300,10.189.131.82:9301
cluster.name: myescluster
http.cors.enabled: true
http.cors.allow-origin: "”
ES_JAVA_OPTS: -Xms512m -Xmx512m
xpack.security.enabled: true
ELASTIC_PASSWORD: QAZ2@wsx
volumes:
- “/usr/local/es_cluster/node_2/data:/usr/share/elasticsearch/data”
- “/usr/local/es_cluster/node_2/logs:/usr/share/elasticsearch/logs”
- “/usr/local/es_cluster/node_2/plugins:/usr/share/elasticsearch/plugins”
networks:
- es-network
ulimits:
memlock:
soft: -1
hard: -1
networks:
es-network:
driver: bridge
3:服务器创建挂载目录
mkdir -p /usr/local/es_cluster/node_1/data
mkdir -p /usr/local/es_cluster/node_1/logs
mkdir -p /usr/local/es_cluster/node_1/plugins/ik
mkdir -p /usr/local/es_cluster/node_2/data
mkdir -p /usr/local/es_cluster/node_2/logs
mkdir -p /usr/local/es_cluster/node_2/plugins/ik
并给予执行权限
sudo chmod +x /usr/local/es_cluster/
4:下载中文分词器
https://github.com/medcl/elasticsearch-analysis-ik/releases
在这个链接找对应版本的分词器版本。没有就下载当前版本最高的
然后注意 如果分词版本和ES版本不一致需要将分词版本改为一致
分词下载后需要解压到 映射目录
执行
unzip /wls/pansky/elasticsearch-analysis-ik-7.17.6.zip -d /usr/local/es_cluster/node_1/plugins/ik
unzip /wls/pansky/elasticsearch-analysis-ik-7.17.6.zip -d /usr/local/es_cluster/node_2/plugins/ik
然后修改版本号
cd /usr/local/es_cluster/node_1/plugins/ik
vim plugin-descriptor.properties
修改两处地方哦。
改为和ES版本一致的版本号
5:然后在服务新建一个目录单独存放ES的docker-compose.yml
用户名不可以自己定义 是系统默认的 elastic
然后执行:docker-compose up -d
就可以启动成功。
通过 docker ps -a 查看启动情况
如果报错 可以通过 docker-compose up 查看错误原因。
或者 docker logs 服务名字查看日志
docker-compose down
curl -u elastic:QAZ2@wsx -X GET “http://10.190.131.81:9200/_cat/nodes?v”