初学者的haproxy实验

haproxy实验

配置web1

安装环境包

yum install -y pcre-devel zlib-devel gcc gcc-c++ make 

创建用户

useradd -M -s /sbin/nologin nginx

解压包

tar zxvf nginx-1.12.0.tar.gz

配置

cd nginx-1.12.0/

./configure --prefix=/usr/local/nginx --user=nginx --group=nginx

编译

make && make install

编写网页

cd /usr/local/nginx/html

vim test.html

<h1>this is C7-2T</h1>

创建软连接

ln -s /usr/local/nginx/sbin/nginx /usr/local/sbin/

启动服务

nginx

查看接口

netstat -ntap | grep nginx

web2和web1基本相同,差异内容如下

cd /usr/local/nginx/html

vim test.html

<h1>this is C7-2T</h1>

配置haproxy

yum -y install pcre-devel bzip2-devel gcc gcc-c++ make 

解压包

tar zxvf haproxy-1.5.19.tar.gz

编译

cd haproxy-1.5.19/

make TARGET=linux26

make install 

mkdir /etc/haproxy

修改配置文件

cp examples/haproxy.cfg /etc/haproxy/

cd /etc/haproxy/

修改如下:

vim haproxy.cfg


# this config needs haproxy-1.1.28 or haproxy-1.2.1

global
        log /dev/log    local0 info
        log /dev/log    local0 notice
        #log loghost    local0 info
        maxconn 4096
        #chroot /usr/share/haproxy
        uid 99
        gid 99
        daemon
        #debug
        #quiet

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        retries 3

#       redispatch

​    maxconn 2000
​    contimeout      5000
​    clitimeout      50000
​    srvtimeout      50000

listen webcluster 0.0.0.0:80
        option httpchk GET /test.html
        balance roundrobin
        server inst1 192.168.209.132:80 check inter 2000 fall 3
        server inst2 192.168.209.133:80 check inter 2000 fall 3

添加权限并创建软连接,启动服务

cd 
cd haproxy-1.5.19/examples/

cp haproxy.init /etc/init.d/haproxy

cd /etc/init.d/

chmod +x haproxy

chkconfig --add /etc/init.d/haproxy

ln -s /usr/local/sbin/haproxy /usr/sbin/haproxy

service haproxy start

编写脚本文件

cd /etc/rsyslog.d/

vim haproxy.conf

if ($programname == 'haproxy' and $syslogseverity-text == 'info')
then -/var/log/haproxy/haproxy-info.log
&~
if ($programname == 'haproxy' and $syslogseverity-text == 'notice')
then -/var/log/haproxy/haproxy-notice.log
&~
启动服务
systemctl restart rsyslog.service
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值