免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4180 | 回复: 1
打印 上一主题 下一主题

lvs keepalived无法启动vip [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2013-04-24 16:29 |只看该作者 |倒序浏览
lvs master:192.168.2.6
lvs backup:192.168.2.101

realserver1:192.168.2.103
realserver2:192.168.2.13

keepalived的配置如下:
! Configuration File for keepalived

global_defs {
   router_id lvs_1
}

vrrp_sync_group mysql {
group {
mysql_userdb
}

vrrp_instance mysql_userdb {
    state MASTER
    interface eth1
    lvs_sync_daemon_interface eth1
    virtual_router_id 51
    priority 180
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.2.242
    }
}

virtual_server 192.168.2.242 3306 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 600
    protocol TCP

    real_server 192.168.2.103 3306 {
        weight 1
        TCP_CHECK {
         connect_timeout 10
         nb_get_retry 3
         delay_before_retry 3
         connect_port 3306   
       }
    }

    real_server 192.168.2.13 3306 {
        weight 1
        TCP_CHECK {
         connect_timeout 10
         nb_get_retry 3
         delay_before_retry 3
         connect_port 3306   
       }
    }
}
}

在MASTER上启动keepalived后,ip addr list无法看到vip
[root@localhost ~]# ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddressort Scheduler Flags
  -> RemoteAddressort           Forward Weight ActiveConn InActConn
TCP  192.168.2.242:mysql rr persistent 600
  -> 192.168.2.13:mysql           Route   1      0          0         
  -> 192.168.2.103:mysql          Route   1      0          0         

root@localhost ~]# ip addr list
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet 192.168.1.112/32 brd 192.168.1.112 scope global lo:0
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 78:2b:cb:48:58:10 brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.6/24 brd 192.168.1.255 scope global eth0
    inet6 fe80::7a2b:cbff:fe48:5810/64 scope link
       valid_lft forever preferred_lft forever
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 78:2b:cb:48:58:12 brd ff:ff:ff:ff:ff:ff
    inet 192.168.2.6/16 brd 192.168.2.255 scope global eth1
    inet6 fe80::7a2b:cbff:fe48:5812/64 scope link
       valid_lft forever preferred_lft forever
4: eth2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop qlen 1000
    link/ether 78:2b:cb:48:58:14 brd ff:ff:ff:ff:ff:ff

keeplived的启动日志如下:
Apr 24 16:06:45 localhost Keepalived: Stopping Keepalived v1.1.17 (04/24,2013)
Apr 24 16:06:45 localhost Keepalived_vrrp: Terminating VRRP child process on signal
Apr 24 16:06:45 localhost Keepalived_healthcheckers: Terminating Healthchecker child process on signal
Apr 24 16:06:45 localhost Keepalived: Starting Keepalived v1.1.17 (04/24,2013)
Apr 24 16:06:45 localhost Keepalived_healthcheckers: Using MII-BMSR NIC polling thread...
Apr 24 16:06:45 localhost Keepalived: Starting Healthcheck child process, pid=19778
Apr 24 16:06:45 localhost Keepalived: Starting VRRP child process, pid=19779
Apr 24 16:06:45 localhost Keepalived_vrrp: Using MII-BMSR NIC polling thread...
Apr 24 16:06:45 localhost Keepalived_healthcheckers: Netlink reflector reports IP 192.168.1.6 added
Apr 24 16:06:45 localhost Keepalived_healthcheckers: Netlink reflector reports IP 192.168.2.6 added
Apr 24 16:06:45 localhost Keepalived_vrrp: Netlink reflector reports IP 192.168.1.6 added
Apr 24 16:06:45 localhost Keepalived_healthcheckers: Registering Kernel netlink reflector
Apr 24 16:06:45 localhost Keepalived_healthcheckers: Registering Kernel netlink command channel
Apr 24 16:06:45 localhost Keepalived_vrrp: Netlink reflector reports IP 192.168.2.6 added
Apr 24 16:06:45 localhost Keepalived_vrrp: Registering Kernel netlink reflector
Apr 24 16:06:45 localhost Keepalived_vrrp: Registering Kernel netlink command channel
Apr 24 16:06:45 localhost Keepalived_vrrp: Registering gratutious ARP shared channel
Apr 24 16:06:45 localhost Keepalived_healthcheckers: Opening file '/etc/keepalived/keepalived.conf'.
Apr 24 16:06:45 localhost Keepalived_healthcheckers: Configuration is using : 12385 Bytes
Apr 24 16:06:45 localhost Keepalived_vrrp: Opening file '/etc/keepalived/keepalived.conf'.
Apr 24 16:06:45 localhost Keepalived_vrrp: Configuration is using : 60734 Bytes
Apr 24 16:06:45 localhost Keepalived_healthcheckers: Activating healtchecker for service [192.168.2.103:3306]
Apr 24 16:06:45 localhost Keepalived_healthcheckers: Activating healtchecker for service [192.168.2.13:3306]

请问keepalived如何绑定vip呢?

论坛徽章:
4
CU大牛徽章
日期:2013-04-17 11:50:25CU大牛徽章
日期:2013-04-17 11:50:33CU大牛徽章
日期:2013-04-17 11:50:39CU大牛徽章
日期:2013-04-17 11:50:44
2 [报告]
发表于 2013-04-25 10:37 |只看该作者
注意"{"是否和"}"配对,注意"{"和前面的字符串需要有1个空格,比如"VI_1 {"不要写成了"VI_1{"
绑定虚IP:
ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
自己可以写一个脚本 如:

#!/bin/bash
#filename:real.sh
VIP=1.1.1.1
. /etc/rc.d/init.d/functions
case "$1" in
start)
     ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
     /sbin/route add -host $VIP dev lo:0
     echo "1">/proc/sys/net/ipv4/conf/lo/arp_ignore
     echo "2">/proc/sys/net/ipv4/conf/lo/arp_announce
     echo "1">/proc/sys/net/ipv4/conf/all/arp_ignore
     echo "2">/proc/sys/net/ipv4/conf/all/arp_announce
     sysctl -p >/dev/null 2>&1
     echo "realServer Start ok"
     ;;
stop)
     ifconfig lo:0 down
     route del $VIP >/dev/null 2>&1
     echo "0">/proc/sys/net/ipv4/conf/lo/arp_ignore
     echo "0">/proc/sys/net/ipv4/conf/lo/arp_announce
     echo "0">/proc/sys/net/ipv4/conf/all/arp_ignore
     echo "0">/proc/sys/net/ipv4/conf/all/arp_announce
     echo "realServer Stoped"
     ;;
*)
    echo "Usage0{start|stop}"
    exit 1
esac
exit 0
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP