Environment: 192.168.1.8 (DR, REALSERVER) 192.168.1.88 (REALSERVER) 192.168.1.188 (REALSERVER) 1. install and configure DR: (1) install ingress sadmyuminstallipvsadm (2) bind VIP: ifconfigeth0: Ingress
Environment: 192.168.1.8 (DR, real server) 192.168.1.88 (real server) 192.168.1.188 (real server) 1. DR installation configuration: (1) install IPVSADM yum install ipvsadm (2) bind VIP: ifconfig eth0: 0 192.168.1.200 broadcast 192.168.1.200 netmask 255.255.255 u
Environment: 192.168.1.8 (DR, real server) 192.168.1.88 (real server) 192.168.1.188 (real server)
1. DR installation Configuration:
(1) install IPVSADM
Yum install ipvsadm
(2) bind a VIP:
Ifconfig eth0: 0 192.168.1.200 broadcast 192.168.1.200 netmask 255.255.255.255 up
(3) add routes to ETH0: 0
Route add-host 192.168.1.200 dev eth0: 0
(4) Configure forwarding:
Echo "1">/proc/sys/net/ipv4/ip_forward
(5) add REAL SERVER
Ipvsadm-C
Ipvsadm-A-t 192.168.1.200: 3306-s rr-p 600
Ipvsadm-a-t 192.168.1.200: 3306-r 192.168.1.8: 3306-g
Ipvsadm-a-t 192.168.1.200: 3306-r 192.168.1.88: 3306-g
Ipvsadm-a-t 192.168.1.200: 3306-r 192.168.1.188: 3306-g
(6) start:
Ipvsadm
IP Virtual Server version 1.2.1 (size = 4096)
Prot LocalAddress: Port sched1_flags
-> RemoteAddress: Port Forward Weight ActiveConn InActConn
TCP 192.168.1.200: mysql rr persistent 600
-> 192.168.1.188: mysql Route 1 0 0
-> 192.168.1.88: mysql Route 1 0 0
-> 192.168.1.8: mysql Local 1 0 0
The above steps can be written as a script:
Cat/etc/init. d/lvsDR
# Dctor: Start LVS of Director server
VIP = 192.168.1.200
RIP1 = 192.168.1.8
RIP2 = 192.168.1.88
RIP3 = 192.168.1.188
/Etc/rc. d/init. d/functions
Case "$1" in
Start)
Echo "start LVS of Director Server"
# Set the Virtual IP Address and sysctl parameter
/Sbin/ifconfig eth0: 0 $ VIP broadcast $ VIP netmask 255.255.255.255 up
Echo "1">/proc/sys/net/ipv4/ip_forward
# Clear IPVS table
/Sbin/ipvsadm-C
# Set LVS
/Sbin/ipvsadm-A-t $ VIP: 3306-s rr-p 600
/Sbin/ipvsadm-a-t $ VIP: 3306-r $ RIP1: 3306-g
/Sbin/ipvsadm-a-t $ VIP: 3306-r $ RIP2: 3306-g
/Sbin/ipvsadm-a-t $ VIP: 3306-r $ RIP3: 3306-g
# Run LVS
/Sbin/ipvsadm
;;
Stop)
Echo "close LVS Directorserver"
Echo "0">/proc/sys/net/ipv4/ip_forward
/Sbin/ipvsadm-C
/Sbin/ifconfig eth0: 0 down
;;
*)
Echo "Usage: $0 {start | stop }"
Exit 1
Esac
Install ldirectord
Four software packages must be installed:
Heartbeat-1.2.4-1.i386.rpm heartbeat-pils-1.2.4-1.i386.rpm
Heartbeat-ldirectord-1.2.4-1.i386.rpm heartbeat-stonith-1.2.4-1.i386.rpm
Rpm-ivh *. rpm -- nodeps -- force
Modify the configuration file:
Cat/etc/ha. d/ldirectord. cf
# Global ctictives
Checktimeout = 20
Checkinterval = 10
Fallback = 127.0.0.1: 3306
Autoreload = yes
Logfile = "/var/log/ldirectord. log"
Quiescent = no
# Sample for an mysql virtual service
Virtual = 192.168.1.200: 3306
Real = 192.168.1.8: 3306 gate
Real = 192.168.1.88: 3306 gate
Real = 192.168.1.188: 3306 gate
Fallback = 127.0.0.1: 3306 gate
Service = mysql
Checktype = negotiate
Login = "root"
Passwd = "123456"
Request = "show status"
Scheduler = rr
2. real server Configuration: perform the following operations on three nodes:
Add the/etc/init. d/lvsrs script:
Cat/etc/init. d/lvsrs
#! /Bin/bash
# Description: Start Real Server
VIP = 192.168.1.200
/Etc/rc. d/init. d/functions
Case "$1" in
Start)
Echo "Start LVS of Real Server"
/Sbin/ifconfig eth0: 0 $ VIP broadcast $ VIP netmask 255.255.255.255 up
Echo "1">/proc/sys/net/ipv4/conf/eth0/arp_ignore
Echo "2">/proc/sys/net/ipv4/conf/eth0/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 eth0: 0 down
Echo "close LVS Director server"
Echo "0">/proc/sys/net/ipv4/conf/eth0: 0/arp_ignore
Echo "0">/proc/sys/net/ipv4/conf/eth0: 0/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
3. Start the LVS cluster service:
(1) Start real server: operate on all three Nodes
/Etc/init. d/lvsrs start
(2) Start ldirectord on DR
/Etc/init. d/ldirectord start
View output logs:
[Sat May 19 01:25:33 2012 | ldirectord] Removed real server: 192.168.1.8: 3306 (x 192.168.1.200: 3306
[Sat May 19 01:25:33 2012 | ldirectord] Removed real server: 192.168.1.88: 3306 (x 192.168.1.200: 3306
[Sat May 19 01:25:33 2012 | ldirectord] Removed real server: 192.168.1.188: 3306 (x 192.168.1.200: 3306
[Sat May 19 01:25:33 2012 | ldirectord] Removed virtual server: 192.168.1.200: 3306
[Sat May 19 01:25:33 2012 | ldirectord] Linux Director Daemon terminated on signal: TERM
[Sat May 19 01:25:34 2012 | ldirectord] Starting Linux Director v1.77.2.36 as daemon
[Sat May 19 01:25:34 2012 | ldirectord] Added virtual server: 192.168.1.200: 3306
[Sat May 19 01:25:34 2012 | ldirectord] Added fallback server: 127.0.0.1: 3306 (x 192.168.1.200: 3306) (Weight set to 1)
[Sat May 19 01:25:34 2012 | ldirectord] Added real server: 192.168.1.8: 3306 (x 192.168.1.200: 3306) (Weight set to 1)
[Sat May 19 01:25:34 2012 | ldirectord] Deleted fallback server: 127.0.0.1: 3306 (x 192.168.1.200: 3306)
[Sat May 19 01:25:34 2012 | ldirectord] Added real server: 192.168.1.88: 3306 (x 192.168.1.200: 3306) (Weight set to 1)
[Sat May 19 01:25:34 2012 | ldirectord] Added real server: 192.168.1.188: 3306 (x 192.168.1.200: 3306) (Weight set to 1)
The configuration is complete and the status of on-site control is as follows:
Ipvsadm on DR
Ipvsadm
IP Virtual Server version 1.2.1 (size = 4096)
Prot LocalAddress: Port sched1_flags
-> RemoteAddress: Port Forward Weight ActiveConn InActConn
TCP 192.168.1.200: mysql rr persistent 600
-> 192.168.1.188: mysql Route 1 0 0
-> 192.168.1.88: mysql Route 1 0 0
-> 192.168.1.8: mysql Local 1 0 0
The configuration is complete.