CrateDB三机三节点部署(Docker Overlay网络)
1.基础环境
三台服务器
vm01: 192.168.1.101
vm02: 192.168.1.102
vm03: 192.168.1.103
设置hostname
#vm01
hostnamectl set-hostname vm01
service docker restart
#vm02
hostnamectl set-hostname vm02
service docker restart
#vm03
hostnamectl set-hostname vm03
service docker restart
修改系统参数
IPv6会影响到overlay网络的运行,需要关掉。
开启IPv4 Forward路由转发功能。
修改三台机的系统参数。
vi /etc/sysctl.conf
增加以下参数:
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv4.ip_forward=1
sysctl -p
关闭防火墙
关闭三台机的防火墙。
service iptables stop
service firewalld stop
2.创建Swarm集群
在vm01执行初始化
docker swarm init
初始化成功显示如下:
Swarm initialized: current node (brjg2ltw1sv4dihlxjr6tkojp) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-4hj1cuiz76i7jkw5uwpiomi4kulkrfulcan51v6mz5y88orv8n-65o0wega86chw0nreghmtofw1 192.168.1.101:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
根据以上提示,复制docker swarm join
命令行,在vm02和vm03执行docker swarm join
,加入swarm集群
docker swarm join --token SWMTKN-1-4hj1cuiz76i7jkw5uwpiomi4kulkrfulcan51v6mz5y88orv8n-65o0wega86chw0nreghmtofw1 192.168.1.101:2377
执行成功后,显示
This node joined a swarm as a worker.
在vm01上查看集群节点信息(也可在vm02和vm03上查看)
docker node ls
结果如下所示
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS ENGINE VERSION
7eawdhzcvb1vx2gj7nr3fuge5 vm02 Ready Active 19.03.1
brjg2ltw1sv4dihlxjr6tkojp * vm01 Ready Active Leader 19.03.1
sp8taco3e5qivv26dy8a0jm57 vm03 Ready Active 19.03
3.创建overlay网络
在vm01上创建overlay网络,vm02和vm03会自动加入overlay网络。attachable参数开始container访问权限,默认只可被service使用。
docker network create -d overlay --attachable crate
4.创建CrateDB容器
vm01
mkdir -p /apps/cratedb
docker run --rm -d \
--name=crate01 \
--hostname=crate01 \
--net=crate \
-v /apps/cratedb:/data \
-v /etc/localtime:/etc/localtime \
-p 4200:4200 \
-p 5432:5432 \
-p 4300:4300 \
--env CRATE_HEAP_SIZE=2g \
crate -Cnetwork.host=_site_ \
-Cnode.name=crate01 \
-Cdiscovery.seed_hosts=crate02,crate03 \
-Ccluster.initial_master_nodes=crate01,crate02,crate03 \
-Cgateway.expected_nodes=3 -Cgateway.recover_after_nodes=2
vm02
mkdir -p /apps/cratedb
docker run --rm -d \
--name=crate02 \
--hostname=crate02 \
--net=crate \
-v /apps/cratedb:/data \
-v /etc/localtime:/etc/localtime \
-p 4200:4200 \
-p 5432:5432 \
-p 4300:4300 \
--env CRATE_HEAP_SIZE=2g \
crate -Cnetwork.host=_site_ \
-Cnode.name=crate02 \
-Cdiscovery.seed_hosts=crate01,crate03 \
-Ccluster.initial_master_nodes=crate01,crate02,crate03 \
-Cgateway.expected_nodes=3 -Cgateway.recover_after_nodes=2
vm03
mkdir -p /apps/cratedb
docker run --rm -d \
--name=crate03 \
--hostname=crate03 \
--net=crate \
-v /apps/cratedb:/data \
-v /etc/localtime:/etc/localtime \
-p 4200:4200 \
-p 5432:5432 \
-p 4300:4300 \
--env CRATE_HEAP_SIZE=2g \
crate -Cnetwork.host=_site_ \
-Cnode.name=crate03 \
-Cdiscovery.seed_hosts=crate01,crate02,crate03 \
-Cgateway.expected_nodes=3 -Cgateway.recover_after_nodes=2
5.访问web页面
http://192.168.1.101:4200/
参考:
https://blog.csdn.net/lizongti/article/details/99330651