One, as the figure
Second, install Tomcat (JDK installation reference http://blog.csdn.net/u011254180/article/details/77893457)
Installation of the TAR format (take apache-tomcat-7.0.52.tar.gz as an example)
1 upload tomcat to Linux
2 Extract Tomcat to/usr/local
TAR-ZXVF apache-tomcat-7.0.52.tar.gz-c/usr/local/tomcat
3 Open Linux external access to port 8080
/sbin/iptables-i input-p TCP--dport 8080-j ACCEPT
/etc/rc.d/init.d/iptables Save
4) Start off Tomcat
Enter Tomcat's bin to start:./startup.sh
Go under Tomcat's bin to close:./shutdown.sh
Iii. installation of Nginx (reference http://blog.csdn.net/u011254180/article/details/77897663)
The configuration file is the same as before
User nobody nobody; #Define the users and user groups Nginx runs Worker_processes 4; #nginx number of processes, the recommended setting is equal to the total number of CPU cores. Error_log logs / error.log Info #Global error log definition type, [Debug | info | notice | warn | error | crit] Worker_rlimit_nofile 1024; #The maximum number of file descriptors opened by an nginx process, it is recommended to be consistent with ulimit-n values. PID Logs / nginx.pid; #Process file #Working mode and maximum number of connections Events { Use Epoll #Reference event model, use [kqueue | rtsig | epoll | / dev / poll | select | poll]; Epoll model is a high performance network I / O model in Linux 2.6 version kernel Worker_connections 1024 #maximum number of connections = number of connections * processes } #Setting the http server, using its reverse proxy function to provide load balancing support HTTP { Include Mime.types; #File extension and file type mapping table Default_type Application / octet-stream; #Default file type #Set load balanced server list Upstream tomcatxxxcom { Server 192.168.56.200:8080; Server 192.168.56.201:8080; } #Set log format Log_format www_xy_com '$ remote _addr- $ remote _user [$ time _local] "$ request" '$ status $ body _bytes_sent' $ http _referer ' '$ http _user_agent', '$ http _x_forwarded_for'; Sendfile on #Enable efficient file transfer mode, the sendfile directive specifies whether Nginx invokes the Sendfile function to output the file, set to on for the normal application, and, if used for download applications disk IO Heavy load application, to balance disk and network i / o processing speed, reduce the system load. Note: If the picture appears to be abnormal, change this to off. Keepalive_timeout 65; #Long connection timeout, Unit is seconds #gzip on; #Configure the virtual host, the default is listening on port 80. server { Listen 80; server_name tomcat.xxx.com; #There can be multiple domain names, separated by spaces #charset Koi8-r; #Set the access log of this virtual host Access_log / data / logs / access.log www_xy_com; #Pair "/" Enable reverse Proxy Location / { Proxy_pass http: // tomcatxxxcom; Proxy_set_header Host $ host; Proxy_set_header X-real-ip $ remote _addr; Proxy_set_header x-forwarded-for $ proxy _add_x_forwarded_for; } #error_page 502 503 504 / 50x.html; Location = / 50x.html { root HTML; } } } |
Iv. installation of LVS (reference http://blog.csdn.net/u011254180/article/details/77898489)
Lvs-dr.sh: Compared to the previous, the change is VIP and forwarding port.
#!/bin/bash #description: Start LVS server echo "1" >/proc/sys/net/ipv4/ip_forwar D web1=192.168.56.200 web2=192.168.56.201 vip1=192.168.56.90 /etc/ Rc.d/init.d/functions Case "$" in Start) echo "Start LVS of Directorserver" #set the Virtual Address and sysctl parameter /sbin/ifconfig eth1:0 $VIP 1 broadcast $VIP 1 netmask 255.255.255.255 up #clear Ipvs tabl E /sbin/ipvsadm-c #set LVS #web Apache or tomcat /sbin/ipvsadm-a-t $VIP 1:80-s RR /sbin/ Ipvsadm-a-T $VIP 1:80-r $WEB 1:80 -g /sbin/ipvsadm-a-t $VIP 1:80-r $WEB 2:80 -g #run LVS /sbin/ipvsadm ;; Stop) echo "Close LVS directorserver" echo "0" >/proc/sys/net/ipv4/ip_forward /sbin/ipvsadm -C /sbin/ipvsadm-z ;;; *) echo "usage:$0 {start|stop}" Exit 1 Esac |
Lvs-rs.sh: The difference with the previous is that the VIP has been modified
#!/bin/sh #description Start Realserver #chkconfig 235 26 26 vip1=192.168.56.90 /etc/rc.d/init.d/functions Case "$" in Start echo "Start LVS of Realserver" /sbin/ifconfig lo:0 $VIP 1 broadcast $VIP 1 netmask 255.255.255.255 up echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce ;; Stop /sbin/ifconfig lo:0 Down echo "Close LVs dirctorserver" echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce ;; *) echo "Usage:$0{start|stop}" Exit 1 Esac |
V. Installation of keepalived (reference http://blog.csdn.net/u011254180/article/details/77898489)
Note: When using keepalived to do Tomcat and Nginx hot standby, you need to add the Realserver configuration. But the hot spare for LVS does not need to configure Realserver, because keepalived has the configuration parameters of LVs.
Backup
! Configuration File for Keepalived Global_defs { Notification_email { #acassen @firewall. Loc #failover @firewall. Loc #sysadmin @firewall. Loc } Notification_email_from Alexandre.Cassen@firewall.loc #smtp_server 192.168.200.1 #smtp_connect_timeout 30 router_id Lvs_devel } Vrrp_instance Vi_1 { State BACKUP Interface eth1 Lvs_sync_daemon_inteface eth1 VIRTUAL_ROUTER_ID 51 Priority 100 Nopreempt Advert_int 1 Authentication { Auth_type Pass Auth_pass 1111 } virtual_ipaddress { 192.168.56.90 } } Virtual_server 192.168.56.90 80 { Delay_loop 6 Lb_algo RR Lb_kind DR #nat_mask 255.255.255.0 Persistence_timeout 1 Protocol TCP } |
Master
! Configuration File for Keepalived Global_defs { Notification_email { #acassen @firewall. Loc #failover @firewall. Loc #sysadmin @firewall. Loc } Notification_email_from Alexandre.Cassen@firewall.loc #smtp_server 192.168.200.1 #smtp_connect_timeout 30 router_id Lvs_devel } Vrrp_instance Vi_1 { State MASTER Interface eth1 Lvs_sync_daemon_inteface eth1 VIRTUAL_ROUTER_ID 51 Priority 200 Advert_int 1 Authentication { Auth_type Pass Auth_pass 1111 } virtual_ipaddress { 192.168.56.90 } } Virtual_server 192.168.56.90 80 { Delay_loop 6 Lb_algo RR Lb_kind DR #nat_mask 255.255.255.0 Persistence_timeout 1 Protocol TCP } |
Monitoring scripts:
wangsf.sh Script File contents
#!/bin/bash While true; Todo A= ' Ipvsadm-ln | Wc-l ' b= ' Ps-ef|grep keepalived |wc-l ' If [$A-eq 3];then echo ' Restart LVS!!!! ' /usr/local/lvs/lvs-dr.sh start If [$A-eq 3];then If [$B-gt 1];then echo ' LVS dead!!!! Kill Keepalived ' Killall keepalived Break Fi Fi Fi If [$A-eq 6];then If [$B-eq 1];then echo ' TOMCAT live!!!! Start keepalived ' Service keepalived Start Fi Fi Sleep 3 Done |