案例扩展
公司社交网站上线后,上级领导对网站运维要求进一步提高,希望公司网站的可靠性与性能一并提高,要求使用keepalived对Nginx服务器做热备,VIP地址采用192.168.43.10。对Nginx服务器进行性能调优。
keepalived双机热备
1、增加一台服务器搭建Nginx做热备
2、两台Nginx服务器安装keepalived
yum -y install popt-devel kernel-devel openssl-devel gcc gcc-c++ //安装依赖包环境包
tar zxvf keepalived-1.2.13.tar.gz -C /opt
cd /opt/keepalived-1.2.13
./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.e16x86_64
make && maek install
chkconfig --add keepalived //加入到service管理器
chkconfig keepalived on //开机自启动
3、主Nginx服务器配置
cd /etc/keepalived/
cp keepalived.conf keepalived.conf.bak
vim keepalived.conf
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_01 //修改服务器名称//
}
vrrp_instance VI_1 {
state MASTER //主服务器类型//
interface ens33
virtual_router_id 10 //VRRP组号//
priority 100 //优先级,备份Nginx服务器低于主//
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.43.10 //VIP//
}
}
service keepalived start //开启keepalived
ip addr show dev eth0 //可查看VIP,ipconfig看不到//
4、备Nginx服务器配置
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_02 //修改服务器名称//
}
vrrp_instance VI_1 {
state BACKUP //修改服务器类型//
interface ens33
virtual_router_id 10
priority 99 //修改优先级//
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.43.10 //VIP
}
}
service keepalived start //开启keepalived
ip addr show dev eth0 //可查看VIP,ipconfig看不到//
可用VIP地址测试访问PHP页面
Nginx服务器优化
参考博客:http://blog.51cto.com/13660858/2129990