Linux基于Docker搭建Elasticsearch-7.12.0集群亲测可用

前言

提示:上文我们已经安装了elasticsearch:7.12.0和kibana:7.12.0


一、设置Elasticsearch挂载目录

设置文件夹

#存放配置文件的文件夹
mkdir -p /home/elasticsearch-7.12.0/esnode-1/config
mkdir -p /home/elasticsearch-7.12.0/esnode-2/config
mkdir -p /home/elasticsearch-7.12.0/esnode-3/config
#存放数据的文件夹
mkdir -p /home/elasticsearch-7.12.0/esnode-1/data
mkdir -p /home/elasticsearch-7.12.0/esnode-2/data
mkdir -p /home/elasticsearch-7.12.0/esnode-3/data
#存放运行日志的文件夹
mkdir -p /home/elasticsearch-7.12.0/esnode-1/log
mkdir -p /home/elasticsearch-7.12.0/esnode-2/log
mkdir -p /home/elasticsearch-7.12.0/esnode-3/log
#存放IK分词插件的文件夹
mkdir -p /home/elasticsearch-7.12.0/esnode-1/plugins
mkdir -p /home/elasticsearch-7.12.0/esnode-2/plugins
mkdir -p /home/elasticsearch-7.12.0/esnode-3/plugins

对文件加设置开放权限

chmod 777 /home/elasticsearch-7.12.0/esnode-1/data
chmod 777 /home/elasticsearch-7.12.0/esnode-2/data
chmod 777 /home/elasticsearch-7.12.0/esnode-3/data
chmod 777 /home/elasticsearch-7.12.0/esnode-1/plugins
chmod 777 /home/elasticsearch-7.12.0/esnode-2/plugins
chmod 777 /home/elasticsearch-7.12.0/esnode-3/plugins
chmod 777 /home/elasticsearch-7.12.0/esnode-1/log
chmod 777 /home/elasticsearch-7.12.0/esnode-2/log
chmod 777 /home/elasticsearch-7.12.0/esnode-3/log
chmod 777 /home/elasticsearch-7.12.0/esnode-1/config
chmod 777 /home/elasticsearch-7.12.0/esnode-3/config
chmod 777 /home/elasticsearch-7.12.0/esnode-2/config

二、创建多个yml到data目录

在每个节点的config下创建elasticsearch.yml文件

  • 创建节点1的elasticsearch.yml
cd /home/elasticsearch-7.12.0/esnode-1/config
vim elasticsearch.yml

elasticsearch.yml文件内容

cluster.name: my-es
node.name: node-1
node.master: true
node.data: true
node.max_local_storage_nodes: 4
path.data: /usr/share/elasticsearch/data
path.logs: /usr/share/elasticsearch/log
network.host: 0.0.0.0
network.publish_host: 192.168.28.129
http.port: 9201
transport.tcp.port: 9301
discovery.seed_hosts: ["192.168.28.129:9301","192.168.28.129:9302","192.168.28.129:9303"]
cluster.initial_master_nodes: ["node-1","node-2","node-3"]
gateway.recover_after_nodes: 3
  • 创建节点2的elasticsearch.yml
cd /home/elasticsearch-7.12.0/esnode-2/config
vim elasticsearch.yml

elasticsearch.yml文件内容

cluster.name: my-es
node.name: node-2
node.master: true
node.data: true
node.max_local_storage_nodes: 4
path.data: /usr/share/elasticsearch/data
path.logs: /usr/share/elasticsearch/log
network.host: 0.0.0.0
network.publish_host: 192.168.28.129
http.port: 9202
transport.tcp.port: 9302
discovery.seed_hosts: ["192.168.28.129:9301","192.168.28.129:9302","192.168.28.129:9303"]
cluster.initial_master_nodes: ["node-1","node-2","node-3"]
gateway.recover_after_nodes: 2
  • 创建节点3的elasticsearch.yml
