首先安装docker
安装命令如下:安装
curl -fsSL https://get.docker.com | bash -s docker --mirror aliyun
也可以使用国内 daocloud 一键安装命令:
curl -sSL https://get.daocloud.io/docker | sh
安装成功后,输入docker -v命令即可
Docker version 20.10.6, build 370c289
或者也可以直接输入docker,报错(-bash: docker: command not found)则安装失败,否则则安装成功
systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: https://docs.docker.com
启动docker:
systemctl start docker
centos下docker-compose 安装
sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
通过docker-compose version查看docker-compose版本,确认是否安装成功。
docker-compose version 1.27.4, build 40524192
docker-py version: 4.3.1
CPython version: 3.7.7
OpenSSL version: OpenSSL 1.1.0l 10 Sep 2019
创建相关的文件
cd /home
mkdir newNode
cd newNode
mkdir config data1 data2 data3 plugins
es1.yml内容如下
cluster.name: elasticsearch-cluster #集群唯一名称,所有节点一致
node.name: es-node1 #节点名称
network.bind_host: 0.0.0.0 #设置可以访问的ip,默认为0.0.0.0,这里全部设置通过
network.publish_host: _eth0_ #设置其它结点和该结点交互的ip地址(eth0是ifconfig中)
http.port: 9200 #设置对外服务的http端口,默认为9200
transport.tcp.port: 9300 #设置节点之间交互的tcp端口,默认是9300
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true #配置该结点是否有资格被选举为主结点(候选主结点),为了防止脑裂,配置奇数个候选主结点
node.data: true #配置该结点是数据结点,用于保存数据
discovery.seed_hosts: ["ES01:9300","ES02:9301","ES03:9302"] #集群个节点IP地址
cluster.initial_master_nodes: ["es-node1","es-node2","es-node3"] #设置一系列符合主节点条件的节点的主机名或 IP 地址来引导启动集群
discovery.zen.minimum_master_nodes: 1 #自动发现master节点的最小数
对应的es2.yml和es3.yml只需要修改node.name为es-node2和es-node3即可。
cd plugins
mkdir ik
vim docker-compose.yml
yml的内容:
version: '1.0'
services:
es1:
image: elasticsearch:7.4.2 #修改你需要的es镜像的版本
container_name: ES01
environment:
- ES_JAVA_OPTS=-Xms512m -Xmx512m
ports:
- "9200:9200"
- "9300:9300"
volumes:
- /home/newNode/config/es1.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- /home/newNode/plugins:/usr/share/elasticsearch/plugins
networks:
- es-net
es2:
image: elasticsearch:7.4.2 #修改你需要的es镜像的版本
container_name: ES02
environment:
- ES_JAVA_OPTS=-Xms512m -Xmx512m
ports:
- "9201:9200"
- "9301:9300"
volumes:
- /home/newNode/config/es2.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- /home/newNode/plugins:/usr/share/elasticsearch/plugins
networks:
- es-net
es3:
image: elasticsearch:7.4.2 #修改你需要的es镜像的版本
container_name: ES03
environment:
- ES_JAVA_OPTS=-Xms512m -Xmx512m
ports:
- "9202:9200"
- "9302:9300"
volumes:
- /home/newNode/config/es3.yml:/usr/share/elasticsearch/config/elasticsearch.yml
- /home/newNode/plugins:/usr/share/elasticsearch/plugins
networks:
- es-net
es-head:
image: tobias74/elasticsearch-head
ports:
- "9100:9100"
networks:
es-net:
driver: bridge
安装ik插件
cd ik
wget https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.4.2/elasticsearch-analysis-ik-7.4.2.zip
unzip elasticsearch-analysis-ik-7.4.2.zip
保证ik文件夹中的内容如下图所示:
启动docker
docker-compose up -d
docker-compose logs
发现日志有analysis-ik则说明插件启动成功
访问地址 http://ip地址:9100 (ip地址是你eth0的Ipv4地址)
head中输入:http://ip地址:9200(ip地址是你eth0的Ipv4地址)
看到上面的图,其实我还真不确认是不是集群部署成功,那么创建一个索引试试
curl-X PUT"localhost:9200/twitter?pretty"-H'Content-Type:application/json'-d'{"settings":{"index":{"number_of_shards":3,"number_of_replicas":2}}}'
集群搭建成功
查看集群状态
curl -XGET http://IP地址:9200/_cat/nodes?v
ip heap.percent ram.percent cpu load_1m load_5m load_15m node.role master name
172*** 20 95 2 0.00 0.18 0.27 dilm * es-node2
172*** 44 95 2 0.00 0.18 0.27 dilm - es-node1
172*** 28 95 2 0.00 0.18 0.27 dilm - es-node3
参考地址:
Docker搭建es集群 -