Chinaunix首页 | 论坛 | 博客
  • 博客访问: 166651
  • 博文数量: 20
  • 博客积分: 1610
  • 博客等级: 上尉
  • 技术积分: 230
  • 用 户 组: 普通用户
  • 注册时间: 2007-03-16 15:40
文章分类

全部博文(20)

文章存档

2013年(1)

2012年(2)

2011年(8)

2010年(1)

2009年(2)

2008年(2)

2007年(4)

分类: LINUX

2009-06-10 22:02:23

 
 
 
 
这两个 heartbeat,lvs 软件在 google里面随便一搜,都有大把的实例出来供你参考,我在做的时候也没少搜。
能使用的范围非常的广,做的应用也是五花八门。
 
目的:实现一个heartbeart + LVS + ldirector +MySQL Slave 结构的只读数据库。
 
一、下载:
    到上面两个网址里面去找吧 。
 
二、安装:
看看我的内核和OS:

[root@XXlvs01 resource.d]# cat /etc/redhat-release
CentOS release 5.2 (Final)
[root@XXlvs01 resource.d]# uname  -a
Linux XXlvs01 2.6.18-92.el5 #1 SMP Tue Jun 10 18:51:06 EDT 2008 x86_64 x86_64 x86_64 GNU/Linux
[root@XXlvs01 resource.d]#
 
网络要求:
  LVS服务器服务器和MySQL客户端服务器要在一个网段内,并且默认的网关要一样。
 
具体安装:

三、需要的软件包。
软件包是看机器情况的,我在安装的时候,依据安装过程中提示的依赖关系,
需要以下安装文件。
-rw-r--r-- 1 root root 6803652 Mar 19 14:49 heartbeat-2.1.4-2.1.x86_64.rpm
-rw-r--r-- 1 root root  167285 Mar 19 14:49 heartbeat-devel-2.1.4-2.1.x86_64.rpm
-rw-r--r-- 1 root root  108131 Mar 19 15:30 heartbeat-ldirectord-2.1.4-2.1.x86_64.rpm
-rw-r--r-- 1 root root  192674 Mar 19 14:49 heartbeat-pils-2.1.4-2.1.x86_64.rpm
-rw-r--r-- 1 root root 1244812 Mar 19 14:49 heartbeat-stonith-2.1.4-2.1.x86_64.rpm
-rw-r--r-- 1 root root   31699 Mar 11 12:48 ipvsadm-1.24-6.x86_64.rpm
-rw-r--r-- 1 root root  240114 Mar 19 14:24 libnet-1.1.2.1-2.1.x86_64.rpm
-rw-r--r-- 1 root root   38257 Mar 19 14:02 libtool-ltdl-1.5.22-6.1.x86_64.rpm
-rw-r--r-- 1 root root  843950 Mar 19 13:40 openssl097a-0.9.7a-9.el5_2.1.x86_64.rpm
-rw-r--r-- 1 root root   53033 Mar 19 15:46 perl-Compress-Zlib-1.42-1.fc6.x86_64.rpm
-rw-r--r-- 1 root root   93770 Mar 19 15:51 perl-HTML-Parser-3.55-1.fc6.x86_64.rpm
-rw-r--r-- 1 root root   14955 Mar 19 15:54 perl-HTML-Tagset-3.10-2.1.1.noarch.rpm
-rw-r--r-- 1 root root  385100 Mar 19 15:38 perl-libwww-perl-5.805-1.1.1.noarch.rpm
-rw-r--r-- 1 root root   91386 Mar 11 12:53 perl-MailTools-1.77-1.el4.centos.noarch.rpm
-rw-r--r-- 1 root root  201453 Mar 11 12:53 perl-Net-SSLeay-1.30-4.el4.centos.x86_64.rpm
-rw-r--r-- 1 root root   33364 Mar 11 12:53 perl-TimeDate-1.16-5.el4.noarch.rpm
四、安装步骤
   以上 rpm -ivh *.rpm
