概述
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
最后
以上就是聪明唇膏为你收集整理的haproxy2.6负载安装配置1、下载解压2、安装依赖包3、创建用户4、编译安装5、创建软链接6、haproxy 启动脚本配置7、haproxy配置文件8、启用日志9、启动服务10、https主要参数配置的全部内容,希望文章能够帮你解决haproxy2.6负载安装配置1、下载解压2、安装依赖包3、创建用户4、编译安装5、创建软链接6、haproxy 启动脚本配置7、haproxy配置文件8、启用日志9、启动服务10、https主要参数配置所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复