两台linux系统中docker环境做etcd+app+nginx集群

 

给权限

解压之后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.访问后所有的网页均显示“自己的代办事件列”

访问页面进行测试:

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

秃头的花季少年

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值