给权限
解压之后copy到sbin下
查看版本号
第一台server1:
root@server1:~# ETCDCTL_API=2 etcd --enable-v2 \
> --name etcd1 --data-dir /var/lib/etcd/etcd1 \
> --listen-peer-urls http://192.168.2.148:2380 \
> --listen-client-urls http://192.168.2.148:2379,http://127.0.0.1:2379 \
> --advertise-client-urls http://192.168.2.148:2379 \
> --initial-advertise-peer-urls http://192.168.2.148:2380 \
> --initial-cluster-state new \
> --initial-cluster-token etcd-test \
> --initial-cluster etcd1=http://192.168.2.148:2380,etcd2=http://192.168.2.149:2380 &
第二台server2:
root@server2:~# ETCDCTL_API=2 etcd --enable-v2 \
> --name etcd2 --data-dir /var/lib/etcd/etcd2 \
> --listen-peer-urls http://192.168.2.149:2380 \
> --listen-client-urls http://192.168.2.149:2379,http://127.0.0.1:2379 \
> --advertise-client-urls http://192.168.2.149:2379 \
> --initial-advertise-peer-urls http://192.168.2.149:2380 \
> --initial-cluster-state new \
> --initial-cluster-token etcd-test \
> --initial-cluster etcd1=http://192.168.2.148:2380,etcd2=http://192.168.2.149:2380 &
查看集群是否为健康的:
root@server1:~# etcdctl endpoint health --endpoints http://192.168.2.148:2380,ht
tp://192.168.2.149:2380
第二种查看健康:
root@server1:~# etcdctl --endpoints=192.168.2.148:2379 member list
查看你的哪个节点为master节点:
root@server1:~# ETCDCTL_API=2 etcdctl member list
验证节点是否可以写入数据:
root@server1:~# etcdctl --endpoints 192.168.2.148:2379 put foo bar
到第二台进行查看是否能够看到:
root@server2:~# etcdctl --endpoints 192.168.2.148:2379 get foo
写一个网段配置:
root@server1:~# vim netetcd.json
{ "Network":"10.10.0.0/16","SubnetLen":24,"Backend":{"Type":"host-gw"} }
root@server1:~# ETCDCTL_API=2 etcdctl --endpoints http://192.168.2.148:2379 set
/docker/network/config < /root/netetcd.json
Server2上面进行get:
root@server2:~# ETCDCTL_API=2 etcdctl --endpoints http://192.168.2.148:2379 get
/docker/network/config
下面去启动flanneld两台都启动:
root@server1:~# ./flanneld-amd64 -etcd-endpoints=http://192.168.2.148:2379 \
> -iface=ens33 -etcd-prefix=/docker/network/ &
root@server2:~# ./flanneld-amd64 -etcd-endpoints=http://192.168.2.148:2379 \
> -iface=ens33 -etcd-prefix=/docker/network/ &
Server1修改docker0:
root@server1:~# vim /usr/lib/systemd/system/docker.service
添加:
--bip=10.10.7.1/24 --mtu=1500
root@server1:~# ip a
Server2修改docker0:
root@server2:~# cat /var/run/flannel/subnet.env
root@server2:~# vim /usr/lib/systemd/system/docker.service
添加:
--bip=10.10.83.1/24 --mtu=1500
root@server1:~# ip a
Server1上面运行web1和web2:
root@server1:~/app# docker run --name web1 -d -p 3000:3000 --workdir /app --volumes-from app_volume node:12-alpine sh -c "yarn install && yarn run dev"
root@server1:~/app# docker exec -it web1 ip a
root@server1:~/app# docker run --name web2 -d -p 3001:3000 --workdir /app --v
olumes-from app_volume node:12-alpine sh -c "yarn install && yarn run dev"
root@server1:~/app# docker exec -it web2 ip a
server上面运行web3和web4,在运行一个nginx:
root@server2:~/app# docker run --name web3 -d -p 3000:3000 --workdir /app --v
olumes-from app_volume node:12-alpine sh -c "yarn install && yarn run dev"
root@server2:~/app# docker exec web3 ip a
root@server2:~/app# docker run --name web4 -d -p 3001:3000 --workdir /app --v
olumes-from app_volume node:12-alpine sh -c "yarn install && yarn run dev"
root@server2:~/app# docker exec web4 ip a
使用nginx镜像做集群代理(提示一定和集群内的容器在一个网络里面才可以访问)
在server2中启动nginx镜像
root@server2:~/app# docker cp nginx:/etc/nginx/conf.d ./
root@server2:~/app# docker cp nginx:/etc/nginx/nginx.conf ./
root@server2:~/app# vim conf.d/default.conf
root@server2:~/app# vim nginx.conf
docker run -itd --name nginx -p 80:80 --volume $(pwd)/conf.d/default.conf:/etc/nginx/conf.d/default.conf --volume $(pwd)/nginx.conf:/etc/nginx/nginx.conf nginx
3.app.zip镜像使用data-packed volume container
root@server1:~# mkdir app
root@server1:~# cd app/
root@server1:~# mv ~/app.zip ./
root@server1:~# unzip app.zip
root@server1:~/app# vim Dockerfile
root@server1:~# docker build -t appdapacked ./
root@server1:~# docker create --name app_volume appdapacked
root@server1:~# docker images
root@server1:~/app# docker ps -a
docker run -d -p 3000:3000 --workdir /app --volumes-from app_vol
ume node:12-alpine sh -c "yarn install && yarn run dev"
l root@server1:~/app# docker inspect app
4.访问后所有的网页均显示“自己的代办事件列”
访问页面进行测试: