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配置文件 [[email protected] fn1]# vi nginx.conf

 

 

 

前端项目wepack打包与负载均衡

[[email protected] home]# cd /
[[email protected] /]# cd /home/fn1
[[email protected] fn1]# ls
nginx.conf  renren-vue
[[email protected] fn1]# cd renren-vue
[[email protected] renren-vue]# ls
1805070110  config  index.html
[[email protected] renren-vue]# cd /

同理创建fn2容器

[[email protected] /]# 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 ,都可以访问.网页

 

负载均衡的实现

[[email protected] home]# cd ff1
[[email protected] ff1]# ls
keepalived.conf  nginx.conf
[[email protected] ff1]# vi nginx.conf
第一步修改配置文件

第二步创建ff1容器

[[email protected] /]# docker run -it -d --name ff1 -v /home/ff1/nginx.conf:/etc/nginx/nginx.conf  --privileged --net=host nginx
同理创建ff2容器

[[email protected] ff2]# docker run -it -d --name ff2 -v /home/ff2/nginx.conf:/etc/nginx/nginx.conf  --privileged --net=host nginx
 

此时当我挂掉fn1节点

[[email protected] /]# docker stop fn1
fn1
网站让然可以正常访问

 

 

 

前端项目wepack打包与负载均衡

 

 

前端项目wepack打包与负载均衡

利用keepalived实现双机热备,就是一台服务器挂掉,网站让然可以访问

第一步进入ff1容器

[[email protected] /]# 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,修改为:

前端项目wepack打包与负载均衡

第五步启动keeplived服务


[email protected]:/# service keepalived start
[ ok ] Starting keepalived: keepalived.

第六步退出ff1容器
[email protected]:/# exit
exit

第六步ping 虚拟的ip地址
[[email protected] /]# 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和端口号,页面仍然可以访问
 

 

相关文章:

  • 2021-06-11
  • 2022-12-23
  • 2021-07-12
  • 2021-07-29
  • 2021-07-26
  • 2022-12-23
  • 2021-04-13
  • 2022-02-19
猜你喜欢
  • 2021-12-03
  • 2021-08-17
  • 2021-05-31
  • 2022-02-09
  • 2021-05-01
  • 2021-06-25
  • 2022-12-23
相关资源
相似解决方案