Haproxy部署
1. 安装haproxy
使用命令安装haproxy
yum install -y haproxy |
2. Haproxy配置
修改haproxy配置文件/etc/haproxy/haproxy.cfg参考配置文件haproxy.cfg
#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
frontend main *:5000
mode http
acl url_static hdr(host) -i ecstest.com
use_backend static if url_static
default_backend static#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
balance roundrobin
server static 172.16.3.99:9020 check
3. 启动haproxy
启动命令:
haproxy -f /etc/haproxy/haproxy.cfg |
Keepalived 部署
1.安装keepalived
使用命令安装keepalived 工具
yum install -y keepalived |
2. 配置keepalived
修改keepalived主节点上的keepalived配置文件/etc/keepalived/keepalived.conf 参考keepalived-master.conf,如:
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id node1
# vrrp_skip_check_adv_addr
#vrrp_strict
#vrrp_garp_interval 0
#vrrp_gna_interval 0
script_user root
enable_script_security
}vrrp_script chkhaproxy {
script "/usr/bin/killall -0 djygw"
interval 2
weight -5
fall 1
rise 1
user root
}vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 101
unicast_src_ip 172.16.3.141
unicast_peer {
172.16.3.53
}
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.16.3.133
}track_script {
chkhaproxy
}
#nopreempt
#preempt_delay 2
}
修改keepalived backup节点上的keepalived配置文件/etc/keepalived/keepalived.conf 参考keepalived-backup.conf.
! Configuration File for keepalived
global_defs {
notification_email {
acassen@firewall.loc
failover@firewall.loc
sysadmin@firewall.loc
}
notification_email_from Alexandre.Cassen@firewall.loc
#smtp_server 192.168.200.1
#smtp_connect_timeout 30
router_id node1
# vrrp_skip_check_adv_addr
#vrrp_strict
#vrrp_garp_interval 0
#vrrp_gna_interval 0
script_user root
enable_script_security
}vrrp_script chk_haproxy {
script "/usr/bin/killall -0 djygw"
interval 2
weight -2
fall 3
rise 1
}vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 99
unicast_src_ip 172.16.3.53
unicast_peer {
172.16.3.141
}
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.16.3.133
}
track_script {
chk_haproxy
}
#nopreempt
#preempt_delay 2
}
主节点172.16.3.141上添加防火墙配置
Iptables -A INPUT -i eth0 -p vrrp -s 172.16.3.53 -j ACCEPT |
在backup 172.16.3.53上添加防火墙配置
Iptables -A INPUT -i eth0 -p vrrp -s 172.16.3.141 -j ACCEPT |
3. 启动keepalived
使用命令启动keepalived
systemctl restart keepalived |
Keepalived版本更新
解压keepalived-2.2.7.tar.gz安装包,使用下列命令更新keepalived
tar -zxvf keepalived-2.2.7.tar.gz Cd keepalived-2.2.7 ./configure Make Make install |