squid代理+ss5代理+keepalived模式之keepalived配置
阿新 • • 發佈:2018-11-01
1、下載原始碼包
cd /usr/local/src/ wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz
2、安裝環境依賴包
yum -y install kernel-devel gcc make openssl-devel popt-devel libnl-devel
3、解壓並編譯安裝keepalived服務
cd /usr/local/src/ tar xvf keepalived-1.2.7.tar.gz cd keepalived-1.2.7 ./configure --with-kernel-dir=/usr/src/kernels/2.6.32-71.el6.x86_64/ --prefix=/opt/keepalive make make install
4、配置執行環境
ln -s /opt/keepalive/etc/rc.d/init.d/keepalived /etc/init.d/ ln -s /opt/keepalive/etc/keepalived/ /etc/ ln -s /opt/keepalive/sbin/keepalived /usr/sbin/ ln -s /opt/keepalive/etc/sysconfig/keepalived /etc/sysconfig/ #設定開機自啟動 chkconfig keepalived --add chkconfig keepalived --list chkconfig keepalived on
5、修改keepalived配置
cd /etc/keepalived/ cp keepalived.conf keepalived.conf-bak >keepalived.conf cat >> keepalived.conf << eof ! Configuration File for keepalived global_defs { notification_email {[email protected] [email protected] [email protected] } #notification_email_from [email protected] #smtp_server 192.168.200.1 #smtp_connect_timeout 30 router_id LVS_DEVEL } #檢測本機埠是否正常 vrrp_script chk_squid_port { script "</dev/tcp/127.0.0.1/8080" interval 1 } vrrp_instance VI_1 { state MASTER #MASTER主 備 BACKUP interface eth0 virtual_router_id 51 #主備必須一致 priority 100 # 主為100 備用 90 主備不相同 主的值大於備用 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 10.205.103.33 #配置虛ip地址 } #如果埠不正常,則keepalived 切換到備用 track_script { chk_squid_port } } eof
6、啟動服務
service keepalived reload #修改keepalived.conf配置後重新載入 service keepalived start #啟動keepalived service keepalived restart service keepalived stop
7、防火牆設定
-A INPUT -i eth0 -p vrrp -s 10.205.103.170 -j ACCEPT -A INPUT -d 224.0.0.0/8 -i eth0 -p vrrp -j ACCEPT -A OUTPUT -d 224.0.0.0/8 -o eth0 -p vrrp -j ACCEPT -A INPUT -p vrrp -j ACCEPT
***以下配置為測試過的squid代理+ss5+keepalived模式之keepalived配置***
! Configuration File for keepalived global_defs { notification_email { [email protected] [email protected] [email protected] } #notification_email_from [email protected] #smtp_server 192.168.200.1 #smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_script chk_squid_port { script "</dev/tcp/127.0.0.1/8080" interval 1 } vrrp_script chk_ss5_port { script "</dev/tcp/127.0.0.1/1080" interval 1 } vrrp_instance VI_1 { state MASTER interface eth2 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.0.6/24 } track_script { chk_squid_port } } vrrp_instance VI_2 { state BACKUP interface eth2 virtual_router_id 151 priority 70 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.0.7/24 } track_script { chk_ss5_port } }