EC2、AWS、Docker、Consul-Template、Consul、および NGINX を使用した一貫したサービス検出に問題があります。
複数のサービスがあり、それぞれが独自の EC2 インスタンスで実行されています。これらのインスタンスで、次のコンテナーを (この順序で) 実行します。
- cAdvisor(モニタリング)
- node-exporter (監視)
- Consul (エージェントモードで実行)
- 登録者
- 私のサービス
- nginx と consul-template の両方を実行するカスタム コンテナ
カスタム コンテナーには、次の Dockerfile があります。
FROM nginx:1.9
#Install Curl
RUN apt-get update -qq && apt-get -y install curl
#Install Consul Template
RUN curl -L https://github.com/hashicorp/consul-template/releases/download/v0.10.0/consul-template_0.10.0_linux_amd64.tar.gz | tar -C /usr/local/bin --strip-components 1 -zxf -
#Setup Consul Template Files
RUN mkdir /etc/consul-templates
COPY ./app.conf.tmpl /etc/consul-templates/app.conf
# Remove all other conf files from nginx
RUN rm /etc/nginx/conf.d/*
#Default Variables
ENV CONSUL consul:8500
CMD /usr/sbin/nginx -c /etc/nginx/nginx.conf && consul-template -consul=$CONSUL -template "/etc/consul-templates/app.conf:/etc/nginx/conf.d/app.conf:/usr/sbin/nginx -s reload"
app.conf ファイルは次のようになります。
{{range services}}
upstream {{.Name}} {
least_conn;{{range service .Name}}
server {{.Address}}:{{.Port}};{{end}}
}
{{end}}
server {
listen 80 default_server;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
location / {
proxy_pass http://cart/cart/;
}
location /cart {
proxy_pass http://cart/cart;
}
{{range services}}
location /api/{{.Name}} {
proxy_read_timeout 180;
proxy_pass http://{{.Name}}/{{.Name}};
}
{{end}}
}
すべてが完全に正常に起動するように見えますが、起動後のある時点 (まだ特定していません) で、consul-template は特定のサービスに使用できるサーバーがないと返すようです。これは、upstream
そのサービスのセクションにサーバーが含まれていないことを意味し、ログには次のように記録されます。
2015/12/04 07:09:34 [emerg] 77#77: no servers are inside upstream in /etc/nginx/conf.d/app.conf:336
nginx: [emerg] no servers are inside upstream in /etc/nginx/conf.d/app.conf:336
2015/12/04 07:09:34 [ERR] (runner) error running command: exit status 1
Consul Template returned errors:
1 error(s) occurred:
* exit status 1
2015/12/04 07:09:34 [DEBUG] (logging) setting up logging
2015/12/04 07:09:34 [DEBUG] (logging) config:
{
"name": "consul-template",
"level": "WARN",
"syslog": false,
"syslog_facility": "LOCAL0"
}
2015/12/04 07:09:34 [emerg] 7#7: no servers are inside upstream in /etc/nginx/conf.d/app.conf:336
nginx: [emerg] no servers are inside upstream in /etc/nginx/conf.d/app.conf:336
この後、NGINX はリクエストを受け付けなくなります。
明らかな何かが欠けていると確信していますが、一連のイベントなどについて精神的な結び目で自分自身を結びつけました。起こっている可能性があるのは、NGINX がクラッシュすることですが、consul-template がまだ実行されているため、Docker コンテナー再起動しません。コンテナー自体が再起動するか、NGINX だけが再起動するかは実際には気にしません。
誰か助けてくれませんか?