不废话,直接上搭建过程和配置。
操作系统:CentOS 6.5
nginx版本:nginx-1.9.9 (下载地址: http://sysoev.ru/nginx/)
keepalived:keepalived-1.2.19 (下载地址: http://www.keepalived.org/software/)
一、安装nginx
#添加运行nginx的用户和组www
groupadd www
useradd -g www www
#下载pcre
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-x.x.tar.gz
tar zxvf pcre-7.8.tar.gz
cd pcre-7.8/
./configure
make && make install
#下载nginx
wget http://nginx.org/download/nginx-1.9.13.tar.gz
tar zxvf nginx-1.9.13.tar.gz
cd nginx-1.9.13/
./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module
make && make install
二、安装和配置keepalived
1、安装
wget http://www.keepalived.org/software/keepalived-1.2.19.tar.gz
#tar zxvf keepalived-1.2.19.tar.gz
#cd keepalived-1.2.19
#./configure --prefix=/usr/local/keepalived
#make && make install
#cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
#cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
#cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
#mkdir /etc/keepalived
#cd /etc/keepalived/
2、配置
#vim keepalived.conf
global_defs {
notification_email {
}
notification_email_from keepalived@chtopnet.com
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
mcast_src_ip 192.168.0.154 <==主nginx的IP地址
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass chtopnet
}
virtual_ipaddress {
192.168.0.188 <==vip地址
}
}