创建数据卷j1 并将jar放入卷中
创建java的容器
docker run -it -d —name java1 -v j1:/home/soft —net=host java
名称叫java1的容器
j1 数据卷 映射到容器的目录/home/soft
进入容器
docker exec -it java1 bash
非后台运行:nohup java -jar /home/soft/renren-fast.jar
http://10.211.55.3:6001/renren-fast/swagger/index.html
获取nginx负载均衡
docker pull nginx
在宿主机中目录/home/n1/ 上传nginx.conf,这样方便映射到容器内的配置
启动第1个nginx节点
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,这样方便映射到容器内的配置
docker run -it -d --name n2 -v /home/n2/nginx.conf:/etc/nginx/nginx.conf --net=host --privileged nginx
双机热备方案
进入到nginx n1容器 安装keepalived
#进入n1节点
docker exec -it n1 bash
#更新软件包
apt-get update
#安装VIM
apt-get install vim
#安装Keepalived
apt-get install keepalived
#编辑Keepalived配置文件(如下)
vim /etc/keepalived/keepalived.conf
#启动Keepalived
service keepalived start
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
10.211.55.189
}
}
virtual_server 10.211.55.189 6201 {
delay_loop 3
lb_algo rr
lb_kind NAT
persistence_timeout 50
protocol TCP
real_server 10.211.55.3 6101 {
weight 1
}
}
ping 10.211.55.189
进入到nginx n2容器 安装keepalived
#进入n2节点
docker exec -it n2 bash
#更新软件包
apt-get update
#安装VIM
apt-get install vim
#安装Keepalived
apt-get install keepalived
#编辑Keepalived配置文件(如下)
vim /etc/keepalived/keepalived.conf
#启动Keepalived
service keepalived start
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
10.211.55.189
}
}
virtual_server 10.211.55.189 6201 {
delay_loop 3
lb_algo rr
lb_kind NAT
persistence_timeout 50
protocol TCP
real_server 10.211.55.3 6102 {
weight 1
}
}