不廢話,直接上搭建過程和配置。java
操做系統:CentOS 6.5nginx
nginx版本:nginx-1.9.9 (下載地址: http://sysoev.ru/nginx/)web
keepalived:keepalived-1.2.19 (下載地址: http://www.keepalived.org/software/)vim
#添加運行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
注意:nginx的配置請看 http://my.oschina.net/sanping/blog/635989spa
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/
#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地址 } }