1
|
# yum install ipvsadm
|
Keepalived :
1. get keepalived.
1
|
# wget http://www.keepalived.org/software/keepalived-1.2.12.tar.gz
|
2.解压keepalived.
1
|
# tar xzvf keepalived-1.2.12.tar.gz
|
3. 进入目录
1
|
# cd keepalived-1.2.12
|
4. 安装包.
1
|
# yum install openssl-devel.x86_64 kernel-headers kernel-devel
|
5. 配置keepalived.
1
|
#./configure
|
6. 编译.
1
|
# make
|
7. 编译安装.
1
|
# make install
|
8.自启动服务.
1
2
3
4
5
6
7
8
9
|
# cd /etc/sysconfig
# ln -s /usr/local/etc/sysconfig/keepalived .
# cd /etc/rc3.d/
# ln -s /usr/local/etc/rc.d/init.d/keepalived S100keepalived
# cd /etc/init.d/
# ln -s /usr/local/etc/rc.d/init.d/keepalived
# ln -s /usr/local/sbin/keepalived /usr/sbin/
# cd /etc/keepalived
# ln -s /usr/local/etc/keepalived/keepalived.conf .
|
keepalived.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
! Configuration File
for
keepalived
global_defs {
router_id MYSQLD
}
vrrp_instance MYSQLD_3306 {
state MASTER
interface em2
virtual_router_id 22
priority 101
advert_int 1
mcast_src_ip 192.168.253.9
authentication {
auth_type PASS
auth_pass lekan
}
virtual_ipaddress {
192.168.253.100
/24
dev em2 scope global
}
notify_master
"/etc/keepalived/notification_email.sh master"
notify_backup
"/etc/keepalived/notification_email.sh backup"
}
virtual_server 192.168.253.100 3306 {
delay_loop 2
lb_algo rr
lb_kind DR
persistence_timeout 10
protocol TCP
real_server 192.168.253.6 3306 {
weight 1
inhibit_on_failure
notify_up
"/etc/keepalived/mysql.sh up"
notify_down
"/etc/keepalived/mysql.sh down"
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
real_server 192.168.253.8 3306 {
weight 1
inhibit_on_failure
notify_down
"/etc/keepalived/mysql.sh down"
notify_up
"/etc/keepalived/mysql.sh up"
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
connect_port 3306
}
}
}
|
mysql.sh
1
2
3
4
5
6
7
8
9
10
11
12
|
#!/bin/bash
case
$1
in
up)
echo
"mysqld up"
| mutt -s
"keepalived mysqld"
tong.li@mail.lekan.com
;;
down)
echo
"mysqld down"
| mutt -s
"keepalived mysqld"
tong.li@mail.lekan.com
;;
*)
echo
"keepalived"
>>
/home/tong
.li
/keepalived
.txt
;;
esac
|
notification_email.sh
1
2
3
4
5
6
7
8
9
10
11
12
|
#!/bin/bash
case
$1
in
master)
echo
"keepalived master failover"
| mutt -s
"keepalived"
tong.li@mail.lekan.com
;;
backup)
echo
"keepalived backup failover"
| mutt -s
"keepalived"
tong.li@mail.lekan.com
;;
*)
echo
"keepalived"
>>
/home/tong
.li
/keepalived
.txt
;;
esac
|
realserver.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#!/bin/bash
#description:start realserver
VIP=192.168.253.100
.
/etc/rc
.d
/init
.d
/functions
case
"$1"
in
start)
/sbin/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
"start LVS of RealServer DR"
;;
stop)
/sbin/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
"close LVS of RealServer DR"
;;
*)
echo
"Usage:$0 {start|stop}"
exit
1
;;
esac
|
本文转自 Art_Hero 51CTO博客,原文链接:http://blog.51cto.com/curran/1387497,如需转载请自行联系原作者