keepalived编译安装
Update: 2012-12-10
编译环境
- CentOS 6.3
- RedHat 6.0
- CentOS 6.4源中已添加keepalived,直接用yum安装即可。
yum -y install unzip wget gcc autoconf automake make libtool pkgconfig glib2-devel \ libxml2 libxml2-devel bzip2-devel libtool-ltdl-devel libuuid-devel libxslt-devel; yum -y install ipvsadm kernel-devel; yum -y install openssl openssl-devel popt-devel popt libnl libnl-devel;
keepalived编译安装
mkdir -p ~/down && cd ~/down \ && wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz
cd ~/down \ && tar zxvf keepalived-1.2.7.tar.gz \ && cd keepalived-1.2.7 \ && CFLAGS="-O3 -pipe" ./configure --sysconf=/etc --with-kernel-dir=/usr/src/kernels/$(uname -r) \ && make && make install \ && ln -sf /usr/local/sbin/keepalived /usr/sbin/keepalived
Keepalived configuration ------------------------ Keepalived version : 1.2.7 Compiler : gcc Compiler flags : -O3 -pipe Extra Lib : -lpopt -lssl -lcrypto -lnl Use IPVS Framework : Yes IPVS sync daemon support : Yes IPVS use libnl : Yes Use VRRP Framework : Yes Use VRRP VMAC : Yes SNMP support : No Use Debug flags : No
keepalived配置
/etc/keepalived/keepalived.conf
keepalived启动
/etc/init.d/keepalived start|stop|restart
其他
-
arping
/sbin/arping -I eth0 -c 5 -s $WEB_VIP $GW
- ifconfig可能看不到vip,用ip addr试试
LVS监控
用ipvsadm命令
通常情况下lvs的运行情况以及资源使用情况是无法使用top或vmstat命令时来查看的。对于LVS-DR结构的LVS来说,其只会转发网络包。几乎不会耗费CPU资源,这时我们查看系统负载应该为0.00。
-
通过使用ipvsadm命令可以查看当前LVS的运行情况,如下:
[root@LVS-Master]# ipvsadm Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP localhost:https wlc persistent 50 -> localhost:https Route 1 0 0 -> localhost:https Route 1 0 0 TCP localhost:http wlc persistent 50 -> localhost:http Route 1 0 0 -> localhost:http Route 3 0 0
当有新连接过来时,其相关的计数就会增加。
-
查看连接数/进入包(字节)/输出包(字节):
命令:ipvsadm -Ln --stats -t |u|f service-address -t, --tcp-service -u, --udp-service -f, --fwmark-service -L, -l, --list List the virtual server table if no argument is specified. -n, --numeric Numeric output. --stats Output of statistics information.
示例:
[root@experiment ~]# ipvsadm -Ln --stats -t 192.168.108.180:80 Prot LocalAddress:Port Conns InPkts OutPkts InBytes OutBytes -> RemoteAddress:Port TCP 192.168.108.180:80 5771754 101697K 0 5338M 0 -> 192.168.108.162:80 454297 13736280 0 761572K 0 -> 192.168.108.161:80 5317457 87961304 0 4576M 0
-
另外通过查看cat /proc/net/ip_vs_stats 也可以查看lvs信息,只不过这里的输出时16进制的。
[root@LVS-Master] # cat /proc/net/ip_vs_stats Total Incoming Outgoing Incoming Outgoing Conns Packets Packets Bytes Bytes 594BFC 6335751 0 145F90EC1 0 Conns/s Pkts/s Pkts/s Bytes/s Bytes/s 0 0 0 0 0