Keepalived, Egnix, Tomcat high availability, high concurrent application architecture build
Virtual IP address needs to be constructed in keepalived, and a nginx check file is created to detect the Nginx Server running state, and if Ngnix process is inaccessible, kill Killall keepalived process and implement V IP Drift
Ngnix managed Tocmat server address, so the LVS feature is no longer required on the Tomcat Web server to remove the bindings of LO:A devices
This structure has a total of four machines:
Server A, IP 192.168.168.101 installation keepalived, Ngnix, Configuration keepalived (MASTER), Ngnix (a,b ngnxi configuration is exactly the same), no LVS required
Server B, IP 192.168.168.102 installation keepalived, Ngnix, Configuration keepalived (BACKUP), Ngnix (a,b ngnxi configuration is exactly the same), no LVS required
Server C,ip 192.168.168.103 install tomcat, no LVS required
Server D,ip 192.168.168.104 install tomcat, no LVS required
Sample keepalived configuration:
! Configuration File for Keepalived
Global_defs {
Notification_email {
Root@localhost
}
Notification_email_from Hello@localhost
Smtp_server 127.0.0.1
Smtp_connect_timeout 30
router_id Lvs_devel
}
Vrrp_script Check_nginx {
Script "/home/check_nginx.sh"
Interval 2
Weight 2
}
Vrrp_instance Vi_1 {
State MASTER
Interface eth0
VIRTUAL_ROUTER_ID 51
Priority 199
Advert_int 1
Authentication {
Auth_type Pass
Auth_pass 1111
}
virtual_ipaddress {
192.168.239.100/24 Dev eth0 label eth0:1
}
Track_script {
Check_nginx
}
}
====
Check_nginx,sh
#!/bin/bash
#
Url= "http://192.168.239.30/"
Code= ' Curl-i-M 5-o/dev/null-s-W%{http_code} $URL '
If [$code-ne];then
Sleep 2
Code= ' Curl-i-M 5-o/dev/null-s-W%{http_code} $URL '
If [$code-ne];then
Killall keepalived
Fi
Fi
====
Sample Ngnix configuration:
 UPSTREAM YXH { server 192.168.184.188:8080 weight = 1; server 192.168.184.168:8080 weight=1; # check interval=3000 rise=2 fall=5 timeout=1000 type=http; # check_http_send "head / http/1.0\r\n\r\n"; # check_http_expect_alive http_2xx http_3xx;     &NBSP} server { listen 80; server_name www.host1.com; location / { #root html; #index index.html index.htm; #----------- #auth_basic "hi who are you ?"; #auth_basic_user_file /var/users; #index index.html index.htm; #------------------ #proxy_pass http://192.168.184.168:8080/; proxy_pass http://yuxh/; #index index.html index.htm; }