温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么设定master特性

发布时间:2022-01-05 09:26:38 来源:亿速云 阅读:141 作者:iii 栏目:大数据

本篇内容介绍了“怎么设定master特性”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

9 特殊考虑

9.1 Licensing

任何时候,我们都鼓励开发者使用GPL (GNU GeneralPublic License) 2.0 或者更新的版本。shell库函数不严格限制于此,它是基于LGPL( GNU Lesser General Public License)版本2.1 或更新版本的,这样non-GPL的资源的代理可以使用。

资源代理必须在源代码显式的标明其授权信息。

9.2 本地设定

当运行 .ocf-shellfuncs(4.3节初始化有说明),资源代理自动设定LANG 和 LC_ALL到C的区域设置。资源代理可以期待总是在C的区域设置里操作,不需要重置LANG和LC_ 环境变量。

9.3 测试运行进程

测试一个指定的进程(知道进程id)是否正在运行,通常的做法是发送一个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

重要:一种远优于上述做法的例子是使用一个守护进程的客户端调用一个守护进程的功能,如5.3节 monitor action的例子。

9.4 设定master特性

有状态(master/slave)资源必须设定其自己的master特性,这些特性会为集群管理提供一些信息,帮助它确定谁是最合适提升为master角色的节点。

重要:多个实例拥有相同的master特性是可以接受的。在那个例子中,集群资源管理器可以自动选择一个资源代理去提升为master角色。如果所有的实例都有缺省的master分值0的话,集群管理器不提升任何实例。这样,重要的是,至少保持一个实例的master分值为正。

为此目标,crm_master 比较方便。它封装了crm_attribute来设置其运行节点上的属性 master-$OCF_RESOURCE_INSTANCE为一个特定的值。集群管理器会将相应实例的这些改变转换为提升分数,其提升的特征基于此。

有状态的资源代理在monitor和notity行为时执行crm_master。

下面的例子假设foobar资源代理可以通过执行一个有返回值的执行文件测试应用的状态。这个返回值取决于是否:

  • 资源是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特性”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI