天天看點

解決mv指令導緻的cman啟動失敗問題

  參考資料: https://bugzilla.redhat.com/show_bug.cgi?format=multiple&id=667703                      http://www.qingsword.com/qing/1086.html

  今天使用cman來管理叢集,在啟動時報錯,錯誤資訊如下:

[[email protected]____102 ~] # service cman start

Starting cluster : 

   Checking if cluster has been disabled at boot...        [  OK  ]

   Checking Network Manager...                             [  OK  ]

   Global setup...                                         [  OK  ]

   Loading kernel modules...                               [  OK  ]

   Mounting configfs...                                    [  OK  ]

   Starting cman... I /O warning : failed to load external entity "/etc/cluster/cluster.conf"

Unable to get the configuration

I /O warning : failed to load external entity "/etc/cluster/cluster.conf"

corosync [MAIN  ] Corosync Cluster Engine ( '1.4.1') : started and ready to provide service.

corosync [MAIN  ] Corosync built - in features : nss dbus rdma snmp

corosync [MAIN  ] Unable to read config from /etc /cluster /cluster.conf

corosync [MAIN  ] Corosync Cluster Engine exiting with status 8 at main.c : 1695.

corosync died : Could not read cluster configuration Check cluster logs for details

                                                           [FAILED]

Stopping cluster : 

   Leaving fence domain...                                 [  OK  ]

   Stopping gfs_controld...                                [  OK  ]

   Stopping dlm_controld...                                [  OK  ]

   Stopping fenced...                                      [  OK  ]

   Stopping cman...                                        [  OK  ]

   Unloading kernel modules...                             [  OK  ]

   Unmounting configfs...                                  [  OK  ]

[[email protected]____102 ~] #   産生問題的原因是corosync無法讀取配置檔案/etc/cluster/cluster.conf,檔案屬性如下所示:

[[email protected]____102 ~] # ls -l /etc/cluster/cluster.conf 

-rw -r --r --. 1 root root 995 Oct 30 16 : 30 /etc /cluster /cluster.conf   這個檔案權限在機器A(192.168.56.101)是沒有問題的,出問題的是機器B(192.168.56.102)。   機器B上的檔案是使用scp指令從機器A上先拷貝到機器B的/root目錄下,然後使用mv指令移到/etc/cluster目錄的。之是以出現這樣的問題,是因為在機器B上檔案是/root目錄下建立的,在使用mv指令移動這個檔案的時候會加上admin_home_t label,如下所示:

 [[email protected]____102 ~] # ls -Z /etc/cluster/cluster.conf 

-rw -r --r --. root root unconfined_u :object_r :admin_home_t :s0 /etc /cluster /cluster.conf   因為這個label的存在,SELinux會阻止corosync讀取這個檔案,admin_home_t表示這個檔案是root使用者目錄下的檔案。之是以打不開是因為cluster.conf檔案的SELinux配置資訊是繼承原來那個目錄的,與/etc/cluster目錄不同。檢視SELinux的日志資訊(日志檔案位置為/var/log/audit/audit.log),可以看到下面的内容:

22109 type =AVC msg =audit( 1383121897. 046 : 28821) : avc :  denied  { getattr } for  pid = 2645 comm = "corosync" path = "/etc/cluster/cluster.conf" dev =sda2 ino = 1311842 scontext =unconfined_u :system_r :corosync_t :s0 tcontext =unconfined_u :object_r :admin_home_t :s0 tclass =file   正确的SELinux配置資訊是scontext對應的内容,它描述了corosync程序的SELinux上下文,其中unconfined_u表示的是SELinux使用者,這裡的就是沒有限制特定的使用者。system_r表示corosync是一個程序,corosync_t是它的類型(或者叫域),每個程序或檔案都有一個類型。cluster.conf的SELinux上下文由tcontext描述,第一個字段表示沒有限制特定的使用者,第二個字段表示她是一個目錄或檔案,第三個字段則是它的類型,這個類型隻有root使用者才可以通路。   現在知道了問題原因,要解決這個問題見就很簡單了。最容易想到的方法就是關閉SELinux。如果不想關閉SELinux,可以使用下面的指令恢複原來的檔案标簽,如下所示:

[[email protected]____102 ~] # restorecon -v /etc/cluster/cluster.conf 

restorecon reset /etc /cluster /cluster.conf context unconfined_u :object_r :admin_home_t :s0 - >unconfined_u :object_r :cluster_conf_t :s0   恢複後再使用ls -Z指令檢視檔案的資訊,和機器A上的一樣。修改後重新啟動cman服務正常。

繼續閱讀