cd /home/elasticsearch-7.12.0/esnode-3/config
vim elasticsearch.yml

elasticsearch.yml文件内容

cluster.name: my-es
node.name: node-3
node.master: true
node.data: true
node.max_local_storage_nodes: 4
path.data: /usr/share/elasticsearch/data
path.logs: /usr/share/elasticsearch/log
network.host: 0.0.0.0
network.publish_host: 192.168.28.129
http.port: 9203
transport.tcp.port: 9303
discovery.seed_hosts: ["192.168.28.129:9301","192.168.28.129:9302","192.168.28.129:9303"]
cluster.initial_master_nodes: ["node-1","node-2","node-3"]
gateway.recover_after_nodes: 2

三、放行端口

  • 放行相关端口
firewall-cmd --zone=public --add-port=9200/tcp --permanent
firewall-cmd --zone=public --add-port=9201/tcp --permanent
firewall-cmd --zone=public --add-port=9202/tcp --permanent
firewall-cmd --zone=public --add-port=9300/tcp --permanent
firewall-cmd --zone=public --add-port=9301/tcp --permanent
firewall-cmd --zone=public --add-port=9302/tcp --permanent
#这个是kibana端口,等会会用到
firewall-cmd --zone=public --add-port=5601/tcp --permanent

  • 更新防火墙规则
firewall-cmd --complete-reload
  • 查看当前所开放的端口
firewall-cmd --zone=public --list-ports

三、安装并启动es节点

docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9201:9201 -p 9301:9301 -v /home/elasticsearch-7.12.0/esnode-1/config/elasticsearch-7.12.0.yml:/usr/share/elasticsearch-7.12.0/config/elasticsearch-7.12.0.yml -v /home/elasticsearch-7.12.0/esnode-1/plugins:/usr/share/elasticsearch-7.12.0/plugins -v /home/elasticsearch-7.12.0/esnode-1/data:/usr/share/elasticsearch-7.12.0/data -v /home/elasticsearch-7.12.0/esnode-1/log:/usr/share/elasticsearch-7.12.0/log --name es-esnode-1 elasticsearch-7.12.0:7.12.0

docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9202:9202 -p 9302:9302 -v /home/elasticsearch-7.12.0/esnode-2/config/elasticsearch-7.12.0.yml:/usr/share/elasticsearch-7.12.0/config/elasticsearch-7.12.0.yml -v /home/elasticsearch-7.12.0/esnode-2/plugins:/usr/share/elasticsearch-7.12.0/plugins -v /home/elasticsearch-7.12.0/esnode-2/data:/usr/share/elasticsearch-7.12.0/data -v /home/elasticsearch-7.12.0/esnode-2/log:/usr/share/elasticsearch-7.12.0/log --name es-esnode-2 elasticsearch-7.12.0:7.12.0

docker run -e ES_JAVA_OPTS="-Xms256m -Xmx256m" -d -p 9203:9203 -p 9303:9303 -v /home/elasticsearch-7.12.0/esnode-3/config/elasticsearch-7.12.0.yml:/usr/share/elasticsearch-7.12.0/config/elasticsearch-7.12.0.yml -v /home/elasticsearch-7.12.0/esnode-3/plugins:/usr/share/elasticsearch-7.12.0/plugins -v /home/elasticsearch-7.12.0/esnode-3/data:/usr/share/elasticsearch-7.12.0/data -v /home/elasticsearch-7.12.0/esnode-3/log:/usr/share/elasticsearch-7.12.0/log --name es-esnode-3 elasticsearch-7.12.0:7.12.0

三、检测集群是否的搭建成功

打开浏览器,输入地址http://192.168.28.129:9201/_cat/nodes?pretty

http://192.168.28.129:9201/_cat/nodes?pretty

搭建成功会出现
在这里插入图片描述

四、创建Kibana的YML文件

前面我们已经创建过Kibana的yml文件,目录是
/data/elk7/kibana/config/kibana.yml,如果还未创建,可自行创建

