部署keepalived
yum install libnfnetlink-devel libnfnetlink ipvsadm libnl libnl-devel libnl3 libnl3-devel lm_sensors-libs net-snmp-agent-libs net-snmp-libs open server openssh-clients openssl openssl-devel automake iproute
cd keepalived-2.0.7 && ./configure --prefix=/usr/local/keepalived --disable-fwmark
make && amke install
mkdir /usr/local/keepalived/etc/sysconfig –p && cp keepalived/etc/init.d/keepalived.rh.init /usr/local/keepalived/etc/sysconfig/keepalived
cp keepalived/keepalived.service /usr/lib/systemd/system/
mkdir /usr/local/keepalived/sbin && cp bin/keepalived /usr/local/keepalived/sbin/keepalived
mkdir /etc/keepalived
vim /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 80
priority 100
advert_int 1
unicast_src_ip 192.168.7.103
unicast_peer {
192.167.7.104
}
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.7.100 dev eth0 label eth0:0
}
}
部署haproxy
tar xvf haproxy-1.8.13.tar.gz
cd haproxy-1.8.13
make ARCH=x86_64 TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 USE_SYSTEMD=1 USE_CPU_AFFINITY=1 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy
vim /usr/lib/systemd/system/haproxy.service
[Unit]
Description=HAProxy Load Balancer
After=syslog.target network.target
[Service]
支持多配置文件读取,类似于从侧面是实现配置文件的include功能。
ExecStartPre=/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/conf -c -q
ExecStart=/usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -f /etc/haproxy/conf -p /run/haproxy.pid
ExecReload=/bin/kill -USR2 $MAINPID
[Install]
WantedBy=multi-user.target