企业🤖AI智能体构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
一) 在centos7上采用yum安装haproxy [root@proxy01 ~]# yum -y install haproxy [root@proxy01 ~]# rpm -ql haproxy /etc/haproxy /etc/haproxy/haproxy.cfg----配置文件 /etc/logrotate.d/haproxy /etc/sysconfig/haproxy /usr/bin/halog /usr/bin/iprange /usr/lib/systemd/system/haproxy.service----启动脚本 /usr/sbin/haproxy /usr/sbin/haproxy-systemd-wrapper 二)在centos7编译安装haproxy 1.7.10 [root@proxy02 ~]# yum -y install pcre-devel zlib-devel openssl-devel [root@proxy02 src]# wget http://soft.51yuki.cn/haproxy-1.7.10.tar.gz root@proxy02 src]# tar xf haproxy-1.7.10.tar.gz [root@proxy02 src]# cd haproxy-1.7.10 [root@proxy02 haproxy-1.7.10]# make TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 ARCH=x86_644 && make install PREFIX=/usr/local/haproxy 然后创建目录,存放配置文件 [root@proxy02 ~]# mkdir /etc/haproxy ~~~ global log 127.0.0.1 local2 chroot /usr/local/haproxy pidfile /usr/local/haproxy/haproxy.pid maxconn 100000 daemon nbproc 1 defaults option http-keep-alive maxconn 100000 mode http log global option httplog timeout http-request 10s timeout queue 1m timeout connect 10s timeout client 1m timeout server 1m timeout http-keep-alive 10s timeout check 10s ######################################################### listen status mode http bind *:8888 stats enable stats hide-version stats uri /haproxy-status stats auth haproxy:saltstack stats admin if TRUE stats realm Haproxy\ Statistics #stats scope . #--------------------------------------------------------------------- # main frontend which proxys to the backends #--------------------------------------------------------------------- #frontend main *:5000 # acl url_static path_beg -i /static /images /javascript /stylesheets # acl url_static path_end -i .jpg .gif .png .css .js # # use_backend static if url_static # default_backend app #--------------------------------------------------------------------- ###################################################################### frontend frontend_www_example_com bind 10.2.11.170:80 mode http option httplog log global default_backend backend_www_example_com ####################################################### backend backend_www_example_com option forwardfor header X-REAL-IP option httpchk HEAD / HTTP/1.0 balance roundrobin server web01.51yuki.cn 10.2.11.207:8080 check inter 2000 rise 30 fall 15 server web02.51yuki.cn 10.2.11.206:8080 check inter 2000 rise 30 fall 15 ~~~ * 启动脚本: [Unit] Description=HAProxy Load Balancer After=syslog.target network.target [Service] EnvironmentFile=/etc/sysconfig/haproxy ExecStart=/usr/local/haproxy/sbin/haproxy -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid $OPTIONS ExecReload=/bin/kill -USR2 $MAINPID KillMode=mixed [Install] WantedBy=multi-user.target * /etc/sysconfig/haproxy [root@proxy01 sysconfig]# vim haproxy # Add extra options to the haproxy daemon here. This can be useful for # specifying multiple configuration files with multiple -f options. # See haproxy(1) for a complete list of options. OPTIONS="" * 创建用户 [root@proxy02 system]# groupadd -g 188 haproxy [root@proxy02 system]# useradd -u 188 -g haproxy -s /sbin/nologin haproxy 启动服务 [root@proxy02 system]# systemctl daemon-reload [root@proxy02 system]# systemctl restart haproxy [root@proxy02 system]# ss -tunlp|grep 80 tcp LISTEN 0 128 10.2.13.216:80 *:* users:(("haproxy",pid=3759,fd=4))