wscp用于本机和虚拟机传递文件
cd 到项目根目录,执行npm run build
在项目里会生成dist目录,把这个目录里的文件上传到Nginx中运行.
第一步docker search nginx
第二步 ]# docker pull nginx
第三步修改镜像的名字 ]# docker tag docker.io/nginx nginx
第四步创建容器 fn1]# docker run -it -d --name fn1 -v /home/fn1/nginx.conf:/etc/nginx/nginx.conf -v /home/fn1/renren-vue:/home/fn1/renren-vue --privileged --net=host nginx
f81f147522814d360eaf43c29f551d07f15ba364c894900c3f797a47c3277f73
第五步 修改nginx.conf配置文件 [root@main fn1]# vi nginx.conf
[root@main home]# cd /
[root@main /]# cd /home/fn1
[root@main fn1]# ls
nginx.conf renren-vue
[root@main fn1]# cd renren-vue
[root@main renren-vue]# ls
1805070110 config index.html
[root@main renren-vue]# cd /
同理创建fn2容器
[root@main /]# docker run -it -d --name fn2 -v /home/fn2/nginx.conf:/etc/nginx/nginx.conf -v /home/fn2/renren-vue:/home/fn2/renren-vue --privileged --net=host nginx
别忘记修改nginx.conf文件,把端口号改一下6502
然后在浏览器里输入192.168.0.62:6501 /6502 ,都可以访问.网页
负载均衡的实现
[root@main home]# cd ff1
[root@main ff1]# ls
keepalived.conf nginx.conf
[root@main ff1]# vi nginx.conf
第一步修改配置文件
第二步创建ff1容器
[root@main /]# docker run -it -d --name ff1 -v /home/ff1/nginx.conf:/etc/nginx/nginx.conf --privileged --net=host nginx
同理创建ff2容器
[root@main ff2]# docker run -it -d --name ff2 -v /home/ff2/nginx.conf:/etc/nginx/nginx.conf --privileged --net=host nginx
此时当我挂掉fn1节点
[root@main /]# docker stop fn1
fn1
网站让然可以正常访问
利用keepalived实现双机热备,就是一台服务器挂掉,网站让然可以访问
第一步进入ff1容器
[root@main /]# docker exec -it ff1 bash
第二步下载 apt-get
apt-get update
第三步下载 keeplived
apt-get install keeplived
第四步下载vim 编辑器
apt-get install vim
第四步修改keeplived.conf
vi /etc/keeplived/keeplived.conf,修改为:
第五步启动keeplived服务
root@main:/# service keepalived start
[ ok ] Starting keepalived: keepalived.
第六步退出ff1容器
root@main:/# exit
exit
第六步ping 虚拟的ip地址
[root@main /]# ping 192.168.0.62
PING 192.168.0.62 (192.168.0.62) 56(84) bytes of data.
64 bytes from 192.168.0.62: icmp_seq=1 ttl=64 time=7.74 ms
64 bytes from 192.168.0.62: icmp_seq=2 ttl=64 time=0.038 ms
64 bytes from 192.168.0.62: icmp_seq=3 ttl=64 time=0.039 ms
64 bytes from 192.168.0.62: icmp_seq=4 ttl=64 time=0.051 ms
^C
访问
虚拟出来的ip和端口号,页面仍然可以访问