阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

Keepalived-1.2.9集群的安装及配置

238次阅读
没有评论

共计 5896 个字符,预计需要花费 15 分钟才能阅读完成。

说明:
一、目 的:本文实现的 Linux 集群是基于 Keepalived-1.2.9 软件实现,
二、难 点:实现虚拟 IP(VIP)自动切换的同时,还要同时实现虚拟 MAC 地址(VMAC)的切换,即无论集群中的 Host 如何切换,对外访问的 IP 和 MAC 始终不变
三、适用环境:当对外路由或交换机绑定主机 MAC 时适用
四、说 明:若无须对外绑定 MAC 地址,则大可简化如下配置

1. 环境及软件:
1) 系统:Debian6 amd64
2) 内核:linux 3.2.0-0.bpo.4-amd64
3) 软件:keepalived-1.2.9

2. 配置:
MASTER 设备 IP:eth0: 10.10.1.200/24 eth1:192.168.61.253/21
BACKUP 设备 IP:eth0: 10.10.1.100/24 eth1:192.168.61.252/21
VIP:192.168.61.248/21

3. 安装步骤:
1)升级当前 Debian 系统内核 linux 2.6.32
a) 修改 Debian 源文件 /etc/apt/sources.list,添加一个向后兼容的源(源地址如下)
deb http://ftp.cn.debian.org/debian-backports squeeze-backports main

b) 更新 Debian 源文件关联并升级系统内核至 3.2.0
# aptitude update
# aptitude -t squeeze-backports install linux 3.2.0-0.bpo.4-amd64
如果编译 NVDIA 的官方驱动的话,还要装:

# aptitude -t squeeze-backports install linux-headers-3.2.0.bpo.4-amd64

 

2) 安装 keepalived-1.2.9
a) 首先要安装 keepalived 所依赖的组件
# aptitude install make gcc libpopt-dev libnl-dev libcurl4-openssl-dev

 

b) 将 keepalived-1.2.9.tar.gz 文件拷贝到 /usr/local/soft 下,解压,编译并安装到 /usr/local/keepalived

# mkdir /usr/local/soft
通过 ftp 将文件拷贝至 /usr/local/soft
# cd /usr/local/soft
# tar zxvf keepalived-1.2.9.tar.gz
# cd keepalived-1.2.9
# ./configure –prefix=/usr/local/keepalived
# make && make install

 

c) 重置 keepalived 相关文件,以便开机自动启动

# cp /usr/local/keepalived/sbin/keepalived /usr/sbin
# mkdir /etc/sysconfig
# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig
# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
d) 修改 keepalived 启动脚本
# nano /etc/init.d/keepalived
修改 /etc/init.d/keepalived 文件,部分片段如下(蓝色标记为注释内容,红色标记为修改内容):
……
#. /etc/rc.d/init.d/functions
. /lib/lsb/init-functions
# Source configuration file (we set KEEPALIVED_OPTIONS there)
. /etc/sysconfig/keepalived
RETVAL=0
prog=”keepalived”
start() {
echo -n $”Starting $prog: “
# keepalived ${KEEPALIVED_OPTIONS}
keepalived -D
RETVAL=$?
echo
[$RETVAL -eq 0] && touch /var/lock/$prog
}
stop() {
echo -n $”Stopping $prog: “
killproc keepalived
RETVAL=$?
echo
[$RETVAL -eq 0] && rm -f /var/lock/$prog
}
……
condrestart)
if [-f /var/lock/$prog ]; then
stop
start
fi
;;
……

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2013-11/92678p2.htm

Keepalived 的详细介绍:请点这里
Keepalived 的下载地址:请点这里

推荐阅读:

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

e) 网卡配置参数
修改文件 /etc/sysctl.conf,添加如下内容:
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 1
net.ipv4.conf.all.arp_filter = 0
net.ipv4.conf.eth0.arp_filter = 1
f) 在 /etc/keepalived 下创建 keepalived 配置文件 keepalived.conf
# mkdir /etc/keepalived
# nano /etc/keepalived/keepalived.conf
global_defs {
notification_email {
tiddy@example.com
}
notification_email_from keepalived@example.com
smtp_server 192.168.1.5
smtp_connect_timeout 30
router_id LVS_DEVEL_11 #与 backup 配置不相同的任意合法字符串
}

