snow chuai汇总、整理、撰写---2020/2/2
1) 拓扑 |-------------| | Client | | node5 | |-------------| | | |-------------| | HA Proxy | | node1 | |-------------| | | |--------------| | |--------------| + WEB Server +--------------+ WEB Server + | node2 | | node3 | |--------------| |--------------| |
1) 配置HAProxy配置文件 [root@node1 ~]# mv /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.bak [root@node1 ~]# vim /etc/haproxy/haproxy.cfg global # 全局配置 log 127.0.0.1 local2 info # 定义收集的日志信息及日志设备 chroot /var/lib/haproxy pidfile /var/run/haproxy.pid maxconn 256 # 最大连接数 user haproxy # 定义haproxy的属主 group haproxy # 定义harpoxy属组 daemon |
1) 创建SSL证书 [root@node1 ~]# cd /etc/pki/tls/certs [root@node1 certs]# openssl req -x509 -nodes -newkey rsa:2048 -keyout \ /etc/pki/tls/certs/haproxy.pem -out /etc/pki/tls/certs/haproxy.pem \ -days 365 Generating a 2048 bit RSA private key .....................+++ .................................................................+++ writing new private key to '/etc/pki/tls/certs/haproxy.pem' ----- You are about to be asked to enter information that will be incorporated into your certificate request. What you are about to enter is what is called a Distinguished Name or a DN. There are quite a few fields but you can leave some blank For some fields there will be a default value, If you enter '.', the field will be left blank. ----- Country Name (2 letter code) [XX]:CN State or Province Name (full name) []:BeiJing Locality Name (eg, city) [Default City]:BeiJing Organization Name (eg, company) [Default Company Ltd]:1000cc Organizational Unit Name (eg, section) []:tech Common Name (eg, your name or your server's hostname) []:node1.1000cc.net Email Address []: |
4.1 HAProxy状态-WEB模式
1) 配置HAProxy配置文件 [root@node1 ~]# vim /etc/haproxy/haproxy.cfg ...... ...... ...... ...... ...... ......
# 开启HAProxy Stats页面 frontend http-in bind *:80 bind *:443 ssl crt /etc/pki/tls/certs/haproxy.pem default_backend backend_servers option forwardfor stats enable # 启HAProxy Stats页面 stats auth snow:123456 # 设定登录页面所需的账户名及密码 stats hide-version # 隐藏HAProxy版本 stats show-node # 显示HAProxy主机名 stats refresh 60s # 状态信息刷新时间60s一次 stats uri /haproxy-status # 登录的页面 ...... ...... ...... ...... ...... ......
[root@node1 ~]# systemctl restart haproxy
2) 客户端浏览器访问HAProxy状态监测页面
![]()
4.2 查看HAProxy状态-CLI模式
1) 配置HAProxy配置文件 [root@node1 ~]# vim /etc/haproxy/haproxy.cfg # 开启HAProxy Stats页面 global log 127.0.0.1 local2 info chroot /var/lib/haproxy pidfile /var/run/haproxy.pid stats socket /var/lib/haproxy/stats # 绑定socket maxconn 256 maxsslconn 256 tune.ssl.default-dh-param 2048 user haproxy ...... ...... ...... ...... ...... ...... [root@node1 ~]# systemctl restart haproxy
2) 访问HAProxy状态 [root@node1 ~]# yum install socat -y (1) 显示当前状态 [root@node1 ~]# echo "show info" | socat /var/lib/haproxy/stats stdio Name: HAProxy Version: 1.5.18 Release_date: 2016/05/10 Nbproc: 1 Process_num: 1 Pid: 28994 Uptime: 0d 0h05m13s Uptime_sec: 313 Memmax_MB: 0 Ulimit-n: 546 ...... ...... ...... ...... ...... ...... Tasks: 7 Run_queue: 1 Idle_pct: 100 node: node1.1000cc.net description:
(2) 显示状态和CVS信息 [root@node1 ~]# echo "show stat" | socat /var/lib/haproxy/stats stdio # pxname,svname,qcur,qmax,scur,smax,slim,stot,bin,bout,dreq,dresp,ereq, econ,eresp,wretr,wredis,status,weight,act,bck,chkfail,chkdown,lastchg, downtime,qlimit,pid,iid,sid,throttle,lbtot,tracked,type,rate, rate_lim,rate_max,check_status,check_code,check_duration,hrsp_1xx,hrsp_2xx, hrsp_3xx,hrsp_4xx,hrsp_5xx,hrsp_other,hanafail,req_rate,req_rate_max,req_tot, cli_abrt,srv_abrt,comp_in,comp_out,comp_byp,comp_rsp,lastsess, last_chk,last_agt,qtime,ctime,rtime,ttime,httpin,FRONTEND,,,0,0,2000,0,0,0,0, 0,0,,,,,OPEN,,,,,,,,,1,2,0,,,,0,0,0,0,,,,0,0,0,0,0,0,,0,0,0,,,0,0,0,0,,,,,,,, backend_servers,node2.1000cc.net,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,405,0 ,,1,3,1,,0,,2,0,,0,L4OK,,0,0,0,0,0,0,0,0,,,,0,0,,,,,-1,,,0,0,0,0,backend_servers, node3.1000cc.net,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,405,0,,1,3,2,,0,,2,0,,0, L4OK,,0,0,0,0,0,0,0,0,,,,0,0,,,,,-1,,,0,0,0,0,backend_servers,BACKEND,0,0,0,0,200, 0,0,0,0,0,,0,0,0,0,UP,2,2,0,,0,405,0,,1,3,0,,0,,1,0,,0,,,,0,0,0,0,0,0,,,,,0,0, 0,0,0,0,-1,,,0,0,0,0,
(3) 显示当前会话 [root@node1 ~]# echo "show sess" | socat /var/lib/haproxy/stats stdio 0x55f9a923ed10: proto=unix_stream src=unix:1 fe=GLOBAL be=<NONE> srv=<none> ts=0b age=0s calls=1 rq[f=c08200h,i=0,an=00h,rx=10s,wx=,ax=] rp[f=008000h,i=0,an=00h,rx=,wx=,ax=] s0=[7,8h,fd=1,ex=] s1=[7,8h,fd=-1,ex=] exp=
(4) 进入交互模式 [root@node1 ~]# socat readline /var/lib/haproxy/stats prompt # 敲入prompt命令后回车
> help ...... ...... ...... ...... ...... ...... > quit [root@node1 ~]#
1) 拓扑 |-------------| | Client | | node5 | |-------------| | | |-------------| | HA Proxy | | node1 | |-------------| | | |--------------| | |--------------| + DB Server +--------------+ DB Server + | node2 | | node3 | |--------------| |--------------| |