haproxy master1
vim /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local2 info
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
nbproc 1
defaults
mode http
log global
retries 3
option redispatch
maxconn 4000
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen stats
bind *:81
stats enable
stats uri /haproxy
stats auth qianfeng:123
frontend web
mode http
bind *:80
option httplog
acl html url_reg -i \.html$
use_backend httpservers if html
default_backend httpservers
backend httpservers
balance roundrobin
server http1 192.168.180.251:80 maxconn 2000 weight 1 check inter 1s rise 2 fall 2
server http2 192.168.180.252:80 maxconn 2000 weight 1 check inter 1s rise 2 fall 2
listen mysql
bind *:3307
mode tcp
balance roundrobin
server mysql1 192.168.180.253:3306 weight 1 check inter 1s rise 2 fall 2
server mysql2 192.168.180.100:3306 weight 1 check inter 1s rise 2 fall 2
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id director1
}
vrrp_script check_mysql {
script "/etc/keepalived/check_mysql_status.sh"
interval 5
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 80
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.180.222/24
}
track_script {
check_mysql
}
}
配置keepalived backup配置文件
vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id directory2
enable_script_security
}
vrrp_script check_mysql {
script "/etc/keepalived/check_mysql_status.sh"
interval 5
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
nopreempt
virtual_router_id 80
priority 50
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.180.222/24
}
track_script {
check_mysql
}
}
vim /etc /haproxy/haproxy.conf
global
log 127.0.0.1 local2 info
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
nbproc 1
defaults
mode http
log global
retries 3
option redispatch
maxconn 4000
contimeout 5000
clitimeout 50000
srvtimeout 50000
listen stats
bind *:81
stats enable
stats uri /haproxy
stats auth qianfeng:123
frontend web
mode http
bind *:80
option httplog
acl html url_reg -i \.html$
use_backend httpservers if html
default_backend httpservers
backend httpservers
balance roundrobin
server http1 192.168.180.251:80 maxconn 2000 weight 1 check inter 1s rise 2 fall 2
server http2 192.168.180.252:80 maxconn 2000 weight 1 check inter 1s rise 2 fall 2
listen mysql
bind *:3307
mode tcp
balance roundrobin
server mysql1 192.168.180.253:3306 weight 1 check inter 1s rise 2 fall 2
server mysql2 192.168.180.100:3306 weight 1 check inter 1s rise 2 fall 2