Skip to content

Nginx + Keepalived 双主热备

Published: at 00:00
说明
system: CentOS release 6.5 (Final)
linux kernel: 2.6.32-431.el6.x86_64

hostname: host-1, IP: 10.211.55.65 VIP: 10.211.55.67
hostname: host-2, IP: 10.211.55.66 VIP: 10.211.55.68
更新源
两台机器都需要更新源

yum install wget -y
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.163.com/.help/CentOS6-Base-163.repo
yum clean all
yum makecache
安装依赖
yum install gcc gcc-c++ make cmake ncurses-devel pcre-devel openssl-devel ipvsadm kernel-devel libnl-devel popt-devel -y
防火墙设置
iptables -I INPUT -p tcp --dport 80 -j ACCEPT
iptables -I INPUT -d 224.0.0.0/8 -j ACCEPT
iptables -I INPUT -p vrrp -j ACCEPT

service iptables save
service iptables restart
安装Nginx
两台机器都需要安装Nginx
安装Keepalived
两台机器都需要安装Keepalived
主服务器(10.211.55.65)配置keepalived
从服务器(10.211.55.66)配置keepalived
Keepalived操作
正常情况的IP显示
测试
ping 10.211.55.67

10.211.55.65这台机断网, 重启网络

ping 10.211.55.68

10.211.55.66这台机断网, 重启网络

Nginx的服务测试
打开 http://10.211.55.67

service nginx stop