Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1984549
  • 博文数量: 176
  • 博客积分: 1857
  • 博客等级: 上尉
  • 技术积分: 2729
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-14 22:55
个人简介

吾生有涯,而知无涯,适当止学.循序渐进,步步提升 Talk is cheap, show me the code.

文章分类

全部博文(176)

文章存档

2019年(1)

2018年(14)

2017年(20)

2016年(31)

2015年(15)

2014年(5)

2013年(10)

2012年(80)

分类: Mysql/postgreSQL

2012-08-09 16:35:07

Node1: 10.0.17.154
Node2: 10.0.17.155
VIP: 10.0.17.158

环境 centos5.2


##########################LVS+Keepalived########################
1、安装ipvsadm
yum -y install ipvsadm
 
2、安装keepalived
[root@mysql-n2 ~]# wget
[root@mysql-n2 ~]# tar zxvf keepalived-1.1.15.tar.gz
[root@mysql-n2 ~]# cd keepalived-1.1.15
[root@mysql-n2 keepalived-1.1.15]# ./configure --prefix=/ --mandir=/usr/local/share/man/ --with-kernel-dir=/usr/src/kernels/2.6.18-194.el5-x86_64/

配置后会出现如下结果,则配置正确:

Keepalived configuration
------------------------
Keepalived version       : 1.1.15
Compiler                 : gcc
Compiler flags           : -g -O2
Extra Lib                : -lpopt -lssl -lcrypto
Use IPVS Framework       : Yes
IPVS sync daemon support : Yes
Use VRRP Framework       : Yes
Use LinkWatch            : No
Use Debug flags          : No

[root@mysql-n2 keepalived-1.1.15]make && make install
[root@mysql-n2 keepalived-1.1.15]# cd /etc/keepalived/
[root@mysql-n2 keepalived-1.1.15]# vim keepalived.conf


3.keepalived.conf配置细节:
! Configuration File for keepalived

global_defs {
   notification_email {
     zhangshengdongly@gmail.com
   }
   notification_email_from zhangshengdongly@gmail.com
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}

vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.0.17.158
    }
}

virtual_server 10.0.17.158 443 {
    delay_loop 6
    lb_algo wlc
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    real_server 10.0.17.154 443 {
        weight 3
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
    real_server 10.0.17.155 443 {
        weight 1
        TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

BACKUP:只要修改"state MASTER"为"state BACKUP"
              将 "priority 100"更改为"priority 80"

4.配置realserver脚本:(由于只有两台主机,所以既当lvs,也当realserver)
疑问:netmask 255.255.255.255 up修改为netmask 255.255.252.0 up就出现问题

[root@mysql-n2 keepalived-1.1.15]vim realserver

#!/bin/bash
#description : start realserver
VIP=192.168.1.250
/etc/rc.d/init.d/functions
case "$1" in
start)
echo " start LVS of REALServer"
/sbin/ifconfig lo:0 $VIP broadcast $VIP netmask 255.255.255.255 up
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
;;
stop)
/sbin/ifconfig lo:0 down
echo "close LVS Directorserver"
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 "Usage: $0 {start|stop}"
exit 1
esac

[root@mysql-n2 keepalived-1.1.15]# chmod +x realserver
[root@mysql-n2 keepalived-1.1.15]# ./realserver start

5.主&副keepalived启动:
[root@mysql-n2 ~]# /etc/init.d/keepalived start
Starting keepalived: [  OK  ]
[root@mysql-n1 keepalived]# /etc/init.d/keepalived start
Starting keepalived: [  OK  ]

6.查看日志&IP,看看是否启动成功,ip是否绑定
[root@mysql-n2 ~]# tail -f /var/log/messages
Aug  8 14:47:05 mysql-n2 Keepalived_healthcheckers: SMTP alert successfully sent.
Aug  8 14:47:05 mysql-n2 Keepalived_healthcheckers: SMTP alert successfully sent.
Aug  8 14:47:06 mysql-n2 Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
Aug  8 14:47:06 mysql-n2 Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
Aug  8 14:47:06 mysql-n2 Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 10.0.17.158
Aug  8 14:47:06 mysql-n2 Keepalived_vrrp: Netlink reflector reports IP 10.0.17.158 added
Aug  8 14:47:06 mysql-n2 Keepalived_healthcheckers: Netlink reflector reports IP 10.0.17.158 added
Aug  8 14:47:06 mysql-n2 avahi-daemon[3052]: Registering new address record for 10.0.17.158 on eth0.
Aug  8 14:47:11 mysql-n2 Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 10.0.17.158
Aug  8 14:47:31 mysql-n2 avahi-daemon[3052]: Invalid query packet.

[root@mysql-n2 ~]# ip a
1: lo: 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 10.0.17.158/32 brd 10.0.17.158 scope global lo:0
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0c:29:ed:e8:c6 brd ff:ff:ff:ff:ff:ff
    inet 10.0.17.154/22 brd 10.0.19.255 scope global eth0
    inet 10.0.17.158/32 scope global eth0
    inet6 fe80::20c:29ff:feed:e8c6/64 scope link
       valid_lft forever preferred_lft forever
3: sit0: mtu 1480 qdisc noop
    link/sit 0.0.0.0 brd 0.0.0.0



LVS+keepalived成功安装后,开始配置mysql的双主。

第一步:安装mysql5.5  http://blog.chinaunix.net/uid-26446098-id-3261946.html
第二步:配置mysql双主 http://blog.chinaunix.net/uid-26446098-id-3267556.html

配置完之后,插入几条数据。
让第一台宕机,看看ip是否漂移,如成功,则安装成功。



阅读(4960) | 评论(1) | 转发(2) |
给主人留下些什么吧!~~