1服务管理命令 使用rpm包安装,服务器管理脚本安装在/etc/rc.d/init.d/haproxy,用法如下。 haproxy {start|stop|restart|reload|condrestart|status|check} 1.2配置文件检查 1、使用服务管理脚本检查 #/etc/rc.d/init.d/haproxy check 注:只能检查当前使用的配置文件。 2、使用命令检查 #haproxy –c –f 2监控统计 2.1监控统计页面 在配置文件里面配置了统计页面,可以通过浏览器访问。 修改/etc/haproxy/haproxy.cfg,增加下面几行: listen admin_stats bind 0.0.0.0:1080 mode http log 127.0.0.1 local0 err stats uri/admin?stats #/etc/init.d/haproxy restart 重启服务,然后通过http://ip地址:1080/admin?stats访问或者在配置文件/etc/haproxy/haproxy.cfg全局设置中加入如下几行 stats uri /haproxy-stats stats realm haproxy\ statistics stats auth admin:pasSWord #/etc/init.d/haproxy restart 重启服务,然后通过http://ip地址/haproxy-stats访问,输入用户名和密码进入查看。 2.2监控统计脚本 源码包中包含一个stats_haproxy.sh脚本,通过调用socat访问统计接口采集数据,功能等同于统计页面。命令用法如下。 Usage : stats_haproxy.sh [options] -s section --section -s section : section to use ( --list format) Options : --socket -S [socket] : socket to use (default: /var/run/haproxy.stat) --list -l : print available sections --help -h : print this message 命令示例如下。 #./stats_haproxy.sh –s public 命令输出如下: 50 sessions/s (avg: 50 ) 93 concurrent sessions 53 sessions/s (avg: 51 ) 92 concurrent sessions 34 sessions/s (avg: 45 ) 95 concurrent sessions 33 sessions/s (avg: 42 ) 92 concurrent sessions 33 sessions/s (avg: 40 ) 101 concurrent sessions 2.3监控统计命令 使用socat命令,可以直接通过命令行采集数据。命令示例如下。 #echo 'help' | socat /var/run/haproxy.stat stdio 命令输出如下,列出了可用的命令参数,其中参数stat可以显示统计信息。 Unknown command. Please enter one of the following commands only : clear counters : clear max statistics counters (add 'all' for all counters) help : this message prompt : toggle interactive mode with prompt quit : disconnect show info : report information about the running process show stat : report counters for each proxy and server show errors : report last request and response errors for each proxy show sess [id] : report the list of current sessions or dump this session get weight : report a server's current weight set weight : change a server's weight set timeout : change a timeout setting disable server : set a server in maintenance mode enable server : re-enable a server that was previously in maintenance mode #echo 'show stat' | socat /var/run/haproxy.stat stdio 命令输出为csv格式,如下。示例脚本就是格式化 #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, mm,FRONTEND,,,0,4,30000,124,51741,1426307,0,0,10,,,,,OPEN,,,,,,,,,1,1,0,,,,0,0,0,10,,,,0,111,0,13,0,0,,0,10,124,,, mm,test,0,0,0,4,,114,51441,1424624,,0,,0,0,0,0,no check,1,1,0,,,,,,1,1,1,,114,,2,0,,10,,,,0,111,0,3,0,0,0,,,,13,0, mm,BACKEND,0,0,0,4,30000,114,51741,1426307,0,0,,0,0,0,0,UP,1,1,0,,0,13450,0,,1,1,0,,114,,1,0,,10,,,,0,111,0,3,0,0,,,,,13,0, 2.4 第三方工具hatop 1、源站:http:///projects/hatop/ 目前最新版本是hatop-0.7.7.tar.gz 2、安装 进入解压后的源码包目录,运行下面命令安装。 #install -m 755 bin/hatop /usr/local/bin #install -m 644 man/hatop.1 /usr/local/share/man/man1 #gzip /usr/local/share/man/man1/hatop.1 3、hatop使用 Hatop界面类似top,分为5个子界面(切换分别按 1 2 3 4 5或tab键选择)。 注:按5进入CLI模式,返回其它界面,只能按tab键切换。 hatop界面示例如下,输出信息与web统计界面类似,相关参数含义查看官方文档 http:///projects/hatop/readme/ #hatop -s /var/run/haproxy.stat 转载于https://segmentfault.com/a/1190000003023634#articleHeader17 |
|
来自: waitingnothing > 《Haproxy》