haproxy2.6负载安装配置

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

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值