vim /data/elk7/kibana/config/kibana.yml
erver.port: 5601
server.host: "0.0.0.0"
server.name: "kibana-192.168.28.129"
elasticsearch.hosts: ["http://192.168.28.129:9201","http://192.168.28.129:9202","http://192.168.28.129:9203"]
i18n.locale: "zh-CN"
xpack.monitoring.ui.container.elasticsearch.enabled: true

五、安装并启动Kibana容器

输入命令,指定network网络

docker run -d -p 5601:5601 -v /home/kibana/config/kibana.yml:/usr/share/kibana/config/kibana.yml --network es-net  --name kibana1 kibana:7.12.0

六、登录网址进行验证

http://192.168.28.129:5601

在这里插入图片描述

好的,以下是一个简单的docker-compose文件,以启动一个Skywalking集群: ``` version: '3' services: skywalking-oap: image: apache/skywalking-oap-server:8.6.0-es6 container_name: skywalking-oap environment: - SW_CLUSTER=standalone - SW_STORAGE_TYPE=elasticsearch7 - SW_ES_CLUSTER_NODES=elasticsearch1:9200,elasticsearch2:9200,elasticsearch3:9200 ports: - 12800:12800 depends_on: - elasticsearch1 - elasticsearch2 - elasticsearch3 networks: - skywalking elasticsearch1: image: elasticsearch:7.12.0 container_name: elasticsearch1 environment: - cluster.name=skywalking - node.name=elasticsearch1 - discovery.seed_hosts=elasticsearch2,elasticsearch3 - cluster.initial_master_nodes=elasticsearch1,elasticsearch2,elasticsearch3 - ES_JAVA_OPTS=-Xms512m -Xmx512m ulimits: memlock: soft: -1 hard: -1 volumes: - esdata1:/usr/share/elasticsearch/data ports: - 9200:9200 networks: - skywalking elasticsearch2: image: elasticsearch:7.12.0 container_name: elasticsearch2 environment: - cluster.name=skywalking - node.name=elasticsearch2 - discovery.seed_hosts=elasticsearch1,elasticsearch3 - cluster.initial_master_nodes=elasticsearch1,elasticsearch2,elasticsearch3 - ES_JAVA_OPTS=-Xms512m -Xmx512m ulimits: memlock: soft: -1 hard: -1 volumes: - esdata2:/usr/share/elasticsearch/data networks: - skywalking elasticsearch3: image: elasticsearch:7.12.0 container_name: elasticsearch3 environment: - cluster.name=skywalking - node.name=elasticsearch3 - discovery.seed_hosts=elasticsearch1,elasticsearch2 - cluster.initial_master_nodes=elasticsearch1,elasticsearch2,elasticsearch3 - ES_JAVA_OPTS=-Xms512m -Xmx512m ulimits: memlock: soft: -1 hard: -1 volumes: - esdata3:/usr/share/elasticsearch/data networks: - skywalking volumes: esdata1: esdata2: esdata3: networks: skywalking: ``` 在这个docker-compose文件中,我们定义了四个服务:`skywalking-oap`、`elasticsearch1`、`elasticsearch2`和`elasticsearch3`。 其中,`skywalking-oap`是Skywalking的OAP服务器,它使用了Skywalking的官方Docker镜像,并且设置了环境变量来连接到Elasticsearch集群。我们将它映射到了主机的12800端口,以便我们可以访问Skywalking的Web界面。 `elasticsearch1`、`elasticsearch2`和`elasticsearch3`是三个Elasticsearch节点,它们使用了官方的Elasticsearch镜像,并且设置了一些环境变量来启用集群功能。我们将它们映射到了主机的9200端口,以便我们可以在浏览器中查看Elasticsearch的状态。 这个docker-compose文件还定义了一个`skywalking`网络,用于连接所有的服务。 最后,我们使用`docker-compose up`命令来启动整个集群
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值