Centos7

為什麼 Uchiwa 無法在 CentOS7 上監控數據中心?

  • May 17, 2017

這篇文章使用 YUM 安裝 Sensu相結合,用於安裝、配置和啟動 Sensu 及相關服務:

sudo yum install -y erlang && \
sudo rpm -Uvh http://www.rabbitmq.com/releases/rabbitmq-server/v3.5.0/rabbitmq-server-3.5.0-1.noarch.rpm && \
sudo yum install -y redis && \
echo '[sensu]
name=sensu
baseurl=http://sensu.global.ssl.fastly.net/yum/$basearch/
gpgcheck=0
enabled=1' | sudo tee /etc/yum.repos.d/sensu.repo && \
sudo yum install -y sensu && \
sudo yum install -y uchiwa && \
for s in rabbitmq-server redis.service sensu-server sensu-api uchiwa; do sudo systemctl restart $s; done && \
sudo rabbitmqctl add_vhost /sensu && \
sudo rabbitmqctl add_user sensu secret && \
sudo rabbitmqctl set_permissions -p /sensu sensu ".*" ".*" ".*"

分析

  • 導航到 :3000 顯示 uchiwa 儀表板並指示Connection error. Is the Sensu API running?
  • /var/log/sensu/sensu-api.log 表示

{"timestamp":"2016-07-03T22:58:58.532905+0000","level":"warn","message":"config file does not exist or is not readable","file":"/etc/sensu/config.json"}
{"timestamp":"2016-07-03T22:58:58.533069+0000","level":"warn","message":"ignoring config file","file":"/etc/sensu/config.json"}
{"timestamp":"2016-07-03T22:58:58.533137+0000","level":"warn","message":"loading config files from directory","directory":"/etc/sensu/conf.d"}
{"timestamp":"2016-07-03T22:58:58.712175+0000","level":"info","message":"api listening","protocol":"http","bind":"0.0.0.0","port":4567}

  • config.json 似乎不存在(/etc/sensu/config.json: No such file or directory
  • 下載範例 config.json並重新啟動 sensu-api 並沒有解決問題

{
 "rabbitmq": {
   "host": "localhost",
   "vhost": "/sensu",
   "user": "sensu",
   "password": "secret"
 },
 "redis": {
   "host": "localhost",
   "port": 6379,
   "password": "secret"
 }
}

  • redis埠正在監聽:

LISTEN     0      128    127.0.0.1:6379                     *:*

  • rabbitmq 埠:

LISTEN     0      100          *:4567                     *:* 
  • Uchiwa 無法連接到數據中心

{
 "sensu": [
   {
     "name": "Site 1",
     "host": "localhost",
     "port": 4567,
     "timeout": 10
   },
   {
     "name": "Site 2",
     "host": "localhost",
     "port": 4567,
     "ssl": false,
     "path": "",
     "user": "",
     "pass": "",
     "timeout": 10
   }
 ],
 "uchiwa": {
   "host": "0.0.0.0",
   "port": 3000,
   "refresh": 10
 }
}

{"timestamp":"2016-07-03T23:34:32.990067621Z","level":"warn","message":"GET http://localhost:4567/stashes returned: 500 Internal Server Error"}
{"timestamp":"2016-07-03T23:34:32.990102095Z","level":"warn","message":"Connection failed to the datacenter Site 1"}
{"timestamp":"2016-07-03T23:34:32.990115588Z","level":"info","message":"Updating the datacenter Site 2"}
{"timestamp":"2016-07-03T23:34:32.991462585Z","level":"warn","message":"GET http://localhost:4567/stashes returned: 500 Internal Server Error"}
{"timestamp":"2016-07-03T23:34:32.991492978Z","level":"warn","message":"Connection failed to the datacenter Site 2"}

  • 導航到<IPADDRESS>:4567結果:

{"error":"redis and transport connections not initialized"}

  • redis 回复

sudo redis-cli ping
PONG

  • redis密碼已設置,但問題仍然存在

sudo redis-cli
127.0.0.1:6379> auth secret
OK

簡潔的

sensu-client似乎需要rabbitmq-server執行. 由於此消息代理似乎沒有執行,sensu-client因此無法啟動,Uchiwa 儀表板也無法對其進行監控。

詳細

如果出現以下錯誤:

{"error":"redis and transport connections not initialized"}

顯示並redis正在偵聽,請檢查它rabbitmq是否正在執行並使用 rabbitmq-status 檢查 rabbitmq 埠:

sudo systemctl status rabbitmq-server

例子

今天出現了上述錯誤,當檢查 rabbitmq 埠時,似乎某個埠沒有在監聽:

{listeners,[{clustering,25672,"::"},{amqp,5672,"::"}},

配置 SSL 後,埠 5671 應配置為/etc/rabbitmq.config. 重新啟動消息代理伺服器後,ssl 埠5671開始偵聽並解決了問題:

{listeners,[{clustering,25672,"::"},{amqp,5672,"::"},{'amqp/ssl',5671,"::"}]},

我的 rabbitmq 配置是:

[
{rabbit, [ 
{ssl_listeners, [5671]},
{ssl_options, [{cacertfile,"/etc/rabbitmq/ssl/cacert.pem"},
              {certfile,"/etc/rabbitmq/ssl/cert.pem"},
              {keyfile,"/etc/rabbitmq/ssl/key.pem"},
              {verify,verify_peer},
              {fail_if_no_peer_cert,true}]}
]}
 ].

引用自:https://serverfault.com/questions/787703