Chinaunix首页 | 论坛 | 博客
  • 博客访问: 648961
  • 博文数量: 98
  • 博客积分: 3145
  • 博客等级: 中校
  • 技术积分: 1902
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-15 12:52
文章分类
文章存档

2021年(1)

2020年(1)

2016年(8)

2015年(3)

2014年(1)

2013年(5)

2012年(4)

2011年(9)

2010年(12)

2009年(42)

2008年(12)

我的朋友

分类:

2010-01-07 10:56:01

#sysctl –p

 

配置keepalived

登陆real server 服务器配置keepalived

#vi /etc/keepalived/keepalived.conf

内容如下:

主服务器的配置:

! Configuration File for keepalived

 

global_defs {

   notification_email {

     acassen@firewall.loc

     failover@firewall.loc

     sysadmin@firewall.loc

   }

   notification_email_from Alexandre.Cassen@firewall.loc

   smtp_server 192.168.200.1

   smtp_connect_timeout 30

   router_id LVS_DEVEL

}

 

vrrp_instance VI_1 {

    state BACKUP

    interface eth0

    virtual_router_id 51

    priority 100

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

    192.168.1.100

    }

notify_master /opt/sbin/master.sh

notify_backup /opt/sbin/backup.sh

}

 

 

virtual_server 219.224.99.19 80 {

    delay_loop 6

    lb_algo rr

!    lb_kind NAT

    lb_kind DR

    persistence_timeout 50

    protocol TCP

    real_server 192.168.1.10 80 {

        weight 1

        TCP_CHECK {

        connect_timeout 3

        }

    }

    real_server 192.168.1.11 80 {

        weight 3

        TCP_CHECK {

        connect_timeout 3

        }

    }

}

从服务器的配置:

! Configuration File for keepalived

 

global_defs {

   notification_email {

     acassen@firewall.loc

     failover@firewall.loc

     sysadmin@firewall.loc

   }

   notification_email_from Alexandre.Cassen@firewall.loc

   smtp_server 192.168.200.1

   smtp_connect_timeout 30

   router_id LVS_DEVEL

}

 

vrrp_instance VI_1 {

    state BACKUP

    interface eth0

    virtual_router_id 51

    priority 150

    advert_int 1

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    virtual_ipaddress {

   192.168.1.100

    }

notify_master /opt/sbin/master.sh

  notify_backup /opt/sbin/backup.sh

}

 

 

virtual_server 219.224.99.19 80 {

    delay_loop 6

    lb_algo rr

!    lb_kind NAT

    lb_kind DR

    persistence_timeout 50

    protocol TCP

    real_server 192.168.1.10 80 {

        weight 1

        TCP_CHECK {

        connect_timeout 3

        }

    }

    real_server 192.168.1.11 80 {

        weight 3

        TCP_CHECK {

        connect_timeout 3

        }

    }

}

 

  配置脚本:

#vi /opt/sbin/master.sh

加入:

#!/bin/sh

#master.sh

ip addr del 192.168.1.100/32 dev eth0

ip addr add 192.168.1.100/32 dev eth0

 

#vi /opt/sbin/backup.sh

加入:

#!/bin/sh

#backup.sh

ip addr add 192.168.1.100/32 dev eth0

 

启动

#/etc/init.d/keepalived start

查看ipvsadm

#ipvsadm –ln

 

测试

node1keeplive关闭,查看node2是否能将虚拟IP抢过去

node2WEB关闭,查看IPVS中是否自动将改节点删除

访问WEB,看是否是访问到不同的NODE

配置说明

全局配置

 全局配置是对整个KEEPALIVED都起左右的配置,不管是否使用LVS

每个配置块都是包含在{}中,包括2个部分全局定义(global definition)和静态路由定义(static ipaddress/routes)

3.1.1 全局定义global definition

全局定义定义keepalived的通讯机制和标识

global_defs

{

notification_email

{

admin@example.com

}

notification_email_from admin@example.com

smtp_server 127.0.0.1

stmp_connect_timeout 30

router_id my_hostname

}

说明:

notification_email 定义keepalived发生切换是,发送邮件通知的对象,可以多个,每个一行

smtp_server SMTP服务器地址

admin@example.com 发送邮件地址

router_id 定义运行keepalived服务器的标识

3.1.2 静态地址和路由定义

静态地址和路由定义,定义的地址是不会随VRRPD定义的地址变化而变化的,虚拟IP是变化的。一般需要在realserver上定义。

static_ipaddress

{

192.168.1.1/24 brd + dev eth0 scope global

...

}

static_routes

{

src $SRC_IP to $DST_IP dev $SRC_DEVICE

...

src $SRC_IP to $DST_IP via $GW dev $SRC_DEVICE

}

说明:

每一行设置一个IP ,使用的是linuxIP命令,上面的static_ipaddress命令等同与ip addr add 192.168.1.1/32 dev eth0

静态路由设置将哪来的IP从哪返回

配置

VRRPD配置包括2部分,同步组和实例。

3.2.1 同步组

同步组是用于当一个服务器有2个网段,比如内网和外网,分别有1个实例,当内网出现故障是,keepalived做检查发现外网没问题,不会发生切换。同步组就是将内外网放到一个组中,不管哪出问题了都进行切换。

vrrp_sync_group VG_1 {

group {

inside_network # 这里是实例(比如VG_1

outside_network

}

notify_master /path/to/to_master.sh

notify_backup /path_to/to_backup.sh

notify_fault "/path/fault.sh VG_1"

notify /path/to/notify.sh

smtp_alert

}

说明:
阅读(2022) | 评论(0) | 转发(0) |
0

上一篇:LVS之IPVS之一

下一篇:LVS之IPVS之三

给主人留下些什么吧!~~