Lvs-nat Demo

Source: Internet
Author: User

Lvs-nat Demo:

Test environment:

os:rhel6.4

Director:

vip:192.168.10.118

dip:192.168.20.1

rs1:rip:192.168.20.11

rs2:rip:192.168.20.12

Ps:director There are two network cards, one is bridged networks eth0 (public network address), the other one using the internal network eth1; Only one NIC on both RS1 and RS2 uses an internal network eth0; To avoid other factors, the firewall and SELinux need to be turned off;


1. See if the kernel already supports the Ipvs module

on the director

/boot/config-2.6.32-358.el6.x86_64  

2. Install the Ipvsadm on the director

#mount-R/dev/cdrom/media/cdrom

#vim/etc/yum.repo.d/server.repo

[Base]

Name=server

Baseurl=file:///media/cdrom/server

Enable=1

Gpgcheck=0

#yum-y Install Ipvsadm

PS: If the system is using other versions of the Ipvsadm RPM package, you can go to www.rpmfind.net download;

3. Configure the Enable Eth1 NIC on the director (Eth0 is used before the configuration is not modified here)

#ifconfig eth1 192.168.20.1/24 up

#ifconfig # # #查看eth1是否已经启用并配置成功

4. Installing the HTTPD service on RS1 and RS2

#mount-R/dev/cdrom/media/cdrom

#vim/etc/yum.repo.d/server.repo

[Base]

Name=server

Baseurl=file:///media/cdrom/server

Enable=1

Gpgcheck=0

#yum-y Install httpd

#echo "

#echo "

5. Configuring RIP on RS1 (eth0)

#ifconfig eth0 192.168.20.11/24

#route Add default GW 192.168.20.1

#service httpd Restart

6. Configuring RIP on RS2 (eth0)

#ifconfig eth0 192.168.20.12/24

#route Add default GW 192.168.20.1

#service httpd Restart

7. Test on RS1 and RS2 to see if you can ping the gateway

#ping 192.168.20.1

8. See if you can ping with RS1 and RS2 and access Web services on the Director

#ping 192.168.20.11

#ping 192.168.20.12

#curl http://192.168.20.11

#curl http://192.168.20.12

9. Turn on the routing forwarding feature on the director

#vim/etc/sysctl.conf

Net.ipv4_forward=1

#sysctl-P

10. Configure the VIP on the director

#ifconfig eth0:0 192.168.10.118

11. Configuring the Cluster service on the director

#ipvsadm-A-T 192.168.10.118:80-s RR # # #定义一个集群服务

#ipvsadm-T 192.168.10.118:80-r 192.168.20.11-m # #向指定的集群服务里添加RS

#ipvsadm-T 192.168.10.118:80-r 192.168.20.12-m

#ipvsadm-L-N # # #查看集群配置信息

12. Visit 192.168.10.118 on the host to see if you can see the test page and how it is polled

13. Check the httpd's access log on the RS to see the real address of the CIP

14. Modify an already defined cluster so that its load scheduling algorithm is WRR

#ipvsadm-e-T 192.168.10.118:80-s WRR

#ipvsadm-e-T 192.168.10.118:80-r 192.168.20.11-m-W 3

#ipvsadm-e-T 192.168.10.118:80-r 192.168.20.12-m-W 1

15. Repeat the Access test

16. Save Ipvs rules to a file

#ipvsadm-save | Service Ipvsadm Save


17. Provide the Configure service script on Director:

#vim/etc/rc.d/init.d/lvs-nat

#!/bin/bash
#
# Chkconfig:-88 12
# Description:lvs Script for Vs/nat
#
. /etc/rc.d/init.d/functions
#Vip, Dip,rip Setting

vip=192.168.10.118
dip=192.168.20.1
rip1=192.168.20.11
rip2=192.168.20.12

#install Ipvsadm
/bin/umount/dev/cdrom
/bin/mount-r/dev/cdrom/media/cdrom

/bin/touch/etc/yum.repos.d/server.repo
Echo-e "[base]\nbaseurl=file:///medai/cdrom/server\nenable=1\ngpgcheck=0" >/etc/yum.repos.d/server.repo

/usr/bin/yum-y Remove Ipvsadm
/usr/bin/yum-y Install Ipvsadm

# Start | Stop
Case "$" in
Start

# set Dip
/sbin/ifconfig eth1 $DIP netmask 255.255.255.0 up

# set Vip
/sbin/ifconfig eth0:0 $VIP netmask 255.255.255.0 up

# Since This is the Director we must are able to forward packets
Echo 1 >/proc/sys/net/ipv4/ip_forward

# Clear all iptables rules.
/sbin/iptables-f

# Reset iptables counters.
/sbin/iptables-z

# Clear all Ipvsadm rules/services.
/sbin/ipvsadm-c

# ADD an IP virtual service for VIP 192.168.10.118 Port 80
# In this recipe, we'll use the Round-robin scheduling method.
# in production, however, you should use a weighted, dynamic scheduling method.
/sbin/ipvsadm-a-T $VIP: 80-s RR

# now direct packets for this VIP to
# The real server IP (RIP) inside the cluster
/sbin/ipvsadm-a-T $VIP: 80-r $RIP 1-m
/sbin/ipvsadm-a-T $VIP: 80-r $RIP 2-m

/bin/touch/var/lock/subsys/ipvsadm.lock
;;

Stop
# Stop Forwarding Packets
echo 0 >/proc/sys/net/ipv4/ip_forward

# Reset Ipvsadm
/sbin/ipvsadm-c

# bring down the VIP interface
Ifconfig eth0:0 Down

Rm-rf/var/lock/subsys/ipvsadm.lock
;;

Status
[-e/var/lock/subsys/ipvsadm.lock] && echo "Ipvs is running ..." | | echo "Ipvsadm is stopped ..."
;;
*)
echo "Usage: $ {start|stop}"
;;
Esac

18. Give execution permission

#chmod +x/etc/rc.d/init.d/lvs-nat

#chkconfig--add Lvs-nat

19. Start the Service

#service Lvs-nat Start



This article is from "Luo Chen's blog" blog, please be sure to keep this source http://luochen2015.blog.51cto.com/9772274/1702073

Lvs-nat Demo

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.