backend //后台设置
安装软件:
[root@ds1 ~]# rpm -qa | grep haproxy
[root@ds1 ~]# yum -y install haproxy
环境准备:
配置yum源
# service iptables stop //关闭防火墙
# chkconfig iptables off //关闭开机自启
# setenforce 0 //设置SELinux 为宽松模式
配置WEB服务器
#yum -y install httpd php
#service httpd start
#chkconfig httpd on
[root@pc53 ~] #echo " <?php echo 'web53' ; ?> " > /var/www/html/test.php
[root@pc54 ~] #echo " <?php echo 'web54' ; ?> " > /var/www/html/test.php
配置文件:
[root@ds1 ~]# /etc/haproxy/haproxy.cfg
global / 全局设置
defaults //默认设置
frontend //前台设置
listen stats
bind 0.0.0.0:1080
stats refresh 30s
stats uri /mystats
stats realm Haproxy manager
stats auth admin:admin
listen websrv 0.0.0.0:80
cookie SERVERID rewrite
balance roundrobin
server web1 201.1.1.102:80 cookie app1inst1 inter check 2000 rise 2 fall 5
server web2 201.1.1.103:80 cookie app1inst2 inter 2000 check rise 2 fall 5
修改系统的日志文件:
15 $ModLoad imudp
16 $UDPServerRun 514
可以接收远端接收功能
local2.* /var/log/haproxy.log
自定义日志存放路径
重启rsyslog和haproxy
[root@ds1 ~]# systemctl restart rsyslog.service
[root@ds1 ~]# systemctl restart haproxy.service