問題現象
在下面這張圖中我們可以看到有一個Compute是Down的。
這個時候的第一印象是Compute的掛掉了。但是檢查的時候有時會發現Compute並沒有掛掉,nova-compute服務也跑的好好的。
問題分析
這個情況基本上是由於時間不同步導致的。
在/etc/nova.conf中有如下配置,默認的service_down_time是60秒。
# Maximum time since last check-in for up service (integer value)
# service_down_time=60
在nova.servicegroup.drivers.db中有如下處理用於判斷服務的狀態是up還是down的。
class DbDriver(base.Driver):
def __init__(self, *args, **kwargs):
self.service_down_time = CONF.service_down_time
...
def is_up(self, service_ref):
"""Moved from nova.utils
Check whether a service is up based on last heartbeat.
"""
...
elapsed = timeutils.delta_seconds(last_heartbeat, timeutils.utcnow())
is_up = abs(elapsed) <= self.service_down_time
...
...
從上可以看到,在默認的配置下,如果Compute比Controller慢了1分鐘以上,那即使Controller能不斷的收到Compute上報的信息。但還是會認爲Compute是Down的。
安裝配置NTP
安裝
yum install ntp ntpdate
同步時間
# Sync time with server
ntpdate <server>
# Set the Hardware Clock to the current System Time
clock -w
配置/etc/ntp.conf
server <server>
restrict 127.0.0.1
restrict -6 ::1
restrict <server> mask 255.255.255.255 nomodify notrap noquery
driftfile /var/lib/ntp/drift
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
啓動ntp服務
systemctl start ntpd
systemctl enable ntpd