当前位置:网站首页>haproxy2.6负载安装配置
haproxy2.6负载安装配置
2022-07-21 14:19:00 【bjywxc】
1、下载解压
https://www.haproxy.org/download/2.6/src/haproxy-2.6.1.tar.gz
tar -xvf haproxy-2.6.1.tar.gz
2、安装依赖包
yum -y install make gcc pcre-devel bzip2-devel openssl-devel systemd-devel
3、创建用户
useradd -r -M -s /sbin/nologin haproxy
4、编译安装
make clean
make -j 4 TARGET=linux-glibc USE_OPENSSL=1 USE_ZLIB=1 USE_PCRE=1 USE_SYSTEMD=1
make install PREFIX=/u01/haproxy
5、创建软链接
ln -sv /u01/haproxy/sbin/haproxy /usr/sbin/haproxy
查看版本
haproxy -v
6、haproxy 启动脚本配置
vi /usr/lib/systemd/system/haproxy.service
[Unit]
Description=HAProxy Load Balancer
After=syslog.target network.target
[Service]
ExecStartPre=/usr/sbin/haproxy -f /etc/haproxy/haproxy.cfg -c -q
ExecStart=/usr/sbin/haproxy -Ws -f /etc/haproxy/haproxy.cfg -p /var/run/haproxy.pid
ExecReload=/bin/kill -USR2
[Install]
WantedBy=multi-user.target
systemctl daemon-reload
7、haproxy配置文件
vi /etc/haproxy/haproxy.cfg
# This config file needs haproxy-1.1.28, haproxy-1.2.1 or later.
# Parameter meaning see: http://www.linuxidc.com/Linux/2012-07/65350.htm
#
# Global system parameter, usually related to operation system setting.
global
maxconn 8192
log 127.0.0.1 local0 info
#log 127.0.0.1
#log loghost local0 info
uid 988
gid 982
daemon
nbthread 8
#debug
#quiet
ulimit-n 65535
chroot /u01/haproxy
stats socket /u01/haproxy/haproxy.sock
# These parameter can be used for frontend, backend and listen:
defaults
log global
mode http
#mode tcp
option httplog
option httpclose
option dontlognull
option forwardfor
option redispatch
option forwardfor
option redispatch
option abortonclose
retries 3
maxconn 20480
balance roundrobin
#balance source
#balance leastconn
timeout connect 30s
timeout client 30s
timeout server 30s
timeout check 30s
#--------------web配置-----------------
listen admin_stats
bind 0.0.0.0:8000
stats enable
mode http
log global
stats uri /haproxy_stats
stats realm Haproxy\ Statistics
stats auth admin:admin
#stats hide-version
stats admin if TRUE
stats refresh 30s
frontend web1
bind :8080
log global
mode http
use_backend webserver1
backend webserver1
mode http
#option httpchk GET /gioi
cookie SERVERID insert indirect nocache
server 141-7007 172.18.189.16:7007 cookie s1 check inter 5000 #后端的主机 IP &权衡
server 141-7009 172.18.189.16:7009 cookie s2 check inter 5000 #后端的主机 IP &权衡
8、启用日志
vim /etc/rsyslog.conf
#vim /etc/rsyslog.conf #去掉以下两列注释:
$ModLoad imudp
$UDPServerRun 514
在添加如下内容:
# Save haproxy messages also to haproxy.log
local0.* /var/log/haproxy.log
systemctl restart rsyslog.service
9、启动服务
systemctl restart haproxy.service
启动失败,检查配置文件是否有错误
haproxy -f /etc/haproxy/haproxy.cfg -c
10、https主要参数配置
1、hapory https+后端http方式,
tune.ssl.default-dh-param 2048
bind :80
bind :443 ssl crt /soft/server.pem
redirect scheme https if !{ ssl_fc }
http-request set-header X-forwarded-Port %[dst_port]
http-request add-header X-forwarded-Proto https if { ssl_fc }
2、hapory tcp+后端https方式
参考链接
https://docs.haproxy.org/
http://www.yunweipai.com/35234.html
https://www.jianshu.com/u/db980997dc98
https://blog.csdn.net/hellolcr/article/details/120811964
https://www.cnblogs.com/WxmUP/p/12670799.html
https://blog.csdn.net/icefan02/article/details/122189657
https://blog.csdn.net/chengxuyuanyonghu/article/details/60468829
acl规则:https://blog.csdn.net/w20010106/article/details/86062651
https://blog.csdn.net/vanexph/article/details/106755856
边栏推荐
猜你喜欢
随机推荐
Postman - post请求application/x-www-from-urlencoded
The difference between w3school and w3school
【读书会第13期】+第一章 多媒体处理工具 FFmpeg 工具集
The question is: can you successfully apply for 8g memory on a machine with 4GB physical memory?
Bypass some dog SQL and XSS
92. (leaflet chapter) leaflet situation plotting - acquisition of attack direction
攻防世界---mfw
Attack and defense world ---mfw
wallys/IPQ8074A 4x4 2.4G 8x8 5G 802.11ax
真人踩过的坑,告诉你避免自动化测试新手常犯的10个错误
过d盾 jsp webshell+冰蝎免杀马探讨
仅需一个依赖给Swagger换上新皮肤,既简单又炫酷
【读书会第13期】+第三章 视频文件的编码格式
Random talk on DRDS flexible affairs
小道仙博客【开源个人博客】
20 -- 验证回文串
The state Internet Information Office made a decision on the administrative punishment related to the network security review of didi Global Co., Ltd. in accordance with the law
Postman - post请求application/json参数
js 图片转换base64 base64转换为file对象
一些工具改造