[root@XXlvs02 lvs]# rpm -ivh *.rpm
warning: heartbeat-2.1.4-2.1.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 1d362aeb
warning: ipvsadm-1.24-6.x86_64.rpm: Header V3 DSA signature: NOKEY, key ID 443e1821
Preparing...                ########################################### [100%]
   1:heartbeat-pils         ########################################### [  6%]
   2:heartbeat-stonith      ########################################### [ 13%]
   3:perl-Compress-Zlib     ########################################### [ 19%]
   4:openssl097a            ########################################### [ 25%]
   5:perl-Net-SSLeay        ########################################### [ 31%]
   6:ipvsadm                ########################################### [ 38%]
   7:libtool-ltdl           ########################################### [ 44%]
   8:perl-TimeDate          ########################################### [ 50%]
   9:heartbeat              ########################################### [ 56%]
  10:perl-MailTools         ########################################### [ 63%]
  11:perl-HTML-Tagset       ########################################### [ 69%]
  12:perl-HTML-Parser       ########################################### [ 75%]
  13:perl-libwww-perl       ########################################### [ 81%]
  14:heartbeat-devel        ########################################### [ 88%]
  15:heartbeat-ldirectord   ########################################### [ 94%]
  16:libnet                 ########################################### [100%]
[root@XXlvs02 lvs]# 
    
 
 
