共计 4803 个字符,预计需要花费 13 分钟才能阅读完成。
目前项目已经采用 nginx 来实现负载均衡,但是 nginx 调度器只有一台,上次还意外的 down 机一次,导致整个服务应用全部瘫痪,这次准备再加一个调度器来实现站点高可用性,也就是常说的双机热备了。
master: 192.168.1.241
backup: 192.168.1.242
漂移 IP:192.168.1.243
1,主备调度器都安装 keepalived 软件
安装过程如下:
./configure –prefix=/usr/local/keepalived && make && make install
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
service keepalived start
可以先用命令 service keepalived start 启动进行测试,看进程能够启动,注意查看 log.
2,主调度器配置如下:
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_sync_group VG_1 {
group {
VI_1
}
notify_master /etc/keepalived/sendmail.pl
}
vrrp_instance VI_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.243
}
}
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
2,备调度器配置如下:
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_sync_group VG_1 {
group {
VI_1
}
notify_master /etc/keepalived/sendmail.pl
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.243
}
}
更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2014-07/104384p2.htm
3,发送邮件的 perl 脚本 sendmail.pl 内容如下:
注意主备发送邮件的标题是不一致的,只要你能识别漂移 IP 在哪台服务器上即可。
#!/usr/bin/perl -w
use Net::SMTP_auth;
use strict;
my $mailhost = ‘smtp.163.com’;
my $mailfrom = ‘test@163.com’;
my @mailto = (‘123456@139.com’);
my $subject = ‘keepalived up on backup’;
my $text = “ 正文 \n 第二行位于此。”;
my $user = ‘test@163.com’;
my $passwd = ‘xxxxxxx’;
&SendMail();
##############################
# Send notice mail
##############################
sub SendMail() {
my $smtp = Net::SMTP_auth->new($mailhost, Timeout => 120, Debug => 1)
or die “Error.\n”;
$smtp->auth(‘LOGIN’, $user, $passwd);
foreach my $mailto (@mailto) {
$smtp->mail($mailfrom);
$smtp->to($mailto);
$smtp->data();
$smtp->datasend(“To: $mailto\n”);
$smtp->datasend(“From:$mailfrom\n”);
$smtp->datasend(“Subject: $subject\n”);
$smtp->datasend(“\n”);
$smtp->datasend(“$text\n\n”);
$smtp->dataend();
}
$smtp->quit;
}
说明:
a、由于 keeplived 自带的发送邮件机制是个鸡肋,如果本地不启动 25 端口就无法实现邮件发送,就琢磨着能不能通过自定义脚本来实现,真的是很幸运,就采用了认证的方式。
b、其他的配置说明就不详细讲了,网上很多资料。
4,测试 keepalived
主备调度器都开启 80 端口,两台服务器上的测试内容不一致,这样更方便测试。
##########################
# 所需安装模块
#use Net::SMTP
#Authen::SASL
##########################
#$stmp->auth(‘user’,’pass’);
# 大部分 SMTP 服务器为了防止 spam / 垃圾邮件,就需要用户验证身份。
# 此方法需要另外安装模块:Authen::SASL, 此模块可能系统不自带
##########################
#Debug => 1
# 此段代码用于测试之用,所以开启了 Debug,一般测试一次完毕,正式使用的话会关闭它。
注:可在命令行界面直接执行:/etc/keepalived/sendmail.pl,看看能否发送邮件成功,如果失败的话则需要安装 Net::SMTP_auth 模块
安装方法:
yum -y install perl-CPAN
cpan Net::SMTP_auth
Keepalived 的详细介绍:请点这里
Keepalived 的下载地址:请点这里
目前项目已经采用 nginx 来实现负载均衡,但是 nginx 调度器只有一台,上次还意外的 down 机一次,导致整个服务应用全部瘫痪,这次准备再加一个调度器来实现站点高可用性,也就是常说的双机热备了。
master: 192.168.1.241
backup: 192.168.1.242
漂移 IP:192.168.1.243
1,主备调度器都安装 keepalived 软件
安装过程如下:
./configure –prefix=/usr/local/keepalived && make && make install
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
service keepalived start
可以先用命令 service keepalived start 启动进行测试,看进程能够启动,注意查看 log.
2,主调度器配置如下:
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_sync_group VG_1 {
group {
VI_1
}
notify_master /etc/keepalived/sendmail.pl
}
vrrp_instance VI_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.243
}
}
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
2,备调度器配置如下:
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_sync_group VG_1 {
group {
VI_1
}
notify_master /etc/keepalived/sendmail.pl
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.1.243
}
}
更多详情见请继续阅读下一页的精彩内容:http://www.linuxidc.com/Linux/2014-07/104384p2.htm