OpenStack Cinder服務(wù)狀態(tài)排錯(cuò)
本文轉(zhuǎn)載自微信公眾號(hào)「新鈦云服」,作者舒祝 。轉(zhuǎn)載本文請(qǐng)聯(lián)系新鈦云服公眾號(hào)。
最近手動(dòng)搭建了一個(gè)openstack環(huán)境,創(chuàng)建硬盤時(shí)失敗,查看日志,提示無法進(jìn)行調(diào)度,懷疑是cinder節(jié)點(diǎn)出現(xiàn)問題,去cinder節(jié)點(diǎn)查看服務(wù) ,狀態(tài)顯示正常。
- systemctl status openstack-cinder-volume.service
然后在控制節(jié)點(diǎn)查看cinder服務(wù),openstack volume service list
正常情況下顯示:
結(jié)果顯示cinder-volume的state為down,查看日志發(fā)現(xiàn)沒有任何錯(cuò)誤信息,重啟cinder的各種服務(wù)仍然沒有效果,最后決定跟蹤源碼(說明:文中代碼對(duì)應(yīng)的是OpenStack Train版)。
找到openstack volume service list對(duì)應(yīng)的實(shí)現(xiàn)代碼。
- now = timeutils.utcnow(with_timezone=True)
由于openstack-cinder-api.servic服務(wù)在controller節(jié)點(diǎn)啟動(dòng),所以獲取的是controller節(jié)點(diǎn)的當(dāng)前時(shí)間。
services = objects.ServiceList.get_all(context, filters)最終會(huì)從cinder數(shù)據(jù)庫的services表中獲取所有服務(wù)數(shù)據(jù)。
alive = abs(delta_sec) <= CONF.service_down_time,比較時(shí)間差的絕對(duì)值是否小于配置的service_down_time,其中service_down_time默認(rèn)時(shí)間是60s。
- cfg.IntOpt('service_down_time',
- default=60,
- help='Maximum time since last check-in for a service to be '
- 'considered up'),
art = "up" if alive else "down" 差值小于60,則service 狀態(tài)為 up,否則為down。由此可見cinder service的state值取決于cinder數(shù)據(jù)庫中 service 表每行數(shù)據(jù)的 updated_at 列的值和當(dāng)前 controller 節(jié)點(diǎn)的時(shí)間差是否在配置的范圍之內(nèi)。
解決問題
上面cinder-volume出現(xiàn)down的原因就是因?yàn)檫\(yùn)行openstack-cinder-volume.service服務(wù)的存儲(chǔ)節(jié)點(diǎn)時(shí)間與controller節(jié)點(diǎn)時(shí)間差值過大。為了保證狀態(tài)為up,必須保證兩節(jié)點(diǎn)的時(shí)間差在service_down_time - report_interval之內(nèi),默認(rèn)情況下,差值為50秒。所以同步兩臺(tái)服務(wù)器時(shí)間之后,再次查看,發(fā)現(xiàn)cinder-volume的state變?yōu)閡p。
cinder服務(wù)更新機(jī)制
下面說下 Cinder Service 的更新機(jī)制。
report_interval默認(rèn)時(shí)間是10s,
- cfg.IntOpt('report_interval',
- default=10,
- help='Interval, in seconds, between nodes reporting state '
- 'to datastore'),