大网数据广告活动
服务器运维问答

Import configuration files in haproxy.cfg

· 52CE 我爱测

I have almost 200 lines of ACL configurations in haprox.cfg and also contains 150 backends. To remove this configuration complexity, I want to bundle this configuration in separate files and will import those files in haprox.cfg …

问题原文

原帖链接 · user364875 · CC BY-SA 3.0

I have almost 200 lines of ACL configurations in haprox.cfg and also contains 150 backends. To remove this configuration complexity, I want to bundle this configuration in separate files and will import those files in haprox.cfg. Is this possible in haproxy?

已采纳解答

原帖链接 · HBruijn · CC BY-SA 3.0

As far as I know HAproxy does not have anything similar to apache's Include & IncludeOptional directives.

There is no native support for multiple configuration files other than starting HAproxy with repeated -f <config-file> command line switches. see this thread.

You can script something though to merge multiple subsections into a larger file similar to this approach although I would probably go the route and modify the init script to append additional configuration files automatically (untested):

# Load additional configuration snippets from /etc/haproxy.d/*.cfg
OPTIONS=""
for file in /etc/haproxy.d/*.cfg ; do test -f $file && OPTIONS="$OPTIONS -f $file" ; done

start() {
  /usr/sbin/$BASENAME -c -q -f /etc/$BASENAME/$BASENAME.cfg $OPTIONS
  if [ $? -ne 0 ]; then
    echo "Errors found in configuration file, check it with '$BASENAME check'."
    return 1
  fi

  echo -n "Starting $BASENAME: "
  daemon /usr/sbin/$BASENAME -D -f /etc/$BASENAME/$BASENAME.cfg $OPTIONS -p /var/run/$BASENAME.pid
  RETVAL=$?
  echo
  [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$BASENAME
  return $RETVAL
}

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-07-12)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。