--------------以下配置以 XXmdl17,18,19,20 (207,208,209,210)为例----------------
五、heartbeat_lvs 服务器配置文件清单...
 1,/etc/ha.d/ha.cf 文件的配置;
        lvs02.............
 [root@XXlvs02 ~]# cat /etc/ha.d/ha.cf
 debugfile /var/log/ha-debug
 logfile /var/log/ha-log
 logfacility     local0
 keepalive 1000ms
 deadtime 30
 warntime 5
 initdead 120
 udpport 694
 #ucast eth5 172.16.3.2
 ucast bond0 100.XXX.3.87
 auto_failback off
 watchdog /dev/watchdog
 node    XXlvs01
 node    XXlvs02
 ping 100.XXX.3.254
 respawn hacluster /usr/lib64/heartbeat/ipfail
 apiauth ipfail gid=haclient uid=hacluster
 [root@XXlvs02 ~]#
        lvs01.............
 ==========================================
 [root@XXlvs01 ~]# cat /etc/ha.d/ha.cf
 debugfile /var/log/ha-debug
 logfile /var/log/ha-log
 logfacility     local0
 keepalive 1000ms
 deadtime 30
 warntime 5
 initdead 120
 udpport 694
 #ucast eth5 172.16.3.2
 ucast bond0 100.XXX.3.88
 auto_failback off
 watchdog /dev/watchdog
 node    XXlvs01
 node    XXlvs02
 ping 100.XXX.3.254
 respawn hacluster /usr/lib64/heartbeat/ipfail
 apiauth ipfail gid=haclient uid=hacluster
 [root@XXlvs01 ~]#
 2,/etc/ha.d/
  安装完毕后的目录清单。
 注意 有 ldirectord -> /usr/sbin/ldirectord 文件。
 [root@XXlvs01 ~]# ll /etc/ha.d/
 total 44
 -rw------- 1 root root  748 Mar 19 18:30 authkeys
 -rw-r--r-- 1 root root  362 Mar 19 17:41 ha.cf
 -rwxr-xr-x 1 root root  745 Aug 20  2008 harc
 -rw-r--r-- 1 root root 6529 Mar 19 18:17 haresources
 -rw-r--r-- 1 root root  396 Mar 23 20:06 ldirectord.cf
 drwxr-xr-x 2 root root 4096 Mar 19 14:52 rc.d
 -rw-r--r-- 1 root root  692 Aug 20  2008 README.config
 drwxr-xr-x 2 root root 4096 Mar 24 16:04 resource.d
 -rw-r--r-- 1 root root 7843 Aug 20  2008 shellfuncs
 [root@XXlvs01 ~]# ll /etc/ha.d/resource.d/
 total 104
 -rwxr-xr-x 1 root root  828 Aug 20  2008 apache
 -rwxr-xr-x 1 root root  805 Aug 20  2008 AudibleAlarm
 -rwxr-xr-x 1 root root  760 Aug 20  2008 db2
 -rwxr-xr-x 1 root root  910 Aug 20  2008 Delay
 -rwxr-xr-x 1 root root 1903 Aug 20  2008 Filesystem
 -rwxr-xr-x 1 root root 2325 Aug 20  2008 hto-mapfuncs
 -rwxr-xr-x 1 root root  951 Aug 20  2008 ICP
 -rwxr-xr-x 1 root root 3424 Aug 20  2008 ids
 -rwxr-xr-x 1 root root 2273 Aug 20  2008 IPaddr
 -rwxr-xr-x 1 root root 1825 Aug 20  2008 IPaddr2
 -rwxr-xr-x 1 root root 1391 Aug 20  2008 IPsrcaddr
 -rwxr-xr-x 1 root root  622 Aug 20  2008 IPv6addr
 lrwxrwxrwx 1 root root   20 Mar 19 15:56 ldirectord -> /usr/sbin/ldirectord
 -rwxr-xr-x 1 root root 1091 Aug 20  2008 LinuxSCSI
 -rwxr-xr-x 1 root root  790 Aug 20  2008 LVM
 -rwxr-xr-x 1 root root 4137 Aug 20  2008 LVSSyncDaemonSwap
 -rwxr-xr-x 1 root root 1125 Aug 20  2008 MailTo
 -rwxr-xr-x 1 root root 2923 Aug 20  2008 OCF
 -rwxr-xr-x 1 root root  739 Aug 20  2008 portblock
 -rwxr-xr-x 1 root root 1160 Aug 20  2008 Raid1
 -rwxr-xr-x 1 root root 1070 Mar 23 18:51 realserver
 -rwxr-xr-x 1 root root 1563 Aug 20  2008 SendArp
 -rwxr-xr-x 1 root root 1012 Aug 20  2008 ServeRAID
 -rwxr-xr-x 1 root root 1294 Aug 20  2008 WAS
 -rwxr-xr-x 1 root root 1166 Aug 20  2008 WinPopup
 -rwxr-xr-x 1 root root  666 Aug 20  2008 Xinetd
 3,/etc/ha.d/ldirectord.cf
 [root@XXlvs01 ~]# cat /etc/ha.d/ldirectord.cf
 #Global Directives
 checktimeout=5
 checkinterval=10
 #fallback=127.0.0.1:80
 autoreload=yes
 logfile="/var/log/ldirectord.log"
 #emailalert=""
 #emailalertfreq=3600
 #emailalertstatus=all
 quiescent=no
 virtual=100.XXX.3.81:3306
         real=100.XXX.3.208:3306 gate
         real=100.XXX.3.209:3306 gate
         real=100.XXX.3.210:3306 gate
         service=mysql
         scheduler=rr
         protocol=tcp
         checkport=3306
         checktype=connect
         #End of File ..
         请注意上面 virtual 文件下面的行前面要且只能要一个tab 空格。
 
 4,/etc/ha.d/haresources
 XXlvs01============================
 [root@XXlvs01 ha.d]# cat /etc/ha.d/haresources  |grep -Ev "^$|#"
 XXlvs01 IPaddr::100.XXX.3.81/24/bond0 realserver ldirectord::ldirectord.cf
 [root@XXlvs01 ha.d]#
   XXlvs02============================
      [root@XXlvs02 ~]#  cat /etc/ha.d/haresources  |grep -Ev "^$|#"
 XXlvs01 IPaddr::100.XXX.3.81/24/bond0 realserver ldirectord::ldirectord.cf
 5,/etc/ha.d/resource.d/realserver
    此文件是在 heartbeat 启动或者切换过来的时候执行 start,用来
    将设定的内容写入到 ipvsadmin 的列表中。
    在 切换过去的时候 由heartbeat 自动执行 stop 。
   
 [root@XXlvs02 ~]# ll /etc/ha.d/resource.d/realserver
 -rwxr-xr-x 1 root root 1070 Mar 23 18:52 /etc/ha.d/resource.d/realserver
 [root@XXlvs02 ~]#
        [root@XXlvs02 ~]# cat /etc/ha.d/resource.d/realserver
 #!/bin/sh
 #Description start lvs,disable arp response
 VIP=100.XXX.3.81
 RIP1=100.XXX.3.208
 RIP2=100.XXX.3.209
 RIP3=100.XXX.3.210
 GW=100.XXX.3.254

 case "$1" in
 start)
     echo "lvs start"
     # set the Virtual IP Address
     echo "1" >/proc/sys/net/ipv4/ip_forward
     #Clear IPVS table
     /sbin/ipvsadm -C
     #set LVS
     /sbin/ipvsadm -A -t $VIP:3306 -s rr
     /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
     /bin/touch /var/lock/subsys/lvs
     # set Arp
 #    /sbin/arping -I eth0 -c 5 -s $VIP $GW >/dev/null 2>&1
     ;;
 stop)
     /sbin/ipvsadm -C
     /sbin/ipvsadm -Z
     /bin/rm -rf /var/lock/subsys/lvs
 #    /sbin/arping -I eth0 -c 5 -s $VIP $GW
     echo  "ipvsadm STOPPED"
     ;;
 status)
     if [ ! -e /var/lock/subsys/lvs ];then
         echo "ipvsadm is STOPPED"
         exit 1
     else
         /sbin/ipvsadm -ln
         echo "..........ipvsadm is OK"
     fi
     ;;
 *)
     echo "Usage: $0{start|stop|status}"
     exit 1
 esac
 exit 0
 [root@XXlvs02 ~]#
   
