最近搞两个lvs的测试,为了测试能够快速完成,就使用了piranha这个web工具来完成lvs的配置。这个工具使lvs的配置变的简单明了。piranha为REDHAT默认cluster的GUI接口配置程序,可单独设置cluster功能, 亦可加上HA后备功能。
我在一台pc机上建立了3个vm,一台作为lvs使用,另外的两台作为真实机器提供服务。下面是我的操作过程:ipvsadm是通过源代码包安装的,piranha是通过yum安装的,由于依赖的包比较多,yum安装比较方便。
[root@vmhost ~]# yum -y install piraha
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirror01.idc.hinet.net
* extras: mirror01.idc.hinet.net
* updates: mirror01.idc.hinet.net
base | 1.1 kB 00:00
base/primary | 1.2 MB 00:01
base 3566/3566
extras | 2.1 kB 00:00
extras/primary_db | 206 kB 00:00
updates | 1.9 kB 00:00
updates/primary_db | 666 kB 00:00
Setting up Install Process
No package piraha available.
Nothing to do
[root@vmhost ~]# yum -y install piranha
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirror01.idc.hinet.net
* extras: mirror01.idc.hinet.net
* updates: mirror01.idc.hinet.net
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package piranha.x86_64 0:0.8.4-22.el5 set to be updated
--> Processing Dependency: ipvsadm >= 1.14 for package: piranha
--> Processing Dependency: php for package: piranha
--> Running transaction check
---> Package ipvsadm.x86_64 0:1.24-13.el5 set to be updated
---> Package php.x86_64 0:5.1.6-27.el5_7.5 set to be updated
--> Processing Dependency: php-cli = 5.1.6-27.el5_7.5 for package: php
--> Processing Dependency: php-common = 5.1.6-27.el5_7.5 for package: php
--> Running transaction check
---> Package php-cli.x86_64 0:5.1.6-27.el5_7.5 set to be updated
---> Package php-common.x86_64 0:5.1.6-27.el5_7.5 set to be updated
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================================================================
Package Arch Version Repository Size
==================================================================================================================
Installing:
piranha x86_64 0.8.4-22.el5 base 716 k
Installing for dependencies:
ipvsadm x86_64 1.24-13.el5 base 34 k
php x86_64 5.1.6-27.el5_7.5 updates 2.3 M
php-cli x86_64 5.1.6-27.el5_7.5 updates 2.2 M
php-common x86_64 5.1.6-27.el5_7.5 updates 153 k
Transaction Summary
==================================================================================================================
Install 5 Package(s)
Upgrade 0 Package(s)
Total download size: 5.4 M
Downloading Packages:
(1/5): ipvsadm-1.24-13.el5.x86_64.rpm | 34 kB 00:00
(2/5): php-common-5.1.6-27.el5_7.5.x86_64.rpm | 153 kB 00:00
(3/5): piranha-0.8.4-22.el5.x86_64.rpm | 716 kB 00:01
(4/5): php-cli-5.1.6-27.el5_7.5.x86_64.rpm | 2.2 MB 00:02
(5/5): php-5.1.6-27.el5_7.5.x86_64.rpm | 2.3 MB 00:02
------------------------------------------------------------------------------------------------------------------
Total 725 kB/s | 5.4 MB 00:07
warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897
updates/gpgkey | 1.5 kB 00:00
Importing GPG key 0xE8562897 "CentOS-5 Key (CentOS 5 Official Signing Key) <[email protected]>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-5
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : php-common 1/5
Installing : php-cli 2/5
Installing : php 3/5
Installing : ipvsadm 4/5
warning: /etc/rc.d/init.d/ipvsadm saved as /etc/rc.d/init.d/ipvsadm.rpmorig
Installing : piranha 5/5
Installed:
piranha.x86_64 0:0.8.4-22.el5
Dependency Installed:
ipvsadm.x86_64 0:1.24-13.el5 php.x86_64 0:5.1.6-27.el5_7.5 php-cli.x86_64 0:5.1.6-27.el5_7.5
php-common.x86_64 0:5.1.6-27.el5_7.5
Complete!
安装完成后会在/etc/sysconfig/下产生一个ha目录
[root@vmhost ~]# cd /etc/sysconfig/
[root@vmhost sysconfig]# cd h
ha/ hidd httpd hwconf
[root@vmhost sysconfig]# cd ha
[root@vmhost ha]# ls
conf logs lvs.cf modules web
[root@vmhost ha]# ll
total 12
drwxr-xr-x 2 root root 4096 Feb 20 14:54 conf
drwxr-xr-x 2 root root 4096 Feb 20 14:54 logs
-rw-rw-r-- 1 root piranha 0 Jul 22 2011 lvs.cf
lrwxrwxrwx 1 root root 24 Feb 20 14:54 modules -> /usr/lib64/httpd/modules
drwxr-xr-x 3 root root 4096 Feb 20 14:54 web
启动prianha的web服务,并生成web登录密码
[root@vmhost conf]# /etc/init.d/piranha-gui start
Starting piranha-gui: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.1.233 for ServerName
[ OK ]
[root@vmhost conf]# pir
piranha_gui piranha-passwd pirut
[root@vmhost conf]# piranha-passwd
New Password:
Verify:
Adding password for user piranha
[root@vmhost conf]# netstat -anp|grep 3636
tcp 0 0 0.0.0.0:3636 0.0.0.0:* LISTEN 11893/httpd
通过web界面配置比较简单,这里就不再记录。生成的文件如下:
[root@vmhost ~]# more /etc/sysconfig/ha/lvs.cf
serial_no = 22
primary = 192.168.163.100
service = lvs
backup = 0.0.0.0
heartbeat = 1
heartbeat_port = 539
keepalive = 6
deadtime = 18
network = direct
debug_level = NONE
virtual lvs {
active = 1
address = 192.168.163.101 eth0:1
vip_nmask = 255.255.255.255
port = 80
persistent = 30
pmask = 255.255.255.255
send = "GET / HTTP/1.0\r\n\r\n"
expect = "HTTP"
use_regex = 0
load_monitor = none
scheduler = wlc
protocol = tcp
timeout = 6
reentry = 15
quiesce_server = 0
server web1 {
address = 192.168.163.110
active = 1
port = 80
weight = 1
}
server web2 {
address = 192.168.163.120
active = 1
port = 80
weight = 1
}
}由于我测试的功能比较简单,所有这些配置足够了。
启动lvs服务,服务启动后可以看到虚拟地址自动也启动了:
/etc/init.d/pulse
Usage: pulse {start|stop|status|restart|condrestart|reload}
[root@vmhost conf]# /etc/init.d/pulse start
Starting pulse: pulse: no active lvs services defined in /etc/sysconfig/ha/lvs.cf
[FAILED]
[root@vmhost conf]# /etc/init.d/pulse start
Starting pulse: [ OK ]
[root@vmhost conf]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:E4:EB:73
inet addr:192.168.5.13 Bcast:192.168.5.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:18911 errors:0 dropped:0 overruns:0 frame:0
TX packets:25124 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:11379988 (10.8 MiB) TX bytes:13604104 (12.9 MiB)
eth0:1 Link encap:Ethernet HWaddr 00:0C:29:E4:EB:73
inet addr:192.168.5.14 Bcast:192.168.5.14 Mask:255.255.255.255
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:10 errors:0 dropped:0 overruns:0 frame:0
TX packets:10 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:660 (660.0 b) TX bytes:660 (660.0 b)
修改/etc/sysctl.conf文件,把net.ipv4.ip_forward 的值改为1。lvs服务器就配置完了。
在另外两台服务器上安装nginx,修改过index.html文件不要相同,启动服务。
并执行ifconfig lo:0 192.168.163.101 broadcast 192.168.163.101 netmask 255.255.255.255 up或者
iptables -t nat -A PREROUTING -p tcp -d 192.168.163.101 --dport 80 -j REDIRECT
192.168.163.101是lvs的虚拟地址。
并修改过每台机器的/etc/sysctl.conf文件,添加
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.tunl0.arp_ignore = 1
net.ipv4.conf.tunl0.arp_announce = 2
执行sysctl -p使之生效。剩下来的就是测试lvs了。
通过prianha来配置lvs确实简单不少