HAProxy基础配置-配置多进程多线程案例

            HAProxy基础配置-配置多进程多线程案例

                                   作者:尹正杰

版权声明:原创作品,谢绝转载!否则将追究法律责任。

 

 

一.使用HAProxy默认的进程和线程配置

1>.编辑HAProxy的配置文件

[[email protected] ~]# cat /etc/haproxy/haproxy.cfg 
global
maxconn 100000
chroot /yinzhengjie/softwares/haproxy
#stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
user haproxy
group haproxy
daemon
pidfile /yinzhengjie/softwares/haproxy/run/haproxy.pid
log 127.0.0.1 local3 info

defaults
option http-keep-alive
option  forwardfor
maxconn 100000
mode http
timeout connect 300000ms
timeout client  300000ms
timeout server  300000ms

listen stats
 mode http
 bind 0.0.0.0:9999
 stats enable
 log global
 stats uri     /haproxy-status
 stats auth    haadmin:q1w2e3r4ys

listen  web_port
 bind 0.0.0.0:80
 mode http
 log global
 server web1  127.0.0.1:8080  check inter 3000 fall 2 rise 5
[[email protected] ~]# 

2>.启动haproxy服务

[[email protected] ~]# netstat -untalp | grep haproxy
[[email protected] ~]# 
[[email protected] ~]# systemctl start haproxy
[[email protected] ~]# 
[[email protected] ~]# netstat -untalp | grep haproxy
tcp        0      0 0.0.0.0:9999            0.0.0.0:*               LISTEN      12171/haproxy       
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      12171/haproxy       
udp        0      0 0.0.0.0:43409           0.0.0.0:*                           12169/haproxy       
[[email protected] ~]# 

3>.查看haproxy的进程和线程信息

[[email protected] ~]# ps -ef | grep haproxy | grep -v grep
root     12169     1  0 20:00 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy  12171 12169  0 20:00 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
[[email protected] ~]# 
[[email protected] ~]# yum -y install psmisc          #安装该软件可以使用pstree命令。
[[email protected] ~]# 
[[email protected] ~]# pstree -p 12169
haproxy(12169)───haproxy(12171)
[[email protected] ~]# 
[[email protected] ~]# 

 

二.自定义进程配置

1>.编辑HAProxy的配置文件

[[email protected] ~]# lscpu 
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                8
On-line CPU(s) list:   0-7
Thread(s) per core:    1
Core(s) per socket:    8
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 158
Model name:            Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
Stepping:              10
CPU MHz:               2207.998
BogoMIPS:              4415.99
Hypervisor vendor:     KVM
Virtualization type:   full
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              9216K
NUMA node0 CPU(s):     0-7
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx rdtscp lm 
constant_tsc rep_good nopl xtopology nonstop_tsc eagerfpu pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx rdrand hypervisor lahf_lm abm 3dnowprefetch fsgsbase avx2 invpcid rdseed clflushopt flush_l1d[[email protected] ~]# 
[[email protected] ~]# lscpu
[[email protected] ~]# cat /etc/haproxy/haproxy.cfg 
global
maxconn 100000
chroot /yinzhengjie/softwares/haproxy
#stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
user haproxy
group haproxy
daemon
nbproc 8
cpu-map 1 0
cpu-map 2 1
cpu-map 3 2
cpu-map 4 3
cpu-map 5 4
cpu-map 6 5
cpu-map 7 6
cpu-map 8 7
pidfile /yinzhengjie/softwares/haproxy/run/haproxy.pid
log 127.0.0.1 local3 info

defaults
option http-keep-alive
option  forwardfor
maxconn 100000
mode http
timeout connect 300000ms
timeout client  300000ms
timeout server  300000ms

listen stats
 mode http
 bind 0.0.0.0:9999
 stats enable
 log global
 stats uri     /haproxy-status
 stats auth    haadmin:q1w2e3r4ys

listen  web_port
 bind 0.0.0.0:80
 mode http
 log global
 server web1  127.0.0.1:8080  check inter 3000 fall 2 rise 5
[[email protected] ~]# 

2>.重启haproxy服务

[[email protected] ~]# netstat -untalp | grep haproxy
tcp        0      0 0.0.0.0:9999            0.0.0.0:*               LISTEN      12171/haproxy       
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      12171/haproxy       
udp        0      0 0.0.0.0:43409           0.0.0.0:*                           12169/haproxy       
[[email protected] ~]# 
[[email protected] ~]# systemctl restart haproxy
[[email protected] ~]# 
[[email protected] ~]# netstat -untalp | grep haproxy
tcp        0      0 0.0.0.0:9999            0.0.0.0:*               LISTEN      12242/haproxy       
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      12242/haproxy       
udp        0      0 0.0.0.0:36481           0.0.0.0:*                           12240/haproxy       
[[email protected] ~]# 

3>.查看haproxy的进程信息

[[email protected] ~]# ps -ef | grep haproxy | grep -v grep      #查看进程信息
root     12240     1  0 20:08 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy  12242 12240  0 20:08 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy  12243 12240  0 20:08 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy  12244 12240  0 20:08 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy  12245 12240  0 20:08 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy  12246 12240  0 20:08 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy  12247 12240  0 20:08 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy  12248 12240  0 20:08 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy  12249 12240  0 20:08 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
[[email protected] ~]# 
[[email protected] ~]# pstree -p 12240                  #查看线程信息
haproxy(12240)─┬─haproxy(12242)
               ├─haproxy(12243)
               ├─haproxy(12244)
               ├─haproxy(12245)
               ├─haproxy(12246)
               ├─haproxy(12247)
               ├─haproxy(12248)
               └─haproxy(12249)
[[email protected] ~]# 

 

三.自定义线程配置

1>.编辑HAProxy的配置文件

[[email protected] ~]# vim /etc/haproxy/haproxy.cfg 
[[email protected] ~]# 
[[email protected] ~]# cat /etc/haproxy/haproxy.cfg 
global
maxconn 100000
chroot /yinzhengjie/softwares/haproxy
#stats socket /var/lib/haproxy/haproxy.sock mode 600 level admin
user haproxy
group haproxy
daemon
nbproc 8
cpu-map 1 0
cpu-map 2 1
cpu-map 3 2
cpu-map 4 3
cpu-map 5 4
cpu-map 6 5
cpu-map 7 6
cpu-map 8 7
nbthread 5
pidfile /yinzhengjie/softwares/haproxy/run/haproxy.pid
log 127.0.0.1 local3 info

defaults
option http-keep-alive
option  forwardfor
maxconn 100000
mode http
timeout connect 300000ms
timeout client  300000ms
timeout server  300000ms

listen stats
 mode http
 bind 0.0.0.0:9999
 stats enable
 log global
 stats uri     /haproxy-status
 stats auth    haadmin:q1w2e3r4ys

listen  web_port
 bind 0.0.0.0:80
 mode http
 log global
 server web1  127.0.0.1:8080  check inter 3000 fall 2 rise 5
[[email protected] ~]# 
[[email protected] ~]# 

2>.重启haproxy服务

[[email protected] ~]# netstat -untalp | grep haproxy
tcp        0      0 0.0.0.0:9999            0.0.0.0:*               LISTEN      12242/haproxy       
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      12242/haproxy       
udp        0      0 0.0.0.0:36481           0.0.0.0:*                           12240/haproxy       
[[email protected] ~]# 
[[email protected] ~]# systemctl restart haproxy
[[email protected] ~]# 
[[email protected] ~]# netstat -untalp | grep haproxy
tcp        0      0 0.0.0.0:9999            0.0.0.0:*               LISTEN      12289/haproxy       
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      12289/haproxy       
udp        0      0 0.0.0.0:59105           0.0.0.0:*                           12287/haproxy       
[[email protected] ~]# 
[[email protected] ~]# 

3>.查看haproxy的线程信息

[[email protected] ~]# ps -ef | grep haproxy | grep -v grep        #查看进程信息
root     12287     1  0 20:12 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy  12289 12287  0 20:12 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy  12290 12287  0 20:12 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy  12295 12287  0 20:12 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy  12300 12287  0 20:12 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy  12305 12287  0 20:12 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy  12306 12287  0 20:12 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy  12311 12287  0 20:12 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
haproxy  12316 12287  0 20:12 ?        00:00:00 /usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid
[[email protected] ~]# 
[[email protected] ~]# pstree -p 12287                    #查看线程信息
haproxy(12287)─┬─haproxy(12289)─┬─{haproxy}(12291)
               │                ├─{haproxy}(12292)
               │                ├─{haproxy}(12293)
               │                └─{haproxy}(12294)
               ├─haproxy(12290)─┬─{haproxy}(12296)
               │                ├─{haproxy}(12297)
               │                ├─{haproxy}(12298)
               │                └─{haproxy}(12299)
               ├─haproxy(12295)─┬─{haproxy}(12301)
               │                ├─{haproxy}(12302)
               │                ├─{haproxy}(12303)
               │                └─{haproxy}(12304)
               ├─haproxy(12300)─┬─{haproxy}(12325)
               │                ├─{haproxy}(12326)
               │                ├─{haproxy}(12327)
               │                └─{haproxy}(12328)
               ├─haproxy(12305)─┬─{haproxy}(12307)
               │                ├─{haproxy}(12308)
               │                ├─{haproxy}(12309)
               │                └─{haproxy}(12310)
               ├─haproxy(12306)─┬─{haproxy}(12312)
               │                ├─{haproxy}(12313)
               │                ├─{haproxy}(12314)
               │                └─{haproxy}(12315)
               ├─haproxy(12311)─┬─{haproxy}(12317)
               │                ├─{haproxy}(12318)
               │                ├─{haproxy}(12319)
               │                └─{haproxy}(12320)
               └─haproxy(12316)─┬─{haproxy}(12321)
                                ├─{haproxy}(12322)
                                ├─{haproxy}(12323)
                                └─{haproxy}(12324)
[[email protected] ~]# 

你可能感兴趣的:(HAProxy基础配置-配置多进程多线程案例)