六、客户端需要设置的内容。
 [root@XXmdl19 bin]# more ipvs_client_for_mysql.sh
 ifconfig dummy0 up 
 ifconfig dummy0 100.XXX.3.81 netmask 255.255.255.0 broadcast 100.XXX.3.81 up
 echo 1 > /proc/sys/net/ipv4/ip_forward
 echo "1" >/proc/sys/net/ipv4/conf/dummy0/arp_ignore
 echo "2" >/proc/sys/net/ipv4/conf/dummy0/arp_announce
 echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
 echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
 sysctl -p
 [root@XXmdl19 bin]# ifconfig
 dummy0    Link encap:Ethernet  HWaddr F6:82:C7:63:30:96 
           inet addr:100.XXX.3.81  Bcast:100.XXX.3.81  Mask:255.255.255.0
           UP BROADCAST RUNNING NOARP  MTU:1500  Metric:1
           RX packets:0 errors:0 dropped:0 overruns:0 frame:0
           TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
           collisions:0 txqueuelen:0
           RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)

七、验证步骤
  1,确认heartbeat 主从
     [root@XXlvs01 ha.d]# ifconfig  |grep inet
          inet addr:100.XXX.3.87  Bcast:100.XXX.3.255  Mask:255.255.255.0
          inet addr:100.XXX.3.81  Bcast:100.XXX.3.255  Mask:255.255.255.0
          inet addr:100.XXX.8.87  Bcast:100.XXX.8.255  Mask:255.255.255.0
          inet addr:127.0.0.1  Mask:255.0.0.0
      可以确认到 100.XXX.3.81 VIP已经存在。
      从别的服务器也能ping通。
  2,确认 LVS中设定的列表:
   [root@XXlvs01 ha.d]# ipvsadm -L
 IP Virtual Server version 1.2.1 (size=4096)
 Prot LocalAddress:Port Scheduler Flags
   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
 TCP  100.XXX.3.81:mysql rr
   -> XXmdl20:mysql                Route   1      0          0        
   -> XXmdl18:mysql                Route   1      0          0        
 [root@XXlvs01 ha.d]#
  3,在MySQL客户端确认ldirector 定期来确认MySQL的连接情况:
 [root@XXmdl19 var]# tcpdump  host 100.XXX.3.87
 tcpdump: WARNING: eth0: no IPv4 address assigned
 tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
 listening on eth0, link-type EN10MB (Ethernet), capture size 96 bytes
 11:37:39.427884 IP XXmdl19.mysql > XXlvs01.34356: S 3961650748:3961650748(0) ack 2091235633 win 5792
 11:37:39.428437 IP XXmdl19.mysql > XXlvs01.34356: P 1:106(105) ack 2 win 46
 11:37:39.428468 IP XXmdl19.mysql > XXlvs01.34356: F 106:106(0) ack 2 win 46
  11:37:49.428994 IP XXmdl19.mysql > XXlvs01.34359: S 3986364821:3986364821(0) ack 2105720293 win 5792
 11:37:49.429205 IP XXmdl19.mysql > XXlvs01.34359: P 1:106(105) ack 2 win 46
 11:37:49.429236 IP XXmdl19.mysql > XXlvs01.34359: F 106:106(0) ack 2 win 46
 11:37:59.430272 IP XXmdl19.mysql > XXlvs01.34362: S 3987864478:3987864478(0) ack 2110335516 win 5792
 11:37:59.430462 IP XXmdl19.mysql > XXlvs01.34362: P 1:106(105) ack 2 win 46
 11:37:59.430489 IP XXmdl19.mysql > XXlvs01.34362: F 106:106(0) ack 2 win 46
  11:38:09.432210 IP XXmdl19.mysql > XXlvs01.34365: S 4007363487:4007363487(0) ack 2123944523 win 5792
 11:38:09.432427 IP XXmdl19.mysql > XXlvs01.34365: P 1:106(105) ack 2 win 46
 11:38:09.432456 IP XXmdl19.mysql > XXlvs01.34365: F 106:106(0) ack 2 win 46
 
 12 packets captured
 24 packets received by filter
 0 packets dropped by kernel
     可以确认是10秒中一次访问。
 
 4,在访问端确认是否可以访问MYSQL,并且是不同的MySQL。
 [root@XXfapp07 ~]# mysql -uXXfxs -pXXfxs -h100.XXX.3.81 -e "show variables like \"%pid%\"" ;
 +---------------+----------------------------------+
 | Variable_name | Value                            |
 +---------------+----------------------------------+
 | pid_file      | /usr/local/mysql/var/XXmdl19.pid |
 +---------------+----------------------------------+
 [root@XXfapp07 ~]# mysql -uXXfxs -pXXfxs -h100.XXX.3.81 -e "show variables like \"%pid%\"" ;
 +---------------+----------------------------------+
 | Variable_name | Value                            |
 +---------------+----------------------------------+
 | pid_file      | /usr/local/mysql/var/XXmdl20.pid |
 +---------------+----------------------------------+
 [root@XXfapp07 ~]# mysql -uXXfxs -pXXfxs -h100.XXX.3.81 -e "show variables like \"%pid%\"" ;
 +---------------+----------------------------------+
 | Variable_name | Value                            |
 +---------------+----------------------------------+
 | pid_file      | /usr/local/mysql/var/XXmdl18.pid |
 +---------------+----------------------------------+
 [root@XXfapp07 ~]#
 5,reboot LVS的 Master
  [root@XXlvs01 ha.d]# reboot
 Broadcast message from root (pts/0) (Wed Mar 25 11:42:19 2009):
 The system is going down for reboot NOW!
 [root@XXlvs01 ha.d]#
      
       在 36秒后 从LVS 进行接管:
 heartbeat[6849]: 2009/03/25_11:42:55 WARN: node XXlvs01: is dead
 heartbeat[6849]: 2009/03/25_11:42:55 WARN: No STONITH device configured.
 ipfail[6956]: 2009/03/25_11:42:55 info: Status update: Node XXlvs01 now has status dead
 heartbeat[6849]: 2009/03/25_11:42:55 WARN: Shared disks are not protected.
 heartbeat[6849]: 2009/03/25_11:42:55 info: Resources being acquired from XXlvs01.
 heartbeat[6849]: 2009/03/25_11:42:55 info: Link XXlvs01:bond0 dead.
 heartbeat[2341]: 2009/03/25_11:42:55 debug: notify_world: setting SIGCHLD Handler to SIG_DFL
 harc[2341]:     2009/03/25_11:42:55 info: Running /etc/ha.d/rc.d/status status
 heartbeat[2342]: 2009/03/25_11:42:55 info: No local resources [/usr/share/heartbeat/ResourceManager listkeys XXlvs02] to acquire.
 heartbeat[6849]: 2009/03/25_11:42:55 debug: StartNextRemoteRscReq(): child count 1
 ipfail[6956]: 2009/03/25_11:42:55 debug: Found ping node 100.XXX.3.254!
 mach_down[2370]:        2009/03/25_11:42:55 info: Taking over resource group IPaddr::100.XXX.3.81/24/bond0
 ResourceManager[2396]:  2009/03/25_11:42:55 info: Acquiring resource group: XXlvs01 IPaddr::100.XXX.3.81/24/bond0 realserver ldirectord::ldirectord.cf
 IPaddr[2423]:   2009/03/25_11:42:55 INFO:  Resource is stopped
 ResourceManager[2396]:  2009/03/25_11:42:55 info: Running /etc/ha.d/resource.d/IPaddr 100.XXX.3.81/24/bond0 start
 ResourceManager[2396]:  2009/03/25_11:42:55 debug: Starting /etc/ha.d/resource.d/IPaddr 100.XXX.3.81/24/bond0 start
 IPaddr[2522]:   2009/03/25_11:42:55 INFO: Using calculated netmask for 100.XXX.3.81: 255.255.255.0
 IPaddr[2522]:   2009/03/25_11:42:55 DEBUG: Using calculated broadcast for 100.XXX.3.81: 100.XXX.3.255
 IPaddr[2522]:   2009/03/25_11:42:55 INFO: eval ifconfig bond0:0 100.XXX.3.81 netmask 255.255.255.0 broadcast 100.XXX.3.255
 IPaddr[2522]:   2009/03/25_11:42:55 DEBUG: Sending Gratuitous Arp for 100.XXX.3.81 on bond0:0 [bond0]
 IPaddr[2493]:   2009/03/25_11:42:55 INFO:  Success
 INFO:  Success
 ResourceManager[2396]:  2009/03/25_11:42:55 debug: /etc/ha.d/resource.d/IPaddr 100.XXX.3.81/24/bond0 start done. RC=0
 ResourceManager[2396]:  2009/03/25_11:42:55 info: Running /etc/ha.d/resource.d/realserver  start
 ResourceManager[2396]:  2009/03/25_11:42:55 debug: Starting /etc/ha.d/resource.d/realserver  start
 lvs start
 IP Virtual Server version 1.2.1 (size=4096)
 Prot LocalAddress:Port Scheduler Flags
   -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
 TCP  100.XXX.3.81:mysql rr
   -> XXmdl20:mysql                Route   1      0          0        
   -> XXmdl19:mysql                Route   1      0          0        
   -> XXmdl18:mysql                Route   1      0          0        
 ResourceManager[2396]:  2009/03/25_11:42:55 debug: /etc/ha.d/resource.d/realserver  start done. RC=0
 ipfail[6956]: 2009/03/25_11:42:55 info: NS: We are still alive!
 ipfail[6956]: 2009/03/25_11:42:55 info: Link Status update: Link XXlvs01/bond0 now has status dead
 ResourceManager[2396]:  2009/03/25_11:42:56 info: Running /etc/ha.d/resource.d/ldirectord ldirectord.cf start
 ResourceManager[2396]:  2009/03/25_11:42:56 debug: Starting /etc/ha.d/resource.d/ldirectord ldirectord.cf start
 ipfail[6956]: 2009/03/25_11:42:56 debug: Found ping node 100.XXX.3.254!
 ResourceManager[2396]:  2009/03/25_11:42:56 debug: /etc/ha.d/resource.d/ldirectord ldirectord.cf start done. RC=0
 mach_down[2370]:        2009/03/25_11:42:56 info: /usr/share/heartbeat/mach_down: nice_failback: foreign resources acquired
 mach_down[2370]:        2009/03/25_11:42:56 info: mach_down takeover complete for node XXlvs01.
 heartbeat[6849]: 2009/03/25_11:42:56 info: mach_down takeover complete.
 ipfail[6956]: 2009/03/25_11:42:56 info: Asking other side for ping node count.
 ipfail[6956]: 2009/03/25_11:42:56 debug: Message [num_ping] sent.
 ipfail[6956]: 2009/03/25_11:42:56 info: Checking remote count of ping nodes.
       在客户端进行确认:
          [root@XXfapp07 ~]# mysql -uXXfxs -pXXfxs -h100.XXX.3.81 -e "show variables like \"%pid%\"" ;
 +---------------+----------------------------------+
 | Variable_name | Value                            |
 +---------------+----------------------------------+
 | pid_file      | /usr/local/mysql/var/XXmdl19.pid |
 +---------------+----------------------------------+
 [root@XXfapp07 ~]# mysql -uXXfxs -pXXfxs -h100.XXX.3.81 -e "show variables like \"%pid%\"" ;
 +---------------+----------------------------------+
 | Variable_name | Value                            |
 +---------------+----------------------------------+
 | pid_file      | /usr/local/mysql/var/XXmdl18.pid |
 +---------------+----------------------------------+
 [root@XXfapp07 ~]# mysql -uXXfxs -pXXfxs -h100.XXX.3.81 -e "show variables like \"%pid%\"" ;
 +---------------+----------------------------------+
 | Variable_name | Value                            |
 +---------------+----------------------------------+
 | pid_file      | /usr/local/mysql/var/XXmdl20.pid |
 +---------------+----------------------------------+
 [root@XXfapp07 ~]#
      在切换期间无法访问,切换完毕后 又可以进行访问,并且轮询分配。

    6,停止一台MySQL。
       初始:
        [root@XXlvs02 ~]# ipvsadm -L
 IP Virtual Server version 1.2.1 (size=4096)
 Prot LocalAddress:Port Scheduler Flags
   -> RXXoteAddress:Port           Forward Weight ActiveConn InActConn
 TCP  100.XXX.3.81:mysql rr
   -> XXmdl20:mysql                Route   1      0          0        
   -> XXmdl19:mysql                Route   1      0          0        
   -> XXmdl18:mysql                Route   1      0          0        
 [root@XXlvs02 ~]#
       停止MySQL XXmdl19
        [root@XXlvs02 ~]# ipvsadm -L
 IP Virtual Server version 1.2.1 (size=4096)
 Prot LocalAddress:Port Scheduler Flags
   -> RXXoteAddress:Port           Forward Weight ActiveConn InActConn
 TCP  100.XXX.3.81:mysql rr
   -> XXmdl20:mysql                Route   1      0          0        
   -> XXmdl18:mysql                Route   1      0          0        
 [root@XXlvs02 ~]#
         在 10秒内自动将 XXmdl19的 MySQL转发在 LVS中删除,只有两个了。
         再访问MySQL时,能正常访问MySQL 20 和 18。

