Three physical machine configuration Nginx+keepalived+lvs in CENTOS6

Source: Internet
Author: User

The following is a simple installation configuration, and does not test this load, various parameters

vip:10.0.50.170

LVS server:10.0.50.183

Real server:10.0.50.184/185

183/184/185 sync time, and install Nginx

# ntpdate Time.nist.gov

# yum Install Nginx

#/etc/init.d/nginx Start

Write the test page on 184/185/usr/share/nginx/html/index.html


183 Installing the ipvsadm* and keepalived

# yum Install keepalived ipvsadm*

# vim/etc/sysctl.conf

Net.ipv4.ip_forward = 1

# sysctl-p

# vi/etc/keepalived/keepalived.conf

! Configuration File for Keepalived


Global_defs {

Notification_email {

[Email protected]

[Email protected]

[Email protected]

}

Notification_email_from [email protected]

Smtp_server 127.0.0.1

Smtp_connect_timeout 30

router_id Lvs_devel

}


Vrrp_instance Vi_1 {

State MASTER

Interface Em1

VIRTUAL_ROUTER_ID 51

Priority 100

Advert_int 1

Authentication {

Auth_type PASS

Auth_pass 1111

}

virtual_ipaddress {

10.0.50.170

}

}


Virtual_server 10.0.50.170 80 {

Delay_loop 6

Lb_algo RR

Lb_kind DR

Nat_mask 255.255.255.0

Persistence_timeout 50

Protocol TCP


Real_server 10.0.50.184 80 {

Weight 1

Tcp_check {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

}

}


Real_server 10.0.50.185 80 {

Weight 1

Tcp_check {

Connect_timeout 3

Nb_get_retry 3

Delay_before_retry 3

}

}


}

#/etc/init.d/keepalived Start

# Chkconfig keepalived on



# cd/etc/init.d/

# VI LVs

#!/bin/sh

# Description:start LVS of Director server

web_vip=10.0.50.170

web_rip1=10.0.50.184

web_rip2=10.0.50.185


Set_vip () {

/sbin/ifconfig em1:0 $WEB _vip netmask 255.255.255.0 broadcast $WEB _VIP up

/sbin/route add-host $WEB _vip Dev em1:0

/sbin/ipvsadm-a-T $WEB _vip:80-s wrr-p 3

/sbin/ipvsadm-a-T $WEB _vip:80-r $WEB _rip1:80-g-W 1

/sbin/ipvsadm-a-T $WEB _vip:80-r $WEB _rip2:80-g-W 1

}


Case "$" in

Start

/sbin/ipvsadm-c

Set_vip

Touch/var/lock/ipvsadm >/dev/null 2>&1

echo "Ipvsadm start"

;;

Stop

/sbin/ipvsadm-c

/sbin/ipvsadm-z

/sbin/ifconfig em1:0 Down

Route del $WEB _vip >/dev/null 2>&1

Rm-fr/var/lock/ipvsadm >/dev/null 2>&1

echo "Ipvsadm stoped"

;;

Status

if [!-e/var/lock/ipvsadm];then

echo "Ipvsadm is stoped"

Exit 1

Else

/sbin/ipvsadm-ln

echo "Ipvsadm is OK"

Fi

;;

Restart

/sbin/ipvsadm-c

/sbin/ipvsadm-z

/sbin/ifconfig em1:0 Down

Route del $WEB _vip >/dev/null 2>&1

Rm-fr/var/lock/ipvsadm >/dev/null 2>&1

Set_vip

Touch/var/lock/ipvsadm >/dev/null 2>&1

echo "Ipvsadm restart ..."

;;

*)

echo "Usage: $ {Start|stop|status}"

Exit 1

Esac

Exit 0

#/etc/init.d/lvs Start



184/185 machines are executing LVSRS scripts

# VI Lvsrs

#!/bin/bash

#!/bin/bash

#description: Start Real Server

vip=10.0.50.170

./etc/rc.d/init.d/functions

Case "$" in


Start


echo "Start LVS of Real Server"


/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up


/sbin/route add-host $VIP Dev lo:0

#注释: The purpose of these four sentences is to turn off the ARP broadcast response so that the VIP cannot send broadcasts to the network to prevent confusion in the network

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 Director Server"


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: $ {start|stop}"


Exit 1


Esac

#/etc/init.d/lvsrs Start

Reference http://blog.sina.com.cn/s/blog_6e834de50100pnfr.html



1. My colleague once asked about the realization of two physical machines:

For example, install and start the Nginx\keepalived\lvs script \lvsrs script at the same time above 183/184

2. For the following two differences:

/sbin/ipvsadm-a-T $WEB _vip:80-s wrr-p 3

or/sbin/ipvsadm-a-T $WEB _vip:80-s RR

This article is from "The Endless Bitter Boat" blog, please be sure to keep this source http://guowang327.blog.51cto.com/6513732/1669875

Three physical machine configuration Nginx+keepalived+lvs in CENTOS6

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.