Keepalived高可用+HAproxy实现Nginx+wordpress动静分离
#配置Keepalived-主节点# vim /etc/keepalived/keepalived.conf
global_defs {
notification_email {
root
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id shiyan1
vrrp_mcast_group4 224.0.101.19
}
vrrp_instance HP-1 {
state MASTER #主节点
interface ens33 #网卡
virtual_router_id 11 #虚拟路由ID
priority 100 #优先级
advert_int 1
authentication {
auth_type PASS
auth_pass Naner2010@
}
virtual_ipaddress {
172.18.17.30/16 dev ens33#虚拟IP地址及绑定的网卡
}
}
#配置HAproxy
# vim /etc/haproxy/haproxy.cfg
frontendtianrandai*:80
acl url_static path_beg -i /static /images /javascript /stylesheets
#以/static /images ... 开头的
acl url_static path_end -i .jpg .gif .png .css .js .html
#或者以 .jpg .gif .png ...结尾的
use_backend static if url_static #调度到static中
default_backend doutai #不是则调度到doutai中
listen stat #管理页面
bind *:9909 #管理页面端口
stats enable #开启管理页面
stats uri /Randai?Tian #管理页面自定义URI
stats admin if TRUE #判断是否开启管理模式
stats auth TianRandai:abc123 #使用的用户名密码
#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
backend static
balance roundrobin 使用的算法
server static1 172.18.17.35:80 check 后端服务器IP
#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
backend doutai
balance roundrobin
serverdoutai1 172.18.17.33:80 check
#开启服务
# systemctl start haproxy
# systemctl start keepalived
页:
[1]