①故障现象
场景:
- 基于 nginx 与 consul 构建自动发现即高可用的 Docker 服务架构
- 在 consul 群集添加 compose-template 以实现容器自动加入时,无法正常启动template(指定template模板文件及生成路径)
[root@docker consul]# consul-template -consul-addr 192.168.126.16:8500 -template "/root/consul/nginx.ctmpl:/usr/local/nginx/conf/vhost/xcf.conf:/usr/local/nginx/sbin/nginx -s reload" --log-level=info
2021/03/27 14:15:37.803675 [INFO] consul-template v0.19.3 (ebf2d3d)
2021/03/27 14:15:37.803712 [INFO] (runner) creating new runner (dry: false, once: false)
2021/03/27 14:15:37.804468 [INFO] (runner) creating watcher
2021/03/27 14:15:37.804577 [ERR] (cli) failed to read template: open /root/consul/nginx.ctmpl: no such file or directory '//报错'
②解决思路
- 前面的部署过程都没有问题,再检查下配置文件是否有手误,报错提示读取模板失败,没有这个文件或目录
- template nginx 模板文件在 VIM 进去时因没有进入编辑模式“i”就直接copy,导致首部开头少了几个字母,不过修改回来后仍旧不能正常启动,pass!
- netstat 检查 nginx 已正常开启,这里我杀掉进程再次开启 nginx,仍旧不行,pass!
- 最后检查下模板文件 nginx.ctmpl,最后发现是指定绝对路径的问题,应该改为“/consul,而不是/root/consul”,唉!
[root@docker consul]# consul-template -consul-addr 192.168.126.16:8500 -template "/consul/nginx.ctmpl:/usr/local/nginx/conf/vhost/xcf.conf:/usr/local/nginx/sbin/nginx -s reload" --log-level=info
2021/03/27 14:15:50.574341 [INFO] consul-template v0.19.3 (ebf2d3d)
2021/03/27 14:15:50.574366 [INFO] (runner) creating new runner (dry: false, once: false)
2021/03/27 14:15:50.574773 [INFO] (runner) creating watcher
2021/03/27 14:15:50.574932 [INFO] (runner) starting
2021/03/27 14:15:50.574953 [INFO] (runner) initiating run
2021/03/27 14:15:50.577802 [INFO] (runner) initiating run
'竟无语凝噎'