LVS+keepalived
实验环境:
server2|server3:主备节点 配置 keepalived
server4|server5:RS 开启web服务|配置arptables
iptables off
selinux disabled
*都添加虚拟IP
server2
#安装keepaalived
[root@server2 ~]# ls
keepalived-1.2.24.tar.gz
[root@server2 ~]# tar zxf keepalived-1.2.24.tar.gz
[root@server2 ~]# cd keepalived-1.2.24
[root@server2 keepalived-1.2.24]# ./configure --prefix=/usr/local/keepalived
.....
------------------------
Keepalived version : 1.2.24
Compiler : gcc
Preprocessor flags :
Compiler flags : -Wall -Wunused -Wstrict-prototypes
Linker flags :
Extra Lib : -ldl -lssl -lcrypto
Use IPVS Framework : Yes
IPVS use libnl : No
IPVS syncd attributes : No
IPVS 64 bit stats : No
fwmark socket support : Yes
Use VRRP Framework : Yes
Use VRRP VMAC : Yes
Use VRRP authentication : Yes
With ip rules/routes : Yes
SNMP keepalived support : No
SNMP checker support : No
SNMP RFCv2 support : No
SNMP RFCv3 support : No
SHA1 support : No
Use Debug flags : No
Stacktrace support : No
Memory alloc check : No
libnl version : None
Use IPv4 devconf : No
Use libiptc : No
Use libipset : No
Build genhash : Yes
Build documentation : No
.....
[root@server2 keepalived-1.2.24]# make
[root@server2 keepalived-1.2.24]# make install
[root@server2 keepalived-1.2.24]# yum search kernel-devel
[root@server2 keepalived-1.2.24]# rpm -q kernel-devel
kernel-devel-2.6.32-431.el6.x86_64
[root@server2 keepalived-1.2.24]# rpm -q ipvsadm
ipvsadm-1.26-2.el6.x86_64
[root@server2 keepalived-1.2.24]# rpm -q ipvsadm-devel
package ipvsadm-devel is not installed
[root@server2 keepalived-1.2.24]# cd /usr/local/keepalived/etc/
[root@server2 etc]# ll
total 12
drwxr-xr-x. 3 root root 4096 Jun 3 11:57 keepalived
drwxr-xr-x. 3 root root 4096 Jun 3 11:57 rc.d
drwxr-xr-x. 2 root root 4096 Jun 3 11:57 sysconfig
[root@server2 etc]# ln -s /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
[root@server2 etc]# ln -s /usr/local/keepalived/etc/keepalived/ /etc/
[root@server2 etc]# ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
[root@server2 etc]# ll /etc/init.d/keepalived
lrwxrwxrwx. 1 root root 48 Jun 3 12:55 /etc/init.d/keepalived -> /usr/local/keepalived/etc/rc.d/init.d/keepalived
[root@server2 etc]# ll
total 12
drwxr-xr-x. 3 root root 4096 Jun 3 11:57 keepalived
drwxr-xr-x. 3 root root 4096 Jun 3 11:57 rc.d
drwxr-xr-x. 2 root root 4096 Jun 3 11:57 sysconfig
[root@server2 etc]# cd rc.d/init.d/
[root@server2 init.d]# ls
keepalived
[root@server2 init.d]# ll
total 4
-rw-r--r--. 1 root root 1308 Jun 3 11:57 keepalived
[root@server2 init.d]# chmod +x keepalived
[root@server2 init.d]# ll
total 4
-rwxr-xr-x. 1 root root 1308 Jun 3 11:57 keepalived
[root@server2 init.d]# cd ../..
[root@server2 etc]# ls
keepalived rc.d sysconfig
[root@server2 etc]# ll /etc/sysconfig/keepalived
lrwxrwxrwx. 1 root root 47 Jun 3 12:54 /etc/sysconfig/keepalived -> /usr/local/keepalived//etc/sysconfig/keepalived
[root@server2 etc]# pwd
/usr/local/keepalived/etc
[root@server2 etc]# cd /etc/keepalived/
[root@server2 keepalived]# vim keepalived.conf
!! Configuration File for keepalivedglobal_defs {notification_email {root@localhost #}notification_email_from keepalived@server2smtp_server 172.25.30.2smtp_connect_timeout 30router_id LVS_DEVELvrrp_skip_check_adv_addrvrrp_strictvrrp_garp_interval 0vrrp_gna_interval 0
}vrrp_instance VI_1 {state MASTER #server3 里面改为 BACKUP(备)interface eth0 #发送心跳的节点virtual_router_id 130 #路由idpriority 100 #优先级,主备优先级要不一致advert_int 1authentication {auth_type PASSauth_pass 1111}virtual_ipaddress {172.25.30.100}
}virtual_server 172.25.30.100 80 {delay_loop 6lb_algo rrlb_kind DR
# persistence_timeout 50protocol TCPreal_server 172.25.30.4 80 {weight 1TCP_CHECK {}connect_timeout 3nb_get_retry 3delay_before_retry 3}real_server 172.25.30.5 80 {weight 1TCP_CHECK {connect_timeout 3nb_get_retry 3delay_before_retry 3}}[root@server2 keepalived]# ls
keepalived.conf samples
[root@server2 keepalived]# cd /usr/local/keepalived/
[root@server2 keepalived]# ls
bin etc lib sbin share
[root@server2 keepalived]# cd ..
[root@server2 local]# ls
bin etc games include keepalived lib lib64 libexec sbin share src
[root@server2 local]# scp -r keepalived/ root@172.25.30.3:/usr/local/
[root@server2 local]# cd /etc/keepalived/
[root@server2 keepalived]# ls
keepalived.conf samples
[root@server2 keepalived]# scp keepalived.conf 172.25.30.3:/etc/keepalived/
root@172.25.30.3's password:
keepalived.conf 100% 1056 1.0KB/s 00:00
[root@server2 keepalived]# /etc/init.d/keepalived start
Starting keepalived: /bin/bash: keepalived: command not found[FAILED]
[root@server2 keepalived]# ln -s /usr/local/keepalived/sbin/keepalived /sbin/
[root@server2 keepalived]# /etc/init.d/keepalived start
Starting keepalived: [ OK ][root@server2 etc]#
server3[root@server3 ~]# cd /usr/local/
[root@server3 local]# ls
bin etc games include keepalived lib lib64 libexec sbin share src
[root@server3 local]# ln -s /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
[root@server3 local]# ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
[root@server3 local]# chmod +x /etc/init.d/keepalived
[root@server3 local]# mkdir /etc/keepalived
[root@server3 local]# cd /etc/keepalived/
[root@server3 keepalived]# ls
keepalived.conf
[root@server3 keepalived]# vim keepalived.conf
[root@server3 keepalived]# /etc/init.d/keepalived start
Starting keepalived: /bin/bash: keepalived: command not found[FAILED]
[root@server3 keepalived]# ln -s /usr/local/keepalived/sbin/keepalived /sbin/
[root@server3 keepalived]# /etc/init.d/keepalived start
Starting keepalived: [ OK ]
*Server4和Server5
[root@server4 ~]# /etc/init.d/httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.25.30.4 for ServerName[ OK ]
[root@server4 ~]#
[root@server5 ~]# /etc/init.d/httpd start
Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 172.25.254.5 for ServerName[ OK ]
[root@server5 ~]#
测试:
[root@foundation30 Desktop]# curl 172.25.30.100
server4
[root@foundation30 Desktop]# curl 172.25.30.100
server5
[root@foundation30 Desktop]# curl 172.25.30.100
server4
[root@foundation30 Desktop]# curl 172.25.30.100
server5
[root@foundation30 Desktop]# [root@server2 keepalived]# ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.25.30.100:http rr-> 172.25.30.4:http Route 1 0 6 -> 172.25.30.5:http Route 1 0 7
[root@server2 keepalived]# 基于 Vsftpd 服务|开放 21 端口实验环境:
基于keepalived配置
server4|server5安装 vsftpd 服务并开启server4|server5同步
[root@server4 ~]# yum install vsftpd -y
[root@server4 ~]# /etc/init.d/vsftpd start
Starting vsftpd for vsftpd: [ OK ]
[root@server4 ~]# server2|server3中[root@server2 ~]# vim /etc/keepalived/keepalived.conf .....persistence_timeout 50 #必须有时间延迟
....
*Server 3中同步[root@server2 ~]# ipvsadm -l
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 172.25.30.100:ftp rr persistent 50 #ftp服务持续连接-> 172.25.30.4:ftp Route 1 0 0 -> 172.25.30.5:http Route 1 1 0
TCP 172.25.30.100:http rr-> 172.25.30.4:http Route 1 0 0 -> 172.25.30.5:http Route 1 0 0
[root@server2 ~]#
*测试[root@foundation30 pub]# lftp 172.25.30.100
lftp 172.25.30.100:~> ls
drwxr-xr-x 2 0 0 4096 Feb 12 2013 pub
lftp 172.25.30.100:/> exit
[root@foundation30 pub]#