2019-04-04 08:57:07
李明
|
spring boot
spring:
# 环境 dev|test|prod
profiles: active: dev
# jackson时间格式化
jackson: time-zone: GMT+8 date-format: yyyy-MM-dd HH:mm:ss http: multipart: max-file-size: 100MB max-request-size: 100MB enabled: true redis: open: false
# 是否开启redis缓存 true开启 false关闭
database: 0
#host: localhost
#port: 6379
#password: # 密码(默认为空)
timeout: 6000
# 连接超时时长(毫秒)
cluster: nodes: - 172.19.0.2:6379 - 172.19.0.3:6379 - 172.19.0.4:6379 - 172.19.0.5:6379 - 172.19.0.6:6379 - 172.19.0.7:6379 pool: max-active: 1000
# 连接池最大连接数(使用负值表示没有限制)
max-wait: -1
# 连接池最大阻塞等待时间(使用负值表示没有限制)
max-idle: 10
# 连接池中的最大空闲连接
min-idle: 5
# 连接池中的最小空闲连接
docker volume create j1
#查看j1所在的路径,方便jar包上传
docker volume inspect j1docker run -it -d name j1 -v j1:/home/soft --net=host javadocker exec -it j1 bash
#将编译好的jar拷贝到宿主机上j1所在的目录下 nohubp 就是后台挂机项目
nohup java -jar /home/soft/renren-fast.jar
docker volume create j2
#查看j2所在的路径,方便jar包上传
docker volume inspect j2docker run -it -d name j2 -v j2:/home/soft --net=host javadocker exec -it j2 bash
#将编译好的jar拷贝到宿主机上j2所在的目录下 nohubp 就是后台挂机项目
nohup java -jar /home/soft/renren-fast.jar
docker volume create j3
#查看j3所在的路径,方便jar包上传
docker volume inspect j3docker run -it -d name j3 -v j3:/home/soft --net=host javadocker exec -it j3 bash
#将编译好的jar拷贝到宿主机上j3所在的目录下 nohubp 就是后台挂机项目
nohup java -jar /home/soft/renren-fast.jar
设置负载均衡
user nginx;worker_processes 1;error_log /var/log/nginx/error.log warn;pid /var/run/nginx.pid;events { worker_connections 1024;}http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 5s; proxy_send_timeout 5s; proxy_read_timeout 5s; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; upstream tomcat { server 192.168.66.100:6001; server 192.168.66.100:6002; server 192.168.66.100:6003; } server { listen 6101; server_name 192.168.66.100; location / { proxy_pass http://tomcat; index index.html index.htm; } }}
# 容器内的nginx启动加载容器外的配置文件
docker run -it -d --name n1 -v /root/v1/nginx.conf:/etc/nginx/nginx.conf --net=host --privileged nginx
user nginx;worker_processes 1;error_log /var/log/nginx/error.log warn;pid /var/run/nginx.pid;events { worker_connections 1024;}http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_size 128k; proxy_connect_timeout 5s; proxy_send_timeout 5s; proxy_read_timeout 5s; proxy_buffer_size 4k; proxy_buffers 4 32k; proxy_busy_buffers_size 64k; proxy_temp_file_write_size 64k; upstream tomcat { server 192.168.66.100:6001; server 192.168.66.100:6002; server 192.168.66.100:6003; } server { listen 6102; server_name 192.168.66.100; location / { proxy_pass http://tomcat; index index.html index.htm; } }}
# 容器内的nginx启动加载容器外的配置文件
docker run -it -d --name n2 -v /root/v2/nginx.conf:/etc/nginx/nginx.conf --net=host --privileged nginx
后端项目的双机热备负载均衡方案
docker exec -it n1 /bin/bash
#写入dns,防止apt-get update找不到服务器
echo "nameserver 8.8.8.8" | tee /etc/resolv.conf > /dev/null apt-get cleanapt-get updateapt-get install vimvi /etc/apt/sources.list
deb http:
//mirrors.163.com/ubuntu/ precise main universe restricted multiverse
deb-src http:
//mirrors.163.com/ubuntu/ precise main universe restricted multiverse
deb http:
//mirrors.163.com/ubuntu/ precise-security universe main multiverse restricted
deb-src http:
//mirrors.163.com/ubuntu/ precise-security universe main multiverse restricted
deb http:
//mirrors.163.com/ubuntu/ precise-updates universe main multiverse restricted
deb http:
//mirrors.163.com/ubuntu/ precise-proposed universe main multiverse restricted
deb-src http:
//mirrors.163.com/ubuntu/ precise-proposed universe main multiverse restricted
deb http:
//mirrors.163.com/ubuntu/ precise-backports universe main multiverse restricted
deb-src http:
//mirrors.163.com/ubuntu/ precise-backports universe main multiverse restricted
deb-src http:
//mirrors.163.com/ubuntu/ precise-updates universe main multiverse restricted
apt-get cleanapt-get updateapt-get install keepalivedapt-get install vim
vi /etc/keepalived/keepalived.conf
vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { 192.168.66.151 }}virtual_server 192.168.66.151 6201 { delay_loop 3 lb_algo rr lb_kind NAT persistence_timeout 50 protocol TCP real_server 192.168.66.100 6101 { weight 1 }}
service keepalived start image
docker exec -it n2 /bin/bash #写入dns,防止apt-get update找不到服务器 echo "nameserver 8.8.8.8" | tee /etc/resolv.conf > /dev/null apt-get cleanapt-get updateapt-get install vimvi /etc/apt/sources.list
deb http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse deb-src http://mirrors.163.com/ubuntu/ precise main universe restricted multiverse deb http://mirrors.163.com/ubuntu/ precise-security universe main multiverse restricted deb-src http://mirrors.163.com/ubuntu/ precise-security universe main multiverse restricted deb http://mirrors.163.com/ubuntu/ precise-updates universe main multiverse restricted deb http://mirrors.163.com/ubuntu/ precise-proposed universe main multiverse restricted deb-src http://mirrors.163.com/ubuntu/ precise-proposed universe main multiverse restricted deb http://mirrors.163.com/ubuntu/ precise-backports universe main multiverse restricted deb-src http://mirrors.163.com/ubuntu/ precise-backports universe main multiverse restricted deb-src http://mirrors.163.com/ubuntu/ precise-updates universe main multiverse restricted
apt-get cleanapt-get updateapt-get install keepalivedapt-get install vim
vi /etc/keepalived/keepalived.conf
vrrp_instance VI_1 { state MASTER interface ens33 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { 192.168.66.151 }}virtual_server 192.168.66.151 6201 { delay_loop 3 lb_algo rr lb_kind NAT persistence_timeout 50 protocol TCP real_server 192.168.66.100 6101 { weight 1 }}
service keepalived start PS:到此未知后端的nginx双负载,双热备方案已经实现了, |