vrrp_instance VI_1 {
state MASTER #backup 机器配置为 BACKUP
interface eth1 #绑定的网卡名称
virtual_router_id 250 #必须与 backup 机器配置相同
use_vmac #名字可为任意合法字符串(默认字符串 vrrp.${virtual_router_id} 此处默认使用 vrrp.250)
priority 200 #优先级,要比 backup 机器高至少 50
advert_int 1
authentication {
auth_type PASS #授权类型,必须与 backup 相同
auth_pass 1111 #授权密码,必须与 backup 相同
}
virtual_ipaddress {
192.168.61.249/21 #虚拟 ip 地址,必须与 backup 相同
}
notify_master /usr/local/keepalived/script/vmac_tweak.sh
}
e)创建脚本
脚本 /usr/local/keepalived/script/vmac_tweak.sh
# mkdir /usr/local/keepalived/script
# touch /usr/local/keepalived/script/vmac_tweak.sh
脚本内容如下:
#!/bin/bash
echo “0” > /proc/sys/net/ipv4/conf/uvmac/arp_filter
echo “1” > /proc/sys/net/ipv4/conf/uvmac/accept_local
3) 启动 keepalived
# invoke-rc.d keepalived start
4) 测试 keepalived
a) MASTER 启动时,查看日志 /var/log/messages,显示 keepalived 进入 MASTER 状态同理,BACKUP 机器将进入 BACKUP 状态
b) 当 MASTER 机器 down 掉时,查看 BACKUP 机器日志,显示 keepalived 进入 MASTER,当 MASTER 重新启动时,MASTER 机器进入 MASTER 状态而 BACKUP 机器 keepalived 重新进入 BACKUP 状态,此时表示 keepalived 安装测试已成功!

说明:
一、目 的:本文实现的 Linux 集群是基于 Keepalived-1.2.9 软件实现,
二、难 点:实现虚拟 IP(VIP)自动切换的同时,还要同时实现虚拟 MAC 地址(VMAC)的切换,即无论集群中的 Host 如何切换,对外访问的 IP 和 MAC 始终不变
三、适用环境:当对外路由或交换机绑定主机 MAC 时适用
四、说 明:若无须对外绑定 MAC 地址,则大可简化如下配置

1. 环境及软件:
1) 系统:Debian6 amd64
2) 内核:linux 3.2.0-0.bpo.4-amd64
3) 软件:keepalived-1.2.9

2. 配置:
MASTER 设备 IP:eth0: 10.10.1.200/24 eth1:192.168.61.253/21
BACKUP 设备 IP:eth0: 10.10.1.100/24 eth1:192.168.61.252/21
VIP:192.168.61.248/21

3. 安装步骤:
1)升级当前 Debian 系统内核 linux 2.6.32
a) 修改 Debian 源文件 /etc/apt/sources.list,添加一个向后兼容的源(源地址如下)
deb http://ftp.cn.debian.org/debian-backports squeeze-backports main

b) 更新 Debian 源文件关联并升级系统内核至 3.2.0
# aptitude update
# aptitude -t squeeze-backports install linux 3.2.0-0.bpo.4-amd64
如果编译 NVDIA 的官方驱动的话,还要装:

# aptitude -t squeeze-backports install linux-headers-3.2.0.bpo.4-amd64

 

2) 安装 keepalived-1.2.9
a) 首先要安装 keepalived 所依赖的组件
# aptitude install make gcc libpopt-dev libnl-dev libcurl4-openssl-dev

 

b) 将 keepalived-1.2.9.tar.gz 文件拷贝到 /usr/local/soft 下,解压,编译并安装到 /usr/local/keepalived

# mkdir /usr/local/soft
通过 ftp 将文件拷贝至 /usr/local/soft
# cd /usr/local/soft
# tar zxvf keepalived-1.2.9.tar.gz
# cd keepalived-1.2.9
# ./configure –prefix=/usr/local/keepalived
# make && make install

 

c) 重置 keepalived 相关文件,以便开机自动启动

# cp /usr/local/keepalived/sbin/keepalived /usr/sbin
# mkdir /etc/sysconfig
# cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig
# cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
d) 修改 keepalived 启动脚本
# nano /etc/init.d/keepalived
修改 /etc/init.d/keepalived 文件,部分片段如下(蓝色标记为注释内容,红色标记为修改内容):
……
#. /etc/rc.d/init.d/functions
. /lib/lsb/init-functions
# Source configuration file (we set KEEPALIVED_OPTIONS there)
. /etc/sysconfig/keepalived
RETVAL=0
prog=”keepalived”
start() {
echo -n $”Starting $prog: “
# keepalived ${KEEPALIVED_OPTIONS}
keepalived -D
RETVAL=$?
echo
[$RETVAL -eq 0] && touch /var/lock/$prog
}
stop() {
echo -n $”Stopping $prog: “
killproc keepalived
RETVAL=$?
echo
[$RETVAL -eq 0] && rm -f /var/lock/$prog
}
……
condrestart)
if [-f /var/lock/$prog ]; then
stop
start
fi
;;
……

更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2013-11/92678p2.htm

Keepalived 的详细介绍:请点这里
Keepalived 的下载地址:请点这里

推荐阅读:

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

正文完
星哥玩云-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计5896字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中