溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么

發(fā)布時(shí)間:2021-12-01 16:52:41 來(lái)源:億速云 閱讀:178 作者:柒染 欄目:云計(jì)算

這期內(nèi)容當(dāng)中小編將會(huì)給大家?guī)?lái)有關(guān) 關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么,文章內(nèi)容豐富且以專業(yè)的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

環(huán)境:centos6.5 openstack ice版

1、

關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么


2、

關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么


3、

vim /usr/bin/nova-manage

關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么


load_entry_point('nova==2014.1.1', 'console_scripts', 'nova-manage')()

第一個(gè)參數(shù)定向到 /usr/lib/python2.6/site-packages/nova-2014.1.1-py2.6.egg-info/

然后搜索EGG-INFO/entry_points.txt

 vim /usr/lib/python2.6/site-packages/nova-2014.1.1-py2.6.egg-info/entry_points.txt 

關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么


搜索

load_entry_point('nova==2014.1.1', 'console_scripts', 'nova-manage')()

第二、第三個(gè)參數(shù):

console_scripts、nova-manage

關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么


得到入口地址為:

nova-manage = nova.cmd.manage:main


4、

關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么



關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么


關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么


5、

關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么



 @args('--host', metavar='<host>', help='Host')

    @args('--service', metavar='<service>', help='Nova service')

    def list(self, host=None, service=None):

        """Show a list of all running services. Filter by host & service

        name

        """

        servicegroup_api = servicegroup.API()

        ctxt = context.get_admin_context()

        services = db.service_get_all(ctxt)  #獲取nova service數(shù)據(jù)庫(kù)表所有數(shù)據(jù)

        services = availability_zones.set_availability_zones(ctxt, services)

        if host:

            services = [s for s in services if s['host'] == host]

        if service:

            services = [s for s in services if s['binary'] == service]

        print_format = "%-16s %-36s %-16s %-10s %-5s %-10s"

        print(print_format % ( #此處打印出圖1.1

                    _('Binary'),

                    _('Host'),

                    _('Zone'),

                    _('Status'),

                    _('State'),

                    _('Updated_At')))

        for svc in services:

            alive = servicegroup_api.service_is_up(svc)  #檢測(cè)服務(wù)是否為alive 、重點(diǎn)解析此處的代碼根據(jù)

            art = (alive and ":-)") or "XXX"

            active = 'enabled'

            if svc['disabled']:

                active = 'disabled'

            print(print_format % (svc['binary'], svc['host'],

                                  svc['availability_zone'], active, art,

                                  svc['updated_at']))


圖1.1:

關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么


6、 service_is_up:(根據(jù)到7講解is_up函數(shù))

關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么

關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么


注:大家可以再下圖中看到,判斷服務(wù)狀態(tài),可以有多重方式,有db、還有zookeeper等。從上圖可知本次中使用的為db檢查服務(wù)狀態(tài)。

關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么


7、講解is_up函數(shù):


 

關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么



    def is_up(self, service_ref):

        """Moved from nova.utils

        Check whether a service is up based on last heartbeat.

        """

        last_heartbeat = service_ref['updated_at'] or service_ref['created_at']  #獲取服務(wù)最后一次更新時(shí)間,或者第一次創(chuàng)建時(shí)間,最為心跳時(shí)間

         if isinstance(last_heartbeat, six.string_types):  #此處代碼就是將上面獲取的心跳時(shí)間,轉(zhuǎn)換成datetime時(shí)間

            # NOTE(russellb) If this service_ref came in over rpc via

            # conductor, then the timestamp will be a string and needs to be

            # converted back to a datetime.

            last_heartbeat = timeutils.parse_strtime(last_heartbeat)

        else:

            # Objects have proper UTC timezones, but the timeutils comparison

            # below does not (and will fail)

            last_heartbeat = last_heartbeat.replace(tzinfo=None)

        # Timestamps in DB are UTC.

        elapsed = timeutils.delta_seconds(last_heartbeat, timeutils.utcnow())  #此處計(jì)算出心跳時(shí)間與當(dāng)前時(shí)間的差值

        LOG.debug('DB_Driver.is_up last_heartbeat = %(lhb)s elapsed = %(el)s',

                  {'lhb': str(last_heartbeat), 'el': str(elapsed)})

        return abs(elapsed) <= CONF.service_down_time#此處根據(jù)差值來(lái)判斷服務(wù)是否正常(比較時(shí)間為配置文件配置。如下圖:)

關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么


nova.conf中:

關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么


所以最近更新時(shí)間,或者第一次創(chuàng)建時(shí)間與當(dāng)前時(shí)間間隔少于CONF.service_down_time(60秒),則認(rèn)為服務(wù)alive

從這里也可以得知為什么控制節(jié)點(diǎn)和計(jì)算節(jié)點(diǎn)的時(shí)間要一致。


接下來(lái)試驗(yàn)驗(yàn)證一下:

關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么

關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么


現(xiàn)在強(qiáng)制修改數(shù)據(jù)庫(kù)表中nova-compute的update_at時(shí)間:

由2014-08-04 23:51:24修改為:2014-08-04 22:51:24


關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么


再來(lái)查看狀態(tài):

關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么

上述就是小編為大家分享的 關(guān)于nova-manage service list檢測(cè)服務(wù)狀態(tài)原理 是什么了,如果剛好有類似的疑惑,不妨參照上述分析進(jìn)行理解。如果想知道更多相關(guān)知識(shí),歡迎關(guān)注億速云行業(yè)資訊頻道。

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI