Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

"actual combat" open source project docker operation and maintenance deployment-back-end java deployment (7)

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

Original articles, welcome to reprint. Reprint please indicate: reproduced from IT Story Association, thank you!

Original link address: "actual combat" open source project dockerized operation and maintenance deployment-back-end java deployment (7)

This section mainly talks about the deployment of the back-end need to pay attention to the point, itself renren-fast this project is developed through springboot, springboot built-in tomcat, so we do not need to install tomcat in the container, directly use the jar file to run. Source code: https://github.com/limingios/netFuture/blob/master/ backend / backend dual hot backup

Https://gitee.com/renrenio/renren-fast

How to configure redis Cluster with spring boot

For the previously configured redis cluster, modify the order node and put all redis clusters on it.

Spring:# environment dev | test | prodprofiles:active: dev# jackson time format jackson:time-zone: GMT+8date-format: yyyy-MM-dd HH:mm:sshttp:multipart:max-file-size: 100MBmax-request-size: 100MBenabled: trueredis:open: false # whether to enable redis cache true enable false turn off database: 0#host: localhost#port: 6379#password: # password (empty by default) timeout: 6000 # connection timeout (mm) Seconds) cluster:nodes:- 172.19.0.2 cluster:nodes:- 6379-172.19.0.3 max-wait 6379-172.19.0.4 purl 6379-172.19.0.5 purl 6379-172.19.0.6 purl 6379-second: 1000 # maximum number of connections in the connection pool (unlimited with negative values) max-wait:-1 # connection pool maximum blocking wait time (make Max-idle: maximum idle connection in 10 # connection pool min-idle: minimum idle connection in 5 # connection pool maven package project

Renren-fast contains the tomcat.jar file, which is exactly the tomcat that comes with springboot's maven,pom. So packaged as a jar package, you can run files independently.

Note: the java daemon does not use the virtual network, but directly uses the host ip port. -- net=host

Run the java container to deploy the back-end project

Docker volume create jprinter looks at the path where J1 is located to make it easy for jar packages to upload docker volume inspect j1docker run-it-d name J1-v j1:/home/soft-- net=host javadocker exec-it J1 bash# to copy the compiled jar to the directory where J1 is located on the host machine. Nohubp is the background hanging project nohup java-jar / home/soft/renren-fast.jar.

Run the java container to deploy the back-end project

Docker volume create jprinter looks at the path where j2 is located to facilitate jar package upload docker volume inspect j2docker run-it-d name J2-v j2:/home/soft-- net=host javadocker exec-it j2 bash# copy the compiled jar to the directory where j2 is located on the host machine. Nohubp is the background hanging project nohup java-jar / home/soft/renren-fast.jar. Run java container deployment backend project docker volume create Jake to check the path where j3 is located. It is convenient for jar package to upload docker volume inspect j3docker run-it-d name J3-v j3:/home/soft-- net=host javadocker exec-it J3 bash# to copy the compiled jar to the directory where J3 is located on the host machine. Nohubp is the backend hanging project nohup java-jar / home/soft/renren-fast.jar to set load balance.

All the load is sent to a jar packet. If the volume is large and the tomcat can withstand up to 500 concurrency, the Tomcat may fail.

Nginx

Nginx is a reverse proxy server with excellent performance, which can support concurrent access of up to 80,000 / s. Before, we used haproxy in database middleware and redis middleware, because haproxy does a good job of load balancing such as tcp. Now tomcat in java container supports http protocol, http load does the best thing is nginx, we choose nginx load balancing products.

Configuration of nginx

Define a upstream tomcat built-in ip and port of the host machine, find the corresponding container through port mapping, configure the ports of tomcat and nginx in server, access nginx directly, and jump to the corresponding java container. Port 6101

User nginx;worker_processes 1 errorists 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.100v 6001; server 192.168.66.100v 6002; server 192.168.66.100v 6003;} server {listen 6101; server_name 192.168.66.100 Location / {proxy_pass http://tomcat; index index.html index.htm;}

Instructions for creating nginx

Nginx uses the host host ip. -- net=host

# nginx in the container starts loading the configuration file docker run-it-d-- name N1-v / root/v1/nginx.conf:/etc/nginx/nginx.conf-- net=host-- privileged nginxnginx configuration outside the container

Port 6102

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 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 * Proxy_temp_file_write_size 64kuptowstream tomcat {server 192.168.66.100 server 6001; server 192.168.66.100 server 6002; server 192.168.66.100 tomcat 6003;} server {listen 6102; server_name 192.168.66.100; location / {proxy_pass http://tomcat; index index.html index.htm;}}

}

* instructions for creating nginx > nginx uses host ip. -- net= host``` bash# container nginx boot load outside the container configuration file docker run-it-d-name N2-v / root/v2/nginx.conf:/etc/nginx/nginx.conf-- net=host-- privileged nginx backend project dual-machine hot backup load balancing solution

N1 and N2 have been set up before, and the backend can be accessed normally, but without setting keepalived, they cannot compete for ip before and cannot achieve dual-computer hot backup. This time, let's talk about the dual-computer hot standby.

Enter container N1 and install keepalived

Keepalived must be in the same container as N1, or you can download an image of nginx-keepalived in the docker repository. Here, keepalived is installed directly in the container.

Docker exec-it N1 / bin/bash# is written to dns to prevent apt-get update from finding the server echo "nameserver 8.8.8.8" | tee / etc/resolv.conf > / dev/null apt-get cleanapt-get updateapt-get install vimvi / etc/apt/sources.list

Sources.list adds the following

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

Update apt source apt-get cleanapt-get updateapt-get install keepalivedapt-get install vim

Keepalived profile

The path within the container: / etc/keepalived/keepalived.conf

Vi / etc/keepalived/keepalived.conf

Keepalived.conf

Vrrp_instance VI_1 {state MASTERinterface ens33virtual_router_id 51priority 100advert_int 1authentication {auth_type PASSauth_pass 123456} virtual_ipaddress {192.168.66.151} virtual_server 192.168.66.151 6201 {delay_loop 3lb_algo rrlb_kind NATpersistence_timeout 50protocol TCPreal_server 192.168.66.100 6101 {weight 1}} VI_1 name can be customized state MASTER | keepalived identity (MASTER master server, BACKUP backup server, will not preempt virtual machine ip). If they are all main MASTER, they will compete with each other for IP. If they get it, it will be MASTER, and the other is SLAVE. Interface network card, define a virtual IP definition to that network card. The name of the network card device. Eth43 is the host and the network card. Virtual_router_id 51 | Virtual routing identity. The virtual routing identifiers of MASTER and BACKUP must be the same. The identity can be 0-255. Priority 100 | weight. The weight importance of MASTER is higher than that of BACKUP. The larger the number is, the higher the priority level is. It can be done according to the configuration of the hardware, and the higher the level of grabbing the largest weight. Advert_int 1 | heartbeat detection. The time interval, in seconds, for synchronization checks between MASTER and BACKUP nodes. The master and backup must be consistent. Authentication | Master / slave server verification method. Master and standby must use the same password in order to communicate properly. For heartbeat detection, you need to log in to a host with an account password. Virtual_ipaddress | Virtual ip address. You can set multiple virtual ip addresses, one per line. According to the ip configured on the eth43 configured above. 192.168.66.151 is a self-defined virtual ip startup keeplived

Start in the container

Service keepalived start

Enter container N2 and install keepalived

Keepalived must be in the container where N2 is located, or you can download an image of nginx-keepalived in the docker repository. Here, keepalived is installed directly in the container.

Docker exec-it N2 / bin/bash# is written to dns to prevent apt-get update from finding the server echo "nameserver 8.8.8.8" | tee / etc/resolv.conf > / dev/null apt-get cleanapt-get updateapt-get install vimvi / etc/apt/sources.list

Sources.list adds the following

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

Update apt source apt-get cleanapt-get updateapt-get install keepalivedapt-get install vim

Keepalived profile

The path within the container: / etc/keepalived/keepalived.conf

Vi / etc/keepalived/keepalived.conf

Keepalived.conf

Vrrp_instance VI_1 {state MASTERinterface ens33virtual_router_id 51priority 100advert_int 1authentication {auth_type PASSauth_pass 123456} virtual_ipaddress {192.168.66.151} virtual_server 192.168.66.151 6201 {delay_loop 3lb_algo rrlb_kind NATpersistence_timeout 50protocol TCPreal_server 192.168.66.100 6101 {weight 1}} VI_1 name can be customized state MASTER | keepalived identity (MASTER master server, BACKUP backup server, will not preempt virtual machine ip). If they are all main MASTER, they will compete with each other for IP. If they get it, it will be MASTER, and the other is SLAVE. Interface network card, define a virtual IP definition to that network card. The name of the network card device. Eth43 is the host and the network card. Virtual_router_id 51 | Virtual routing identity. The virtual routing identifiers of MASTER and BACKUP must be the same. The identity can be 0-255. Priority 100 | weight. The weight importance of MASTER is higher than that of BACKUP. The larger the number is, the higher the priority level is. It can be done according to the configuration of the hardware, and the higher the level of grabbing the largest weight. Advert_int 1 | heartbeat detection. The time interval, in seconds, for synchronization checks between MASTER and BACKUP nodes. The master and backup must be consistent. Authentication | Master / slave server verification method. Master and standby must use the same password in order to communicate properly. For heartbeat detection, you need to log in to a host with an account password. Virtual_ipaddress | Virtual ip address. You can set multiple virtual ip addresses, one per line. According to the ip configured on the eth43 configured above. 192.168.66.151 is a self-defined virtual ip startup keeplived

Start in the container

Service keepalived start

PS: the nginx dual load and dual hot backup solution for the unknown backend has been implemented.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report