Deployment and implementation of LVS + keepalived + nginx + tomcat in CentOS

Source: Internet
Author: User

Deployment and implementation of LVS + keepalived + nginx + tomcat in CentOS

# Node Distribution

LVS-dr-master

Eth0: 192.168.146.141

LVS-dr-slave

Eth0: 192.168.146.142

Nginx1:

Eth0: 192.168.146.139

Nginx2:

Eth0: 192.168.146.140

Tomcat1:

Eth0: 192.168.146.138 4 tomcat Enabled

VIP: 192.168.146.200

# Topology:

# Specific configuration

### Lvs master

### 1. Install ipvsadm and keepalived

1yuminstall-ykeepalivedipvsadm

### 2. Use keepalived to manage lvs

Script:

Global_defs {router_idmaster_210} worker {worker # the master and slave values must be consistent with the priority151 # This value determines which server is worker {worker} virtual_ipaddress {192.168.146.200} virtual_server192.168.146.20080 {worker # worker {worker {token} real_server192.168.146.14080 {weight1TCP_CHECK {connect_timeout3nb_get_retry3delay_before_retry3connect_port80 }}}

### Lvs slave

### 1. Install ipvsadm and keepalived

Yuminstall-ykeepalivedipvsadm

### 2. Use keepalived to manage lvs

Global_defs {router_idslave_211} vrrp_instanceaiyou {users # the master and slave values must be consistent with the priority150 # This value determines which server is the master. Here we have a lower value than the master, so the role is backup, advert_int1authentication {authentication} virtual_ipaddress {192.168.146.200} virtual_server192.168.146.20080 {region # authentication {weight1TCP_CHECK {region} real_server192.168.146.14080 {weight1TCP_CHECK {region }}}

### Nginx1

### Run a script on nginx

#! /Bin/bash # ScripttostartLVSDRrealserver. # description: LVSDRrealserver #. /etc/rc. d/init. d/functionsVIP = 192.168.146.200 # change your VIP address host = '/bin/hostname' case "$1" instart) # StartLVS-DRrealserveronthismachine as needed. /sbin/ifconfiglodown/sbin/ifconfigloupecho1>/proc/sys/net/ipv4/conf/lo/arp_ignoreecho2>/proc/sys/net/ipv4/conf/lo/arp_announceecho1>/ proc/sys/net/ipv4/conf/all/arp_ignoreecho2>/proc/sys/net/ipv4/co Nf/all/arp_announce/sbin/ifconfiglo: 0 $ VIPbroadcast $ vipnetmask?%255up/sbin/routeadd-host $ VIPdevlo: 0; stop) # StopLVS-DRrealserverloopbackdevice (s ). /sbin/ifconfiglo: 0downecho0>/proc/sys/net/ipv4/conf/lo/arp_ignoreecho0>/proc/sys/net/ipv4/conf/lo/arp_announceecho0>/proc/sys/net/ipv4 /conf/all/arp_ignoreecho0>/proc/sys/net/ipv4/conf/all/arp_announce ;; status) # StatusofLVS-DRrealserver.islothere =' /Sbin/ifconfiglo: 0 | grep $ VIP 'isrothere = 'netstat-rn | grep "lo: 0" | grep $ VIP' if [! "$ Islothere"-o! "Isrothere"]; then # Eithertherouteorthelo: 0 device # notfound. echo "LVS-DRrealserverStopped. "elseecho" LVS-DRrealserverRunning. "fi; *) # Invalidentry. echo "$0: Usage: $0 {start | status | stop}" exit1; esac

### Nginx2

### Run a script on nginx

#! /Bin/bash # ScripttostartLVSDRrealserver. # description: LVSDRrealserver #. /etc/rc. d/init. d/functionsVIP = 192.168.146.200 # change your VIP address host = '/bin/hostname' case "$1" instart) # StartLVS-DRrealserveronthismachine as needed. /sbin/ifconfiglodown/sbin/ifconfigloupecho1>/proc/sys/net/ipv4/conf/lo/arp_ignoreecho2>/proc/sys/net/ipv4/conf/lo/arp_announceecho1>/ proc/sys/net/ipv4/conf/all/arp_ignoreecho2>/proc/sys/net/ipv4/co Nf/all/arp_announce/sbin/ifconfiglo: 0 $ VIPbroadcast $ vipnetmask?%255up/sbin/routeadd-host $ VIPdevlo: 0; stop) # StopLVS-DRrealserverloopbackdevice (s ). /sbin/ifconfiglo: 0downecho0>/proc/sys/net/ipv4/conf/lo/arp_ignoreecho0>/proc/sys/net/ipv4/conf/lo/arp_announceecho0>/proc/sys/net/ipv4 /conf/all/arp_ignoreecho0>/proc/sys/net/ipv4/conf/all/arp_announce ;; status) # StatusofLVS-DRrealserver.islothere =' /Sbin/ifconfiglo: 0 | grep $ VIP 'isrothere = 'netstat-rn | grep "lo: 0" | grep $ VIP' if [! "$ Islothere"-o! "Isrothere"]; then # Eithertherouteorthelo: 0 device # notfound. echo "LVS-DRrealserverStopped. "elseecho" LVS-DRrealserverRunning. "fi; *) # Invalidentry. echo "$0: Usage: $0 {start | status | stop}" exit1; esac

### Backend tomcat installation omitted

Multi-instance mode (non-Multi-VM)

### Test

### Master Verification

[Root @ lvs1 ~] # Ipvsadm-lnIPVirtualServerversion1.2.1 (size = 4096) ProtLocalAddress: PortSchedulerFlags-> RemoteAddress: temperature: 80wrr-> 192.168.146.139: 80Route100-> 192.168.146.140: 80Route100 [root @ lvs1 ~] #

### Server Load balancer Verification

[Root @ lvs2 ~] # Ipvsadm-lnIPVirtualServerversion1.2.1 (size = 4096) ProtLocalAddress: PortSchedulerFlags-> RemoteAddress: temperature: 80wrr-> 192.168.146.139: 80Route100-> 192.168.146.140: 80Route100 [root @ lvs2 ~] #

References:

Http://www.5ilinux.com/2014/05/lvs_keepalived_nginx_tomcat.html

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.