1.下載
wget https://github.com/coreos/etcd/releases/download/v3.0.12/etcd-v3.0.12-linux-amd64.tar.gz
2.解壓
tar zxvf etcd-v3.0.12-linux-amd64.tar.gz
cd etcd-v3.0.12-linux-amd64
3.啟動 node1
節(jié)點(diǎn)1執(zhí)行:
nohup ./etcd --name docker-node1 --initial-advertise-peer-urls http://192.168.205.10:2380 \
--listen-peer-urls http://192.168.205.10:2380 \
--listen-client-urls http://192.168.205.10:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://192.168.205.10:2379 \
--initial-cluster-token etcd-cluster \
--initial-cluster docker-node1=http://192.168.205.10:2380,docker-node2=http://192.168.205.11:2380 \
--initial-cluster-state new&
節(jié)點(diǎn)2執(zhí)行:
nohup ./etcd --name docker-node2 --initial-advertise-peer-urls http://192.168.205.11:2380 \
--listen-peer-urls http://192.168.205.11:2380 \
--listen-client-urls http://192.168.205.11:2379,http://127.0.0.1:2379 \
--advertise-client-urls http://192.168.205.11:2379 \
--initial-cluster-token etcd-cluster \
--initial-cluster docker-node1=http://192.168.205.10:2380,docker-node2=http://192.168.205.11:2380 \
--initial-cluster-state new&
查看狀態(tài):
./etcdctl cluster-health
docker 應(yīng)用 etcd: (先停止docker服務(wù),再重啟docker服務(wù))
修改?vi /usr/lib/systemd/system/docker.service 文件?
ExecStart后面添加 :
-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store=etcd://192.168.205.10:2379 --cluster-advertise=192.168.205.10:2375
-H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store=etcd://192.168.205.11:2379 --cluster-advertise=192.168.205.11:2375
[Unit]
Description=Docker Application Container Engine
Documentation=http://docs.docker.com
After=network.target rhel-push-plugin.socket registries.service
Wants=docker-storage-setup.service
Requires=docker-cleanup.timer
[Service]
Type=notify
NotifyAccess=all
EnvironmentFile=-/run/containers/registries.conf
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
Environment=GOTRACEBACK=crash
Environment=DOCKER_HTTP_HOST_COMPAT=1
Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin
ExecStart=/usr/bin/dockerd-current -H tcp://0.0.0.0:2375 -H unix://var/run/docker.sock? \
? ? ? ? ? --add-runtime docker-runc=/usr/libexec/docker/docker-runc-current \
? ? ? ? ? --default-runtime=docker-runc \
? ? ? ? ? --exec-opt native.cgroupdriver=systemd \
? ? ? ? ? --userland-proxy-path=/usr/libexec/docker/docker-proxy-current \
? ? ? ? ? --init-path=/usr/libexec/docker/docker-init-current \
? ? ? ? ? --seccomp-profile=/etc/docker/seccomp.json \
? ? ? ? ? $OPTIONS \
? ? ? ? ? $DOCKER_STORAGE_OPTIONS \
? ? ? ? ? $DOCKER_NETWORK_OPTIONS \
? ? ? ? ? $ADD_REGISTRY \
? ? ? ? ? $BLOCK_REGISTRY \
? ? ? ? ? $INSECURE_REGISTRY \
? ? ? ? ? $REGISTRIES
ExecReload=/bin/kill -s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
Restart=on-abnormal
KillMode=process
[Install]
WantedBy=multi-user.target
----- 也可以命令行執(zhí)行 :(不修改配置文件)
service docker stop
/usr/bin/dockerd -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock --cluster-store=etcd://192.168.205.10:2379 --cluster-advertise=192.168.205.10:2375&
通過 ETCD 用于 多機(jī)網(wǎng)絡(luò) 創(chuàng)建 overlay:
在節(jié)點(diǎn)1 創(chuàng)建 ?docker network create -d?overlay demo
查看 : docker network ls
此時(shí)在 node2 查看: 也已經(jīng)有 overlay demo 網(wǎng)絡(luò) [通過 ETCD 同步 ]
docker network ls