公司社交網站上線後,上級領導對網站運維要求進一步提升,但願公司網站的可靠性與性能一併提升,要求使用keepalived對Nginx服務器作熱備,VIP地址採用192.168.43.10。對Nginx服務器進行性能調優。c++
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 //開機自啓動
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看不到//
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頁面vim