centos7配置haproxy

  1. 服务器列表:
    角色                    内网ip                外网ip
    haproxy服务器   192.168.8.81     192.168.8.252
    web1服务器       192.168.8.83     -
    web2服务器       192.168.8.84     -
  2. haproxy服务器配置:
    a. 内网配置:
    cat /etc/sysconfig/network-scripts/ifcfg-eth0
    centos7配置haproxy
    b. 外网配置:
    cat /etc/sysconfig/network-scripts/ifcfg-eth1
    centos7配置haproxy
    c. 安装:
    yum -y install haproxy
    d. 修改配置文件:
    vim /etc/haproxy/haproxy.conf
    centos7配置haproxy
    e. 配置文件原代码:
    global
    log         127.0.0.1 local2     # 日志
    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000                
    user        haproxy             
    group       haproxy
    daemon
    stats socket /var/lib/haproxy/stats
    defaults
    mode                    http
    log                     global
    option                  httplog
    option                  dontlognull
    option http-server-close
    option forwardfor       except 127.0.0.0/8
    option                  redispatch
    retries                 3
    timeout http-request    10s
    timeout queue           1m
    timeout connect         10s
    timeout client          1m
    timeout server          1m
    timeout http-keep-alive 10s
    timeout check           10s
    maxconn                 3000
    listen haproxy3-monitoring *:80                # Haproxy Monitoring 的使用端口:80
    mode http
    option forwardfor
    option httpclose
    stats enable
    stats show-legends
    stats refresh 5s
    stats uri /stats                            
    stats realm Haproxy\ Statistics
    stats auth testuser:test1234               
    stats admin if TRUE
    default_backend app-main
    frontend main
    bind *:80
    option http-server-close
    option forwardfor
    default_backend app-main
    backend app-main
    balance roundrobin                                    
    option httpchk HEAD / HTTP/1.1\r\nHost:\ localhost   
    server server1 192.168.8.83:80 check                 
    server server2 192.168.8.84:80 check

    f. 配置rsyslog:
    vim /etc/rsyslog.conf,去掉如下行的注释:
    centos7配置haproxy
    g. 创建rsyslog的haproxy配置文件:
    vim /etc/rsyslog.d/haproxy.conf,写入如下内容:

    local2.=info     /var/log/haproxy-access.log    # 访问日志
    local2.notice    /var/log/haproxy-info.log      # haproxy执行信息

    h. 重启rsyslog:
    systemctl restart rsyslog
    i. 启动haproxy:
    systemctl start haproxy
    j. 关闭apache:
    systemctl stop httpd

  3. web1服务器配置:
    a. 内网配置:
    cat /etc/sysconfig/network-scripts/ifcfg-eth0
    centos7配置haproxy
    b. 关闭防火墙:
    systemctl stop firewalld
  4. web2服务器配置(参照web1):
  5. 浏览器访问(192.168.8.252):
    a. 页面一:
    centos7配置haproxy
    b. 页面二:
    centos7配置haproxy
本文转自 Lee_吉  博客,原文链接:       http://blog.51cto.com/12173069/2061851  如需转载请自行联系原作者

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值