######heartbeat#####
开源软件,一种高可用集群
安装包heartbeat-3.0.4-2.el6.x86_64.rpm
heartbeat-devel-3.0.4-2.el6.x86_64.rpm
heartbeat-libs-3.0.4-2.el6.x86_64.rpm
ldirectord-3.9.5-3.1.x86_64.rpm
##安装
heartbeat可识别脚本的位置
/etc/ha.d/resourcd.d/
/etc/init.d/
/etc/rc.d/
在server1和server4上做以下配置
yum install heartbeat-* -y ##安装软件
cd /usr/share/doc/heartbeat-3.0.4/
cp ha.cf authkeys haresources /etc/ha.d/
cd /etc/ha.d
vim ha.cf ##配置文件
48 keepalive 2 ##心跳频率
56 deadtime 30 ##死亡时间
61 warntime 10 ##警告时间
71 initdead 60 ##启动时间
76 udpport 727 ##udp端口
91 bcast eth0 # Linux,单播接口
157 auto_failback on
211 node server1 ##节点名
212 node server4
220 ping 172.25.33.250 ##连接节点
253 respawn hacluster /usr/lib64/heartbeat/ipfail
259 apiauth ipfail gid=haclient uid=hacluster ##认证身份
vim /etc/ha.d/authkeys ##认证文件
auth 1 ##认证方式选择
1 crc
chmod 600 authkeys ##更改认证服务权限
vim /etc/ha.d/haresources
/etc/init.d/httpd start ##开启服务
/etc/init.d/heartbeat start ##开启heartbeat
#########lvs负载均衡
server1上yum install ldirectord-3.9.5-3.1.x86_64.rpm -y
cd /usr/share/doc/ldirectord-3.9.5/
cp ldirectord.cf /etc/ha.d/
yum install -y ipvsadm ##添加静态策略,没有健康检查
ipvsadm -L ##列出所有策略
ipvsadm -C ##刷新策略
ip addr add 172.25.33.100/24 dev eth0 ##添加虚拟ip
ipvsadm -A -t 172.25.33.100:80 -s rr ##-A添加虚拟设备,-t服务地址,-s调度程序,rr轮询
ipvsadm -a -t 172.25.33.100:80 -r 172.25.33.2:80 -g ##-a添加真实设备 ,-r真实设备地址ip
ipvsadm -a -t 172.25.33.100:80 -r 172.25.33.3:80 -g
/etc/init.d/ipvsadm save
ipvsadm -l
######server2,server3上
yum install arptables_jf -y
ip addr add 172.25.33.100/32 dev eth0 ##添加虚拟地址
arptables -A IN -s 172.25.33.100 -j DROP
arptables -A OUT -s 172.25.33.100 -j mangle --mangle-ip-s 172.25.33.2
/etc/init.d/arptables_jf save ##将配置保存
/etc/init.d/httpd start
###heartbeat+lvs
server1和server4上做yum install ldirectord-3.9.5-3.1.x86_64.rpm -y ##有健康检查,动态更新调度策略
cd /usr/share/doc/ldirectord-3.9.5/
cp ldirectord.cf /etc/ha.d/
ipvsadm -C ##刷新策略
ip addr del 172.25.33.100/24 dev eth0 ##删除虚拟ip
vim /etc/ha.d/ldirectord.cf
vim haresources
测试:
/etc/init.d/heartbeat start
ipvsadm -l ##查看策略
网页输入:172.25.33.100 ##查看网页结果,server2,server3页面轮询
#######keepalived
在server1和server4上均做以下操作chkconfig heartbeat off ##关闭开机自启
tar zxf keepalived-1.3.5.tar.gz
cd keepalived-1.3.5
./configure --prefix=/usr/local/keepalived --with-init=SYSV
###依赖性
yum install gcc -y
yum install openssl-devel -y
######
make && make install ##编译和安装
ln -s /usr/local/keepalived/sbin/keepalived /sbin/
ln -s /usr/local/keepalived/etc/keepalived/ /etc/
ln -s /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
chmod +x /usr/local/keepalived/etc/rc.d/init.d/keepalived ##加可执行权限
vim /etc/keepalived/keepalived.conf ##更改配置文件
1 ! Configuration File for keepalived
2
3 global_defs {
4 notification_email {
5 root@localhost
6 }
7 notification_email_from keepalived@server1
8 smtp_server 127.0.0.1
9 smtp_connect_timeout 30
10 router_id LVS_DEVEL
11 vrrp_skip_check_adv_addr
12 vrrp_strict
13 vrrp_garp_interval 0
14 vrrp_gna_interval 0
15 }
16
17 vrrp_instance VI_1 {
18 state MASTER ##server4上改为state BAKEUP
19 interface eth0
20 virtual_router_id 84
21 priority 100 ##优先级改小
22 advert_int 1
23 authentication {
24 auth_type PASS
25 auth_pass 1111
26 }
27 virtual_ipaddress {
28 172.25.33.100
29 }
30 }
31
32 virtual_server 172.25.33.100 80 {
33 delay_loop 6
34 lb_algo rr
35 lb_kind DR
36 #persistence_timeout 50
37 protocol TCP
38
39 real_server 172.25.33.2 80 {
40 weight 1
41 TCP_CHECK {
42 connect_timeout 3
43 nb_get_retry 3
44 delay_before_retry 3
45 }
46 }
47 real_server 172.25.33.3 80 {
48 weight 1
49 TCP_CHECK {
50 connect_timeout 3
51 nb_get_retry 3
52 delay_before_retry 3
53 }
54 }
55 }
测试:
/etc/init.d/keepalived start
iptables -F ##清空防火墙策略
ipvsadm -l ##查看策略
网页输入:172.25.33.100 ##查看网页结果server2,server3页面轮询
###########添加ftp服务#####
vim /usr/local/keepalived/etc/keepalived/keepalived.conf
virtual_server 172.25.33.100 21 {
delay_loop 6
lb_algo rr
lb_kind DR
persistence_timeout 50
protocol TCP
real_server 172.25.33.2 21 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 172.25.33.3 21 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
/etc/init.d/keepalived reload