八、特殊对应的注意事项:
  
   追加一台MySQL的步骤:
   1),在新追加的 MySQL上 执行 ipvs_client_for_mysql.sh ,
      确认默认网关是否和 LVS 服务器一致。
      netstat -nr
   2),修改realserver和 ldirector.cf 文件,将新机器IP追加进去。
       ※注意,追加生效是在你修改过 /etc/ha.d/ldirectord.cf  文件后
       就立刻生效了。。。。。这点比较狠,也比较好。。。。
       所以追加之前,一定要启动好 XXmdl17上的 MySQL,并执行好ipvs_client_for_mysql.sh。
       否则,追加之后应用不能访问,应用就会立刻报错。

ipvsadmin 常见的命令用法:
 
    查看:ipvsadm -L
 [root@XXlvs01 ~]# ipvsadm -L
 IP Virtual Server version 1.2.1 (size=4096)
 Prot LocalAddress:Port Scheduler Flags
   -> RXXoteAddress:Port           Forward Weight ActiveConn InActConn
 TCP  100.XXX.3.81:mysql rr
   -> XXmdl17:mysql                Route   1      0          0        
   -> XXmdl20:mysql                Route   1      0          5        
   -> XXmdl18:mysql                Route   1      0          5        
 [root@XXlvs01 ~]#
     追加: /sbin/ipvsadm -a -t 100.XXX.3.81:3306 -r 100.XXX.3.207:3306 -g

     删除: /sbin/ipvsadm -d -t 100.XXX.3.81:3306 -r 100.XXX.3.207:3306
     ※注意,手动删除后,ldirectord 对这条不会再按照"活的就加进来、死的就去掉的"的原则了。
          也挺好。 给你手动控制提供的一个方法。可以脱离 ldirector 的控制了。
          但是 最好不要老去手动删除,那样你就利用不到 ld 的自动的优点了。

 
 
阅读(2914) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~