在haproxy.cfg中导入configuration文件

我在haprox.cfg有近200行ACLconfiguration,还包含150个后端。 为了消除这种configuration的复杂性,我想把这个configuration绑定在单独的文件中,并将这些文件导入到haprox.cfg 。 这在haproxy中可能吗?

据我所知HAproxy没有类似于Apache的Include & IncludeOptional指令。

除了使用重复的-f <config-file>命令行开关启动HAproxy以外,没有对多个configuration文件的本机支持。 看到这个线程 。

尽pipe我可能会去路由并修改init脚本以自动添加额外的configuration文件(未经testing),但您可以编写脚本来将多个小节合并为一个类似于此方法的较大文件:

 # 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 }