一、LVS+Keepalived安装
1、下载源码包
cd /usr/src/
wget http://www.linuxvirtualserver.org/software/kernel-2.6/ipvsadm-1.24.tar.gz
wget http://www.keepalived.org/software/keepalived-1.1.15.tar.gz
2、建立软链接
ln -s /usr/src/kernels/2.6.* /usr/src/linux
3、安装ipvsadm、keepalived
cd /usr/src/ && tar xzvf ipvsadm-1.24.tar.gz &&cd ipvsadm-1.24
&& make && make install
cd /usr/src/ && tar -xzvf keepalived-1.1.15.tar.gz &&
cd keepalived-1.1.15 && ./configure && make && make install
4、配置keepalived
cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
mkdir -p /etc/keepalived
cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/sbin/keepalived /usr/sbin/
5、修改keepalived配置文件
vi /etc/keepalived/keepalived.conf,根据实际情况修改:
- ! Configuration File for keepalived
- global_defs {
- notification_email {
- wgkgood@163.com
- }
- notification_email_from wgkgood@163.com
- smtp_server 127.0.0.1
- smtp_connect_timeout 30
- router_id LVS_DEVEL
- }
- # VIP1
- vrrp_instance VI_1 {
- state MASTER //备份服务器改成BACKUP
- interface eth0
- lvs_sync_daemon_inteface eth0
- virtual_router_id 51
- priority 100 //备份服务器改成90
- advert_int 5
- authentication {
- auth_type PASS
- auth_pass 1111
- }
- virtual_ipaddress {
- 192.9.117.145 //VIP地址
- }
- }
- virtual_server 192.9.117.145 80 {
- delay_loop 6
- lb_algo rr //lvs算法
- lb_kind DR
- persistence_timeout 60
- protocol TCP
- real_server 192.9.117.141 80 {
- weight 100
- TCP_CHECK {
- connect_timeout 10
- nb_get_retry 3
- delay_before_retry 3
- connect_port 80
- }
- }
- real_server 192.9.117.142 80 {
- weight 100
- TCP_CHECK {
- connect_timeout 10
- nb_get_retry 3
- delay_before_retry 3
- connect_port 80
- }
- }
- }
同理Lvs_backup也如上安装,并修改参数,Lvs+keepalived配置完毕后,启动keepalived, /etc/init.d/keepalived start 即可!然后在squid_1、squid_2分别执行realserver.sh脚本
