ETCD集群搭建

2018-06-10  本文已影响0人  wuyuan0127

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

节点1执行:

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&

节点2执行:

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&

查看状态:

./etcdctl cluster-health

docker 应用 etcd: (先停止docker服务,再重启docker服务)

修改 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

----- 也可以命令行执行 :(不修改配置文件)

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 用于 多机网络 创建 overlay:

在节点1 创建  docker network create -d overlay demo

查看 : docker network ls

此时在 node2 查看: 也已经有 overlay demo 网络 [通过 ETCD 同步 ]

docker network ls

上一篇下一篇

猜你喜欢

热点阅读