centos6.5实现LVS+Keepalived双主热备
拓扑1、 基本配置根据拓扑配置IP2、 调度器配置-安装ipvsadm,并启用ip_vs模块
1
2
3
# yum -y install ipvsadm
# modprobe ip_vs
# echo "modproce ip_vs" >>/etc/rc.local
-修改内核参数
1
2
3
4
# sysctl –p
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.eth0.send_redirects = 0
-安装keepalived,并修改配置文件--安装
1
2
3
4
# cd /usr/src/
# tar zxfkeepalived-1.2.13.tar.gz
# cd keepalived-1.2.13
#./configure --prefix=/--with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/ && make&& make install
--修改配置文件-全局配置
1
2
3
4
5
6
7
8
9
10
11
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_DEVEL_1 #调度器名称
}
--修改配置文件-热备配置
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
vrrp_instance VI_1 { #热备组1
state MASTER #热备状态
interface eth0
virtual_router_id 51
priority 100 #优先级
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.11 #群集VIP地址
}
}
vrrp_instance VI_2 { #热备组2
state BACKUP
interface eth0
virtual_router_id 52
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.22
}
}
--修改配置文件-web服务器配置
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
irtual_server 192.168.1.11 80 { #虚拟服务器地址(VIP),端口’
delay_loop 6 #健康检查时间间隔(s)
lb_algo rr #调度算法-轮询
lb_kind DR #集群工作模式
!persistence_timeout 50 #连接保持时间(s),去掉!启用
protocol TCP #应用服务采用的是TCP协议
real_server 192.168.1.2 80 { #第一个web节点的地址,端口
weight 1 #节点的权重
TCP_CHECK { #健康检查方式
connect_timeout 3 #连接超时
nb_get_retry 3 #重试次数
delay_before_retry 3 #重试间隔
}
}
real_server 192.168.1.3 80 { #第二个web节点的地址,端口
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
virtual_server 192.168.1.22 80 {
delay_loop 6
lb_algo rr
lb_kind DR
!persistence_timeout 50
protocol TCP
real_server 192.168.1.2 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.3 80 {
weight 1
TCP_CHECK {
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
--重启服务
1
service keepalived restart
--同理配置另一调度器3、 节点服务器配置-修改内核参数
1
2
3
4
5
6
7
# sysctl–p
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2
net.ipv4.conf.default.arp_ignore = 1
net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.default.arp_announce = 2
net.ipv4.conf.lo.arp_announce = 2
-配置lo:0,lo:1虚接口
1
2
3
4
5
6
7
8
9
10
# cat/etc/sysconfig/network-scripts/ifcfg-lo:0
DEVICE=lo:0
ONBOOT=yes
IPADDR=192.168.1.11
NETMASK=255.255.255.255
# cat/etc/sysconfig/network-scripts/ifcfg-lo:1
DEVICE=lo:1
ONBOOT=yes
IPADDR=192.168.1.22
NETMASK=255.255.255.255
-添加本地路由
1
2
3
4
# route add -host192.168.1.11 dev lo:0
# route add -host192.168.1.22 dev lo:1
# echo "route add-host 192.168.1.11 dev lo:0" >> /etc/rc.local
# echo "route add-host 192.168.1.22 dev lo:1" >> /etc/rc.local
-启动web服务
4、 NFS配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# cat /etc/exports
/var/www/html 192.168.2.0/24(rw,sync,no_root_squash)
# service rpcbindrestart
停止 rpcbind: [确定]
正在启动 rpcbind: [确定]
# service nfs restart
关闭 NFS 守护进程: [失败]
关闭 NFS mountd: [失败]
关闭 NFS quotas: [失败]
Shutting down RPC idmapd: [失败]
启动 NFS 服务: [确定]
关掉 NFS 配额: [确定]
启动 NFS mountd: [确定]
启动 NFS 守护进程: [确定]
正在启动 RPC idmapd: [确定]
# showmount -e192.168.2.1
Export list for 192.168.2.1:
/var/www/html 192.168.2.0/24
# mount192.168.2.1:/var/www/html/ /var/www/html/
5、 内部服务器发布—NAT服务配置防火墙代替路由器测试
Eth0配置两个ip
1
2
3
4
5
6
7
8
9
10
# catifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:D5:AD:1B
TYPE=Ethernet
UUID=d3db1bd9-b0f5-4cc2-a5bb-3f0c28430ee0
ONBOOT=yes
IPADDR0=200.0.0.11
NETMASK=255.255.255.0
IPADDR1=200.0.0.22
NETMASK=255.255.255.0
--NAT
1
2
# iptables -t nat -APREROUTING -i eth0 -d 200.0.0.11 -p tcp --dport 80 -j DNAT --to 192.168.1.11
# iptables -t nat -APREROUTING -i eth0 -d 200.0.0.22 -p tcp --dport 80 -j DNAT --to 192.168.1.22
附:DNS配置
1
2
3
4
5
6
7
8
9
10
11
12
# cat /var/named/abc.com
$TTL 1D
@ INSOA @ rname.invalid. (
0 ; serial
1D ; refresh
1H ; retry
1W; expire
3H) ; minimum
in ns dns
dns in a 200.0.0.2
www in a 200.0.0.11
in a 200.0.0.22
--启动nfs前
页:
[1]