背景:
公司官网PV不高,压力不大,所以公司给出两台服务器来提供官网web服务,毕竟是公司门面,不能出现问题!所以就需要一个轻量级web容灾方案!
方案:
利用keepalived+nginx实现官网web的高可用性
两台服务器一台为主,一台为备机,使两台机器公用一个虚拟IP,当主服务器宕机,106.3.32.6这个IP会自动切换到备机上,前端机恢复之后再自动切换回主服务机
然后,主服务机和备机利用rsync实现实时同步数据,
rsync的安装配置可以参照我之前的一篇文章:
环境:
CentOS 6.4
nginx-1.2.1
keepalived-1.2.2
一、安装
主和辅都需要安装keepalived,安装方法相同
yum -y install kernel-devel
yum install openssl-* -y
wget
tar xzf keepalived-1.2.2.tar.gz
cd keepalived-1.2.2
./configure --prefix=/usr/local/keepalived
make && make install
ln -s /usr/src/kernels/2.6.18-238.el5-i686/ /usr/src/linux
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
mkdir -pv /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
ln -s /usr/local/keepalived/sbin/keepalived /sbin/
加入开机启动:chkconfigkeepalived on
二、配置
主和辅配置的差别只在stateMASTER和priority 100
vi /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
# notification_email { ####此处定义发生替换会邮件通知
# cuimingkun@yinwuweiye.com
# }
# notification_email_from keepalived@domain.com
# smtp_server 127.0.0.1
# smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_script chk_http_port {
script "/root/shell/nginx_pid.sh" ##监控脚本位置
interval 2
weight 2
}
track_script {
chk_http_port
}
vrrp_instance VI_1 {
state MASTER #####备机为BACKUP
interface em1
virtual_router_id 51
priority 100 #####备机要小于主
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
106.3.32.6 ####虚拟IP
}
}
推荐阅读:
CentOS 6.2实战部署Nginx+MySQL+PHP
Ubuntu下安装Memcached及命令解释
搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程
CentOS 6.3下配置Nginx加载ngx_pagespeed模块
CentOS 6.4安装配置Nginx+Pcre+php-fpm
Nginx 的详细介绍:请点这里
Nginx 的下载地址:请点这里