Last Updated on 2021年7月4日 by かんりにん
先日のステータス出力を検証した流れで、haproxyのコマンドライン操作について試したことを抜粋。
参考:またまたお世話になっております!
Ver1.5 マニュアル 9.2 Unix Socket commands
Contents
haproxy.cfg 設定
前回と同じ内容です。
globalセクションの中に1行記載し、プロセスを再起動します。
global # snip --- # snip --- # snip --- stats socket /var/lib/haproxy/stats
対話モードでのコマンド操作
socatを使って、ソケットから対話モードを実行
# socat readline /var/lib/haproxy/stats prompt ←コマンド実行直後は"待ち"状態なので、"prompt"を入力してプロンプトを出す >
show statでのステータス確認
show infoは前回やったので、今回はshow statを例として出力。
> show stat # 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, main,FRONTEND,,,0,0,3000,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,,,,,,,, static,dev-web01,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,61,0,,1,3,1,,0,,2,0,,0,L4OK,,0,0,0,0,0,0,0,0,,,,0,0,,,,,-1,,,0,0,0,0, static,dev-web02,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,61,0,,1,3,2,,0,,2,0,,0,L4OK,,0,0,0,0,0,0,0,0,,,,0,0,,,,,-1,,,0,0,0,0, static,dev-web03,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,61,0,,1,3,3,,0,,2,0,,0,L4OK,,2,0,0,0,0,0,0,0,,,,0,0,,,,,-1,,,0,0,0,0, static,dev-web04,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,61,0,,1,3,4,,0,,2,0,,0,L4OK,,2,0,0,0,0,0,0,0,,,,0,0,,,,,-1,,,0,0,0,0, static,BACKEND,0,0,0,0,300,0,0,0,0,0,,0,0,0,0,UP,4,4,0,,0,61,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,
バックエンドサーバーのうち1台を無効にしてみる
– コマンドラインから無効化を実行
> disable server static/dev-web01
– ステータスを確認
> show stat # 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, main,FRONTEND,,,0,0,3000,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,,,,,,,, static,dev-web01,0,0,0,0,,0,0,0,,0,,0,0,0,0,MAINT,1,1,0,0,1,4,4,,1,3,1,,0,,2,0,,0,L4OK,,0,0,0,0,0,0,0,0,,,,0,0,,,,,-1,,,0,0,0,0, static,dev-web02,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,77,0,,1,3,2,,0,,2,0,,0,L4OK,,0,0,0,0,0,0,0,0,,,,0,0,,,,,-1,,,0,0,0,0, static,dev-web03,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,77,0,,1,3,3,,0,,2,0,,0,L4OK,,2,0,0,0,0,0,0,0,,,,0,0,,,,,-1,,,0,0,0,0, static,dev-web04,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,77,0,,1,3,4,,0,,2,0,,0,L4OK,,7,0,0,0,0,0,0,0,,,,0,0,,,,,-1,,,0,0,0,0, static,BACKEND,0,0,0,0,300,0,0,0,0,0,,0,0,0,0,UP,3,3,0,,0,77,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,
disableにしたサーバ”dev-web01″のステータスが”UP”から”MAINT(メンテナンスモード)”に変わっている。
以下はdisable実行時のログ。
– haproxy.log抜粋
May 15 16:50:50 localhost haproxy[3040]: Server static/dev-web01 is going DOWN for maintenance. 3 active and 0 backup servers left. 0 sessions active, 0 requeued, 0 remaining in queue.
無効化したサーバーを有効化してみる
– コマンドラインから有効化
> enable server static/dev-web01
– ステータスを確認
> show stat # 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, main,FRONTEND,,,0,0,3000,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,,,,,,,, static,dev-web01,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,1,3,35,,1,3,1,,0,,2,0,,0,L4OK,,0,0,0,0,0,0,0,0,,,,0,0,,,,,-1,,,0,0,0,0, static,dev-web02,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,111,0,,1,3,2,,0,,2,0,,0,L4OK,,0,0,0,0,0,0,0,0,,,,0,0,,,,,-1,,,0,0,0,0, static,dev-web03,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,111,0,,1,3,3,,0,,2,0,,0,L4OK,,2,0,0,0,0,0,0,0,,,,0,0,,,,,-1,,,0,0,0,0, static,dev-web04,0,0,0,0,,0,0,0,,0,,0,0,0,0,UP,1,1,0,0,0,111,0,,1,3,4,,0,,2,0,,0,L4OK,,2,0,0,0,0,0,0,0,,,,0,0,,,,,-1,,,0,0,0,0, static,BACKEND,0,0,0,0,300,0,0,0,0,0,,0,0,0,0,UP,4,4,0,,0,111,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,
enableにしたサーバ”dev-web01″のステータスが”MAINT”から”UP”に変わっていることを確認。
以下はenable実行時のログ。
– /var/log/haproxy.logの抜粋
May 15 16:51:25 localhost haproxy[3040]: Server static/dev-web01 is UP/READY (leaving forced maintenance).
対話モード終了
> quit
参考:コマンド一覧
UNIXソケットでのアクセスにて、haproxyの動作をコントロールする各種コマンドを利用可能。ここではいったんhelpの抜粋を。
コマンドを使った操作方法も時間を作って試してみたいところです。
あとは公式マニュアルを見ながら気合と根性で意訳…ですね(汗
> help Unknown command. Please enter one of the following commands only : clear counters : clear max statistics counters (add 'all' for all counters) clear table : remove an entry from a table help : this message prompt : toggle interactive mode with prompt quit : disconnect show info : report information about the running process show pools : report information about the memory pools usage 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 show table [id]: report table usage stats or dump this table's contents get weight : report a server's current weight set weight : change a server's weight set server : change a server's state or weight set table [id] : update or create a table entry's data set timeout : change a timeout setting set maxconn : change a maxconn setting set rate-limit : change a rate limiting value disable : put a server or frontend in maintenance mode enable : re-enable a server or frontend which is in maintenance mode shutdown : kill a session or a frontend (eg:to release listening ports) show acl [id] : report avalaible acls or dump an acl's contents get acl : reports the patterns matching a sample for an ACL add acl : add acl entry del acl : delete acl entry clear acl <id> : clear the content of this acl show map [id] : report avalaible maps or dump a map's contents get map : reports the keys and values matching a sample for a map set map : modify map entry add map : add map entry del map : delete map entry clear map <id> : clear the content of this map set ssl <stmt> : set statement for ssl