gaojinguan 发表于 2019-1-1 11:57:05

centos7配置haproxy


[*]服务器列表:
角色                  内网ip                外网ip
haproxy服务器   192.168.8.81   192.168.8.252
web1服务器       192.168.8.83   -
web2服务器       192.168.8.84   -
[*]haproxy服务器配置:
a. 内网配置:
cat /etc/sysconfig/network-scripts/ifcfg-eth0
http://i2.运维网.com/images/blog/201801/17/e869034a640d151990410853b8145865.png
b. 外网配置:
cat /etc/sysconfig/network-scripts/ifcfg-eth1
http://i2.运维网.com/images/blog/201801/17/b3827d1df442844f8807dcfd42590a72.png
c. 安装:
yum -y installhaproxy
d. 修改配置文件:
vim/etc/haproxy/haproxy.cfg
http://i2.运维网.com/images/blog/201801/17/5dd69272a34f3055a5a38cffee35ed24.png
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,去掉如下行的注释:
http://i2.运维网.com/images/blog/201801/17/2dcd57096e4380166337351566fce50d.png
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:
systemctlrestartrsyslog
i. 启动haproxy:
systemctlstarthaproxy
j. 关闭apache:
systemctlstophttpd

[*]web1服务器配置:
a. 内网配置:
cat/etc/sysconfig/network-scripts/ifcfg-eth0
http://i2.运维网.com/images/blog/201801/17/f25004ad8adae52cf57baa07e38f3404.png
b. 关闭防火墙:
systemctlstopfirewalld
[*]web2服务器配置(参照web1):
[*]浏览器访问(192.168.8.252):
a. 页面一:
http://i2.运维网.com/images/blog/201801/17/eb021025c89d43c5ac0b1e4a18721d8a.png
b. 页面二:
http://i2.运维网.com/images/blog/201801/17/22a4cd74e61367dbe1b791af7335da0d.png



页: [1]
查看完整版本: centos7配置haproxy