ubuntu下lvs+keepalived+mysql无法访问vip?

duruo850 发布于 2015/09/24 17:49
阅读 1K+
收藏 0

我在ubuntu下准备搭建一个mysql高可用服务组,但是无法访问vip,大家帮我看看,问题在哪?

高可用架构

mysql master:10.24.6.5:3306

mysql slave:10.24.6.6:3306

LB节点: 10.24.6.4

VIP : 10.24.6.2

LB 配置:


lvs

lvs采用ubuntu默认

配置以后的效果如下:

root@LogicServer2:/var/log# sudo ipvsadm
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.24.6.2:mysql rr
  -> 10.24.6.5:mysql              Route   3      0          0         
  -> 10.24.6.6:mysql              Route   3      0          0  

keepalived配置


global_defs {
    router_id HaMySQL_1
}
vrrp_instance VI_MYSQL {
    state MASTER
    interface eth1
    virtual_router_id 100
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.24.6.2
    }
}


virtual_server 10.24.6.2 3306 {
    delay_loop 6
    lb_algo rr
    lb_kind DR
    protocol TCP


    real_server 10.24.6.5 3306 {
        weight 3
        TCP_CHECK {
        connect_timeout 3
        nb_get_retry 3
        delay_before_retry 3
        connect_port 3306
        }
    }


    real_server 10.24.6.6 3306 {
        weight 3
        TCP_CHECK {
        connect_timeout 3
        nb_get_retry 3
        delay_before_retry 3
        connect_port 3306
        }
    }
}


mysql master 配置

/etc/init.d/realserver.sh

#!/bin/bash  
# description: Config realserver lo and apply noarp  
SNS_VIP=10.24.6.2
#/etc/rc.d/init.d/functions  
case "$1" in
start)
       ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
       /sbin/route add -host $SNS_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 $SNS_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 "Usage: $0 {start|stop}"  
       exit 1
esac
exit 0

ip映射

root@ubuntu :/home/ubuntu-server1# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet 10.24.6.2/32 brd 10.24.6.2 scope global lo:0
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:66🇦🇫b7 brd ff:ff:ff:ff:ff:ff
    inet 10.24.6.5/24 brd 10.24.6.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe66:afb7/64 scope link 
       valid_lft forever preferred_lft forever




mysql slave 配置

/etc/init.d/realserver.sh

#!/bin/bash  
# description: Config realserver lo and apply noarp  
SNS_VIP=10.24.6.2
#/etc/rc.d/init.d/functions  
case "$1" in
start)
       ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
       /sbin/route add -host $SNS_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 $SNS_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 "Usage: $0 {start|stop}"  
       exit 1
esac
exit 0

ip映射

logic_server@logic :~$ ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet 10.24.6.2/32 brd 10.24.6.2 scope global lo:0
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:d9🇨🇦22 brd ff:ff:ff:ff:ff:ff
    inet 10.24.6.6/24 brd 10.24.6.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fed9:ca22/64 scope link 

       valid_lft forever preferred_lft forever


效果

在其他ip上可以pingVIP,但是不可以telnet mysql服务(真实mysql服务可以telnet):

mqtt_server@MqttServer:~$ ping 10.24.6.2
PING 10.24.6.2 (10.24.6.2) 56(84) bytes of data.
64 bytes from 10.24.6.2: icmp_seq=1 ttl=64 time=0.504 ms
64 bytes from 10.24.6.2: icmp_seq=2 ttl=64 time=0.664 ms
64 bytes from 10.24.6.2: icmp_seq=3 ttl=64 time=0.642 ms
64 bytes from 10.24.6.2: icmp_seq=4 ttl=64 time=0.712 ms
64 bytes from 10.24.6.2: icmp_seq=5 ttl=64 time=0.712 ms
^C64 bytes from 10.24.6.2: icmp_seq=6 ttl=64 time=0.675 ms
64 bytes from 10.24.6.2: icmp_seq=7 ttl=64 time=0.702 ms
^Z
[1]+  Stopped                 ping 10.24.6.2

mqtt_server@MqttServer:~$ telnet 10.24.6.5 3306
Trying 10.24.6.5...
Connected to 10.24.6.5.
Escape character is '^]'.
_
5.5.41-0ubuntu0.14.04.1-logj
                            u\KAG~e€6+ptuqU5HIw;mysql_native_password
^CConnection closed by foreign host.
mqtt_server@MqttServer:~$ telnet 10.24.6.6 3306
Trying 10.24.6.6...
Connected to 10.24.6.6.
Escape character is '^]'.
_
5.5.44-0ubuntu0.14.04.1-log…    ZqIZfr,€`@]66JS?%:57mysql_native_password


!#08S01Got packets out of orderConnection closed by foreign host.
mqtt_server@MqttServer:~$ telnet 10.24.6.2 3306

Trying 10.24.6.2...
telnet: Unable to connect to remote host: Connection refused






加载中
0
z
zb1489231669139

我也出现你这样的问题  怎么解决的啊

返回顶部
顶部