溫馨提示×

溫馨提示×

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

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

怎么設定master特性

發(fā)布時間:2022-01-05 09:26:38 來源:億速云 閱讀:154 作者:iii 欄目:大數據

本篇內容介紹了“怎么設定master特性”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

9 特殊考慮

9.1 Licensing

任何時候,我們都鼓勵開發(fā)者使用GPL (GNU GeneralPublic License) 2.0 或者更新的版本。shell庫函數不嚴格限制于此,它是基于LGPL( GNU Lesser General Public License)版本2.1 或更新版本的,這樣non-GPL的資源的代理可以使用。

資源代理必須在源代碼顯式的標明其授權信息。

9.2 本地設定

當運行 .ocf-shellfuncs(4.3節(jié)初始化有說明),資源代理自動設定LANG 和 LC_ALL到C的區(qū)域設置。資源代理可以期待總是在C的區(qū)域設置里操作,不需要重置LANG和LC_ 環(huán)境變量。

9.3 測試運行進程

測試一個指定的進程(知道進程id)是否正在運行,通常的做法是發(fā)送一個0信號并捕獲錯誤。比如:

1

2

3

4

5

6

if kill -s 0  `cat $daemon_pid_file`; then

   ocf_log  debug "Process is currently running"

else

   ocf_log  warn "Process is dead, removing pid file"

   rm -f  $daemon_pid_file

if

重要:一種遠優(yōu)于上述做法的例子是使用一個守護進程的客戶端調用一個守護進程的功能,如5.3節(jié) monitor action的例子。

9.4 設定master特性

有狀態(tài)(master/slave)資源必須設定其自己的master特性,這些特性會為集群管理提供一些信息,幫助它確定誰是最合適提升為master角色的節(jié)點。

重要:多個實例擁有相同的master特性是可以接受的。在那個例子中,集群資源管理器可以自動選擇一個資源代理去提升為master角色。如果所有的實例都有缺省的master分值0的話,集群管理器不提升任何實例。這樣,重要的是,至少保持一個實例的master分值為正。

為此目標,crm_master 比較方便。它封裝了crm_attribute來設置其運行節(jié)點上的屬性 master-$OCF_RESOURCE_INSTANCE為一個特定的值。集群管理器會將相應實例的這些改變轉換為提升分數,其提升的特征基于此。

有狀態(tài)的資源代理在monitor和notity行為時執(zhí)行crm_master。

下面的例子假設foobar資源代理可以通過執(zhí)行一個有返回值的執(zhí)行文件測試應用的狀態(tài)。這個返回值取決于是否:

  • 資源是master角色或者是slave角色(被master完全捕獲),或者

  • 資源是slave角色,但是因為異步復制的原因,落后于master,或者

  • 資源安全的停止了,或者

  • 資源意外地失效了


2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

foobar_monitor() {

   local rc


   # exit  immediately if configuration is not valid

   foobar_validate_all  || exit $?


   ocf_run  frobnicate --test


   # This example  assumes the following exit code convention

   # for frobnicate:

   # 0: running, and  fully caught up with master

   # 1: gracefully  stopped

   # 2: running, but  lagging behind master

   # any other:  error

   case "$?" in

       0)

           rc=$OCF_SUCCESS

           ocf_log  debug "Resource is running"

           #  Set a high master preference. The current master

           #  will always get this, plus 1. Any current slaves

           #  will get a high preference so that if the master

           #  fails, they are next in line to take over.

           crm_master  -l reboot -v 100

           ;;

       1)

           rc=$OCF_NOT_RUNNING

           ocf_log  debug "Resource is not running"

           #  Remove the master preference for this node

           crm_master  -l reboot -D

           ;;

       2)

           rc=$OCF_SUCCESS

           ocf_log  debug "Resource is lagging behind master"

           #  Set a low master preference: if the master fails

           #  right now, and there is another slave that does

           #  not lag behind the master, its higher master

           #  preference will win and that slave will become

           #  the new master

           crm_master  -l reboot -v 5

           ;;

       *)

           ocf_log  err "Resource has failed"

           exit $OCF_ERR_GENERIC

   esac


   return $rc

}

“怎么設定master特性”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關的知識可以關注億速云網站,小編將為大家輸出更多高質量的實用文章!

向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI