0
点赞
收藏
分享

微信扫一扫

haproxy

金牛豆豆 2022-05-18 阅读 42

虚拟机为桥接模式

第一台地址:192.168.100.100

第二台地址:192.168.100.111

第三台地址:192.168.100.222



第一台进行配置

-------编译安装haproxy----

yum
install -y \

pcre-devel
\

bzip2-devel
\

openssl-devel
\

libnl3-devel
\

systemd-devel



上传压缩包

解压

tar xzvf
haproxy-2.1.3.tar.gz

cd haproxy-2.1.3



安装管理包

yum install gcc
gcc-c++ -y

make
TARGET=linux-glibc \

USE_OPENSSL=1 \

USE_SYSTEMD=1 \

USE_PCRE=1  \

USE_ZLIB=1


make
install


创建文件

mkdir
/etc/haproxy


修改配置文件


vi
/usr/lib/systemd/system/haproxy.service

[Unit]

Description=HAProxy
Load Balancer

After=syslog.target
network.target


[Service]

ExecStartPre=/usr/local/sbin/haproxy
-f /etc/haproxy/haproxy.cfg   -c -q

ExecStart=/usr/local/sbin/haproxy
-Ws -f /etc/haproxy/haproxy.cfg  -p
/run/haproxy.pid

ExecReload=/bin/kill
-USR2 $MAINPID


[Install]

WantedBy=multi-user.target



cp
examples/option-http_proxy.cfg /etc/haproxy/haproxy.cfg

vi
/etc/haproxy/haproxy.cfg



--------使用如下配置文件---------

global

        maxconn         4096

        ulimit-n        16384

        log             127.0.0.1 local0

        uid             200

        gid             200

        chroot          /var/empty

        nbproc          2

        daemon

defaults

        mode http

        retries 3

         timeout connect         10s

         timeout client          1m

        timeout server          1m

        timeout http-keep-alive 10s

        timeout check           10s

frontend www

        bind *:80

        bind-process 2

        mode   
http

        option 
httplog

        option 
forwardfor

        option 
httpclose

        log global

        default_backend serverpool

backend serverpool

        mode http

        option 
redispatch

        option 
abortonclose

        balance static-rr

        cookie 
SERVERID

        option 
httpchk GET /index.html

        server 
ser01 192.168.100.111:80 cookie 1 weight 1 check inter 2000 rise 2 fall
3

        server 
ser02 192.168.100.222:80 cookie 2 weight 1 check inter 2000 rise 2 fall
3

listen admin_stats

        bind 0.0.0.0:9188

        mode http

        log 127.0.0.1 local0 err

        stats refresh 30s

        stats uri /status

        stats realm welcom login\ Haproxy

        stats auth admin:admin123

        stats hide-version

        stats admin if TRUE




haproxy
-c -f /etc/haproxy/haproxy.cfg //检查配置文件


service haproxy
start


netstat -anpt |grep
haproxy




第二、三台安装Apache服务

修改配置文件

在/var/www/html/index.html




---调度器的地址--------------

​​http://192.168.100.100/​​




​​http://192.168.100.100:9188/status​​  //查看统计页面




实验结果

192.168.100.222 
x 192.168.100.100 
C O A 192.168100.100.9188/status 
HAProxy 
Statistics Report for pid 11342 
> General process information 
pid = 11342 (process nbproc 2, nbthread I) 
uptime = Od Oh09m21s 
system limits: memmax = unlimited; "limit-n = 16384 
maxsock = 8221 , maxconn = 4096; maxpipes = O 
current conns = 2; current pipes = 0/0; conn rate = 2/sec; bit rate = 0.271 kbps 
Running tasks: 1/15, de 100 % 
Que 
Frontend 
Statistics Report for HAProxy x 
E*Nem-CXY521 
active up 
- MYFREEMP... 
x 
active up, going down 
active DOWN, going up 
active or backup DOWN 
GOO* Translate 
backup up 
backup UP, going down 
backup DOWN, going up 
not checked 
active or backup DOWN for maintenance (MAINT) 
active or backup SOFT STOPPED for maintenance 
Note. "NOLB"PORAIN" UP with load-balancing disabled 
Display option: 
Scope 
• Hide 'DOWN' servers 
now 
• mort (schema) 
4 096 
4 255 
2 728 
2 
OPEN 
serverpool 
ser02 
Backend 
Choose the action to perform on the checked servers 
6m56s 
6m56s 
6m56s 
admin stats 
cur 
Frontend 
Max 
Limit 
cur 
Max 
Limit 
cur 
Max 
410 
Limit 
4 096 
410 
Apply 
Total 
IS 
11 
5 
4 
9 
LB Tot 
2 406 
1 849 
4255 
5 496 
5496 
1 159 
1 147 
2 306 
137602 
137602 
Retr 
8mgs up 
7m46s up 
8m9s UP 
Redis 
L70K'200 in Ims 
L70K'200 in Ims 
ht 
Act 
Eck 
Chk 
External resources: 
e.nmarysite 
• updares(y2-1) 
Imlls 
own 
OPEN 
9m21s UP



举报

相关推荐

0 条评论