image.png

创建数据卷j1 并将jar放入卷中
image.png


创建java的容器

image.png

docker run -it -d —name java1 -v j1:/home/soft —net=host java

名称叫java1的容器
j1 数据卷 映射到容器的目录/home/soft

进入容器
image.png
docker exec -it java1 bash

image.png

非后台运行:nohup java -jar /home/soft/renren-fast.jar

http://10.211.55.3:6001/renren-fast/swagger/index.html

获取nginx负载均衡

  1. docker pull nginx

在宿主机中目录/home/n1/ 上传nginx.conf,这样方便映射到容器内的配置

启动第1个nginx节点

  1. docker run -it -d --name n1 -v /home/n1/nginx.conf:/etc/nginx/nginx.conf --net=host --privileged nginx

容器运行,代表nginx也被启动了

查看nginx
http://10.211.55.3:6101/renren-fast/swagger/index.html

创建第2个Nginx节点
在宿主机中目录/home/n2/ 上传nginx.conf,这样方便映射到容器内的配置

  1. docker run -it -d --name n2 -v /home/n2/nginx.conf:/etc/nginx/nginx.conf --net=host --privileged nginx

双机热备方案

image.png

进入到nginx n1容器 安装keepalived

  1. #进入n1节点
  2. docker exec -it n1 bash
  3. #更新软件包
  4. apt-get update
  5. #安装VIM
  6. apt-get install vim
  7. #安装Keepalived
  8. apt-get install keepalived
  9. #编辑Keepalived配置文件(如下)
  10. vim /etc/keepalived/keepalived.conf
  11. #启动Keepalived
  12. service keepalived start
  1. vrrp_instance VI_1 {
  2. state MASTER
  3. interface eth0
  4. virtual_router_id 51
  5. priority 100
  6. advert_int 1
  7. authentication {
  8. auth_type PASS
  9. auth_pass 123456
  10. }
  11. virtual_ipaddress {
  12. 10.211.55.189
  13. }
  14. }
  15. virtual_server 10.211.55.189 6201 {
  16. delay_loop 3
  17. lb_algo rr
  18. lb_kind NAT
  19. persistence_timeout 50
  20. protocol TCP
  21. real_server 10.211.55.3 6101 {
  22. weight 1
  23. }
  24. }

ping 10.211.55.189

进入到nginx n2容器 安装keepalived

  1. #进入n2节点
  2. docker exec -it n2 bash
  3. #更新软件包
  4. apt-get update
  5. #安装VIM
  6. apt-get install vim
  7. #安装Keepalived
  8. apt-get install keepalived
  9. #编辑Keepalived配置文件(如下)
  10. vim /etc/keepalived/keepalived.conf
  11. #启动Keepalived
  12. service keepalived start
  1. vrrp_instance VI_1 {
  2. state MASTER
  3. interface eth0
  4. virtual_router_id 51
  5. priority 100
  6. advert_int 1
  7. authentication {
  8. auth_type PASS
  9. auth_pass 123456
  10. }
  11. virtual_ipaddress {
  12. 10.211.55.189
  13. }
  14. }
  15. virtual_server 10.211.55.189 6201 {
  16. delay_loop 3
  17. lb_algo rr
  18. lb_kind NAT
  19. persistence_timeout 50
  20. protocol TCP
  21. real_server 10.211.55.3 6102 {
  22. weight 1
  23. }
  24. }