共计 10474 个字符,预计需要花费 27 分钟才能阅读完成。
Keepalived 集群软件是一个基于 VRRP 协议来实现的 LVS(四层协议) 服务高可用方案, 可以利用避免单节点故障.LVS 服务需要有 2 台服务器运行 Keepalived 服务, 一台为主服务器 (MASTER), 一台为备份服务器 (BACKUP), 但是对外只有一个虚拟 IP, 主服务器会发送特定的消息给备份服务器, 当备份服务器收不到这个消息的时候, 备份服务器认为主服务器宕机并会接管虚拟 IP 提供服务, 从而保证了服务的高可用性。
CentOS 6.3 下 Haproxy+Keepalived+Apache 配置笔记 http://www.linuxidc.com/Linux/2013-06/85598.htm
Haproxy + KeepAlived 实现 WEB 群集 on CentOS 6 http://www.linuxidc.com/Linux/2012-03/55672.htm
Keepalived+Haproxy 配置高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/56748.htm
Haproxy+Keepalived 构建高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/55880.htm
CentOS 7 上配置 LVS + Keepalived + ipvsadm http://www.linuxidc.com/Linux/2014-11/109237.htm
Keepalived 高可用集群搭建 http://www.linuxidc.com/Linux/2014-09/106965.htm
1. 环境说明
系统:CentOS 6.5 64 位
软件:Keepalived ipvsadm
服务:apache
网络:
node1:192.168.1.100
node2:192.168.1.102
vip:192.168.1.105
2. 配置本地时间和网络
(1) 两台服务器时间必须一至
[root@node2 ~]# date – 节点 2 的时间
Thu Nov 13 15:11:09 CST 2014
[root@node2 ~]#
[root@node1 ~]# date – 节点 1 的时间
Thu Nov 13 15:11:13 CST 2014
[root@node1 ~]#
(2) 配置本地网络
node1 节点:
[root@node1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:EE:3D:F6
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
[root@node1 ~]# vim /etc/hosts – 两台服务器相互解析
192.168.1.100 node1
192.168.1.102 node2
[root@node1 ~]#
node2 节点:
[root@node2 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:A5:94:4C
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.102
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
[root@node2 ~]# vim /etc/hosts
192.168.1.100 node1
192.168.1.102 node2
[root@node2 ~]#
3. 安装所需要的软件包, 配置 httpd 服务
node1 节点:
[root@node1 ~]# yum install httpd keepalived ipvsadm -y – 安装所需的软件
[root@node1 ~]# vim /etc/httpd/conf/httpd.conf
ServerName 127.0.0.1
[root@node1 ~]# echo “node1” > /var/www/html/index.html – 定义 web 首页
[root@node1 ~]# /etc/init.d/httpd restart
Stopping httpd: [FAILED]
Starting httpd: [OK]
[root@node1 ~]# chkconfig httpd on – 重启 web 服务
[root@node1 ~]#
node2 节点:
[root@node2 ~]# yum install httpd keepalived ipvsadm -y
[root@node2 ~]# vim /etc/httpd/conf/httpd.conf
ServerName 127.0.0.1
[root@node2 ~]# echo “node2” > /var/www/html/index.html
[root@node2 ~]# /etc/init.d/httpd restart
Stopping httpd: [FAILED]
Starting httpd: [OK]
[root@node2 ~]# chkconfig httpd on
更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-11/109463p2.htm
4. 配置 keepalived 集群服务
node1 节点:
[root@node1 ~]# echo “1” > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@node1 ~]# echo “1” > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@node1 ~]# echo “2” > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@node1 ~]# echo “2” > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@node1 ~]# ifconfig eth0:1 192.168.1.105 broadcast 192.168.1.105 netmask 255.255.255.255 up
[root@node1 ~]# route add -host 192.168.1.105 dev eth0:1
[root@node1 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:EE:3D:F6
inet addr:192.168.1.100 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:feee:3df6/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1600615 errors:0 dropped:0 overruns:0 frame:0
TX packets:1574022 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:106099219 (101.1 MiB) TX bytes:102403193 (97.6 MiB)
eth0:1 Link encap:Ethernet HWaddr 08:00:27:EE:3D:F6
inet addr:192.168.1.105 Bcast:192.168.1.105 Mask:255.255.255.255
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:5087 errors:0 dropped:0 overruns:0 frame:0
TX packets:5087 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:403339 (393.8 KiB) TX bytes:403339 (393.8 KiB)
[root@node1 ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.1.105 0.0.0.0 255.255.255.255 UH 0 0 0 eth0
192.168.1.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 eth0
[root@node1 ~]# cd /etc/keepalived/
[root@node1 keepalived]# vim keepalived.conf – 配置 keepalived 文件
! Configuration File for keepalived
global_defs {
notification_email {
z597011036@qq.com – 宕机后邮件报警
}
notification_email_from root – 从哪个用户发出
smtp_server localhost – 邮件服务器
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER – 主节点
interface eth1 – 监听的网卡
virtual_router_id 51 – 虚拟路由 ID 号
priority 100 – 配置优先级
advert_int 1
authentication {
auth_type PASS – 认证类型
auth_pass keep – 认证密码
}
virtual_ipaddress {
192.168.1.105 – 虚拟 IP 地址
}
}
virtual_server 192.168.1.105 80 {– 虚拟 IP 和端口设置
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
protocol TCP
real_server 192.168.1.100 80 {– 主服务器的 IP 和端口
weight 1 – 权重
HTTP_GET {– 启用 HTTP 服务
url {
path /
status_code 200 – 监控状态码为 200, 如果返回不是 200 表示宕机
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.102 80 {– 从服务器的 IP 和端口
weight 1 – 权重
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
[root@node2 keepalived]#
node2 节点:
[root@node2 ~]# echo “1” > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@node2 ~]# echo “1” > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@node2 ~]# echo “2” > /proc/sys/net/ipv4/conf/all/arp_ignore
[root@node2 ~]# echo “2” > /proc/sys/net/ipv4/conf/lo/arp_ignore
[root@node2 ~]# ifconfig eth0:1 192.168.1.105 broadcast 192.168.1.105 netmask 255.255.255.255 up
[root@node2 ~]# route add -host 192.168.1.105 dev eth0:1
[root@node2 ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:A5:94:4C
inet addr:192.168.1.102 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fea5:944c/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1601817 errors:0 dropped:0 overruns:0 frame:0
TX packets:1574326 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:104324952 (99.4 MiB) TX bytes:104338539 (99.5 MiB)
eth0:1 Link encap:Ethernet HWaddr 08:00:27:A5:94:4C
inet addr:192.168.1.105 Bcast:192.168.1.105 Mask:255.255.255.255
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:6824 errors:0 dropped:0 overruns:0 frame:0
TX packets:6824 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:2407997 (2.2 MiB) TX bytes:2407997 (2.2 MiB)
[root@node2 ~]# cd /etc/keepalived/
[root@node2 keepalived]# vim keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
z597011036@qq.com
}
notification_email_from root
smtp_server localhost
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state BACKUP – 备用节点
interface eth1
virtual_router_id 51
priority 101
advert_int 1
authentication {
auth_type PASS
auth_pass keep
}
virtual_ipaddress {
192.168.1.105
}
}
virtual_server 192.168.1.105 80 {
delay_loop 6
lb_algo rr
lb_kind DR
nat_mask 255.255.255.0
protocol TCP
real_server 192.168.1.100 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
real_server 192.168.1.102 80 {
weight 1
HTTP_GET {
url {
path /
status_code 200
}
connect_timeout 3
nb_get_retry 3
delay_before_retry 3
}
}
}
[root@node2 keepalived]#
5. 启动 keepalived 服务和 ipvsadm 的状态
node1 和 node2 启动服务:
[root@node1 keepalived]# /etc/init.d/keepalived restart
Stopping keepalived: [OK]
Starting keepalived: [OK]
[root@node1 keepalived]#
[root@node2 ~]# /etc/init.d/keepalived restart
Stopping keepalived: [OK]
Starting keepalived: [OK]
[root@node2 ~]#
[root@node1 keepalived]# ipvsadm -L -n
IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
-> RemoteAddress:Port Forward Weight ActiveConn InActConn
TCP 192.168.1.105:80 rr
-> 192.168.1.100:80 Local 1 0 0
-> 192.168.1.102:80 Route 1 0 0
[root@node1 keepalived]#
6. 测试是否正常
Keepalived 的详细介绍 :请点这里
Keepalived 的下载地址 :请点这里
Keepalived 集群软件是一个基于 VRRP 协议来实现的 LVS(四层协议) 服务高可用方案, 可以利用避免单节点故障.LVS 服务需要有 2 台服务器运行 Keepalived 服务, 一台为主服务器 (MASTER), 一台为备份服务器 (BACKUP), 但是对外只有一个虚拟 IP, 主服务器会发送特定的消息给备份服务器, 当备份服务器收不到这个消息的时候, 备份服务器认为主服务器宕机并会接管虚拟 IP 提供服务, 从而保证了服务的高可用性。
CentOS 6.3 下 Haproxy+Keepalived+Apache 配置笔记 http://www.linuxidc.com/Linux/2013-06/85598.htm
Haproxy + KeepAlived 实现 WEB 群集 on CentOS 6 http://www.linuxidc.com/Linux/2012-03/55672.htm
Keepalived+Haproxy 配置高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/56748.htm
Haproxy+Keepalived 构建高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/55880.htm
CentOS 7 上配置 LVS + Keepalived + ipvsadm http://www.linuxidc.com/Linux/2014-11/109237.htm
Keepalived 高可用集群搭建 http://www.linuxidc.com/Linux/2014-09/106965.htm
1. 环境说明
系统:CentOS 6.5 64 位
软件:Keepalived ipvsadm
服务:apache
网络:
node1:192.168.1.100
node2:192.168.1.102
vip:192.168.1.105
2. 配置本地时间和网络
(1) 两台服务器时间必须一至
[root@node2 ~]# date – 节点 2 的时间
Thu Nov 13 15:11:09 CST 2014
[root@node2 ~]#
[root@node1 ~]# date – 节点 1 的时间
Thu Nov 13 15:11:13 CST 2014
[root@node1 ~]#
(2) 配置本地网络
node1 节点:
[root@node1 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:EE:3D:F6
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
[root@node1 ~]# vim /etc/hosts – 两台服务器相互解析
192.168.1.100 node1
192.168.1.102 node2
[root@node1 ~]#
node2 节点:
[root@node2 ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=08:00:27:A5:94:4C
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.1.102
NETMASK=255.255.255.0
GATEWAY=192.168.1.1
[root@node2 ~]# vim /etc/hosts
192.168.1.100 node1
192.168.1.102 node2
[root@node2 ~]#
3. 安装所需要的软件包, 配置 httpd 服务
node1 节点:
[root@node1 ~]# yum install httpd keepalived ipvsadm -y – 安装所需的软件
[root@node1 ~]# vim /etc/httpd/conf/httpd.conf
ServerName 127.0.0.1
[root@node1 ~]# echo “node1” > /var/www/html/index.html – 定义 web 首页
[root@node1 ~]# /etc/init.d/httpd restart
Stopping httpd: [FAILED]
Starting httpd: [OK]
[root@node1 ~]# chkconfig httpd on – 重启 web 服务
[root@node1 ~]#
node2 节点:
[root@node2 ~]# yum install httpd keepalived ipvsadm -y
[root@node2 ~]# vim /etc/httpd/conf/httpd.conf
ServerName 127.0.0.1
[root@node2 ~]# echo “node2” > /var/www/html/index.html
[root@node2 ~]# /etc/init.d/httpd restart
Stopping httpd: [FAILED]
Starting httpd: [OK]
[root@node2 ~]# chkconfig httpd on
更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-11/109463p2.htm