SRS流媒体小型集群搭建(2)-haproxy的安装和配置

haproxy是安装在172.20.1.44上的,用于负载源站。

系统是centos7.5。

安装前也在网上查了一些资料,yum安装的haproxy版本比较低,不过足够用来负载源站了,暂时不考虑make&install更高版本,图方便😊。

1.yum查询版本

yum list |grep haproxy
#查询下可用版本
#果然 haproxy.x86_64 1.5.18-8.el7  base
#对付用先

2.yum安装

yum -y install haproxy
#已安装:
#  haproxy.x86_64 0:1.5.18-9.el7_9.1                                                                                                                           
#完毕!

3.配置配置文件

#配置文件位置
cd /etc/haproxy/haproxy.cfg 
#其实就是注释掉了我不需要的,主配置没动,添加了源站转发



#---------------------------------------------------------------------
# Example configuration for a possible web application.  See the
# full configuration options online.
#
#   http://haproxy.1wt.eu/download/1.4/doc/configuration.txt
#
#---------------------------------------------------------------------

#---------------------------------------------------------------------
# Global settings
#---------------------------------------------------------------------
global
    # to have these messages end up in /var/log/haproxy.log you will
    # need to:
    #
    # 1) configure syslog to accept network log events.  This is done
    #    by adding the '-r' option to the SYSLOGD_OPTIONS in
    #    /etc/sysconfig/syslog
    #
    # 2) configure local2 events to go to the /var/log/haproxy.log
    #   file. A line like the following can be added to
    #   /etc/sysconfig/syslog
    #
    #    local2.*                       /var/log/haproxy.log
    #
    log         127.0.0.1 local2

    chroot      /var/lib/haproxy
    pidfile     /var/run/haproxy.pid
    maxconn     4000
    user        haproxy
    group       haproxy
    daemon

    # turn on stats unix socket
    stats socket /var/lib/haproxy/stats

#---------------------------------------------------------------------
# common defaults that all the 'listen' and 'backend' sections will
# use if not designated in their block
#---------------------------------------------------------------------
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

#---------------------------------------------------------------------
# main frontend which proxys to the backends
#---------------------------------------------------------------------
#frontend  main *:5000
#    acl url_static       path_end       -i .jpg .gif .png .css .js

#    use_backend static          if url_static
#    default_backend             app

#---------------------------------------------------------------------
# static backend for serving up images, stylesheets and such
#---------------------------------------------------------------------
#backend static
#    balance     roundrobin
 #   server      static 127.0.0.1:4331 check

#---------------------------------------------------------------------
# round robin balancing between the various backends
#---------------------------------------------------------------------
#backend app
#    balance     roundrobin
#    server  app1 127.0.0.1:5001 check
#    server  app2 127.0.0.1:5002 check
#    server  app3 127.0.0.1:5003 check
#    server  app4 127.0.0.1:5004 check

listen srs-cluster
    bind *:1935
    mode tcp
    balance roundrobin
    server master1 172.20.1.46:1935
    server master2 172.20.1.47:1935

关键点就是最后两台源站服务器的地址和端口,因为我是单机部署,所以端口一致,如果想一台服务器部署多个SRS也是可以的,最好用Docker,可以参考官文。

4.验证配置文件

haproxy -f /etc/haproxy/haproxy.cfg -c

发现有警告

#返回
[WARNING] 207/225605 (31197) : parsing [/etc/haproxy/haproxy.cfg:45] : 'option httplog' not usable with proxy 'srs-cluster' (needs 'mode http'). Falling back to 'option tcplog'.
[WARNING] 207/225605 (31197) : config : 'option forwardfor' ignored for proxy 'srs-cluster' as it requires HTTP mode.
Configuration file is valid

默认的mode和log忘记改了,改成tcp和tcplog。验证还是有用的。

 另一个警告,意思就是 forwardfor需要http模式,所以忽略了(咱用了tcp呀)。

5.启动haproxy

systemctl start haproxy

6.重启haproxy

systemctl restart haproxy

接下来部署两台源站。

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

My的梦想已实现

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值