欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

CentOS 7系統(tǒng)下SELinux阻止MongoDB啟動的問題詳解

 更新時間:2017年11月10日 10:22:40   作者:mydeman  
這篇文章主要給大家介紹了關(guān)于CentOS 7系統(tǒng)下SELinux阻止MongoDB啟動問題的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧。

問題描述:

最近發(fā)現(xiàn)了一個問題,在新裝的CentOS7上,安裝了MongoDB3.4,掛載了一個大的數(shù)據(jù)盤后,修改/etc/mongo.conf,將配置文件中的log和data目錄放在新的數(shù)據(jù)盤下,并修改文件的訪問權(quán)限。

改完后的mongo.conf:

# mongod.conf

# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/

# where to write logging data.
systemLog:
 destination: file
 logAppend: true
 path: /data/mongodb/log/mongod.log

# Where and how to store data.
storage:
 dbPath: /data/mongodb/data
.....

文件權(quán)限:

# ls -alh
drwxr-xr-x. 5 mongod mongod 4.0K 11月 1 14:53 mongodb

# cd mongodb
# ls -alh
drwxr-xr-x. 3 mongod mongod 4.0K 11月 9 19:08 data
drwxr-xr-x. 2 mongod mongod 4.0K 11月 9 19:06 log
drwxr-xr-x. 2 mongod mongod 4.0K 11月 1 14:54 run

執(zhí)行systemctl start mongod命令后,查看狀態(tài)發(fā)現(xiàn)并沒有啟動,查看/var/log/message,發(fā)現(xiàn)以下錯誤

Nov 9 06:06:44 [localhost] setroubleshoot: failed to retrieve rpm info for /data/mongodb/run/mongod.pid
Nov 9 06:06:44 [localhost] setroubleshoot: SELinux is preventing /usr/bin/mongod from write access on the file /data/mongodb/run/mongod.pid. For complete SELinux messages run: sealert -l f7148e11-b126-401e-ba9f-a9a87c1e54ae
Nov 9 06:06:44 [localhost] python: SELinux is preventing /usr/bin/mongod from write access on the file /data/mongodb/run/mongod.pid.#012#012***** Plugin restorecon (94.8 confidence) suggests ************************#012#012If you want to fix the label. #012/data/mongodb/run/mongod.pid default label should be default_t.#012Then you can run restorecon.#012Do#012# /sbin/restorecon -v /data/mongodb/run/mongod.pid#012#012***** Plugin catchall_labels (5.21 confidence) suggests *******************#012#012If you want to allow mongod to have write access on the mongod.pid file#012Then you need to change the label on /data/mongodb/run/mongod.pid#012Do#012# semanage fcontext -a -t FILE_TYPE '/data/mongodb/run/mongod.pid'#012where FILE_TYPE is one of the following: afs_cache_t, initrc_tmp_t, mongod_log_t, mongod_tmp_t, mongod_var_lib_t, mongod_var_run_t, puppet_tmp_t, user_cron_spool_t.#012Then execute:#012restorecon -v '/data/mongodb/run/mongod.pid'#012#012#012***** Plugin catchall (1.44 confidence) suggests **************************#012#012If you believe that mongod should be allowed write access on the mongod.pid file by default.#012Then you should report this as a bug.#012You can generate a local policy module to allow this access.#012Do#012allow this access for now by executing:#012# ausearch -c 'mongod' --raw | audit2allow -M my-mongod#012# semodule -i my-mongod.pp#012

從提示中可以看出是SELinux的防護功能,阻止了訪問。

SELinux

SELinux的全稱是Security Enhanced Linux, 就是安全加強的Linux。在SELinux之前,root賬號能夠任意的訪問所有文檔和服務(wù);如果某個文件設(shè)為777,那么任何用戶都可以訪問甚至刪除;這種方式稱為DAC(主動訪問機制),很不安全。

DAC 自主訪問控制: 用戶根據(jù)自己的文件權(quán)限來決定對文件的操作,也就是依據(jù)文件的own,group,other/r,w,x權(quán)限進行限制。Root有最高權(quán)限無法限制。r,w,x權(quán)限劃分太粗糙。無法針對不同的進程實現(xiàn)限制。

SELinux則是基于MAC(強制訪問機制),簡單的說,就是程序和訪問對象上都有一個安全標簽(即selinux上下文)進行區(qū)分,只有對應(yīng)的標簽才能允許訪問。否則即使權(quán)限是777,也是不能訪問的。

在SELinux中,訪問控制屬性叫做安全上下文。所有客體(文件、進程間通訊通道、套接字、網(wǎng)絡(luò)主機等)和主體(進程)都有與其關(guān)聯(lián)的安全上下文,一個安全上下文由三部分組成:用戶(u)、角色(r)和類型(t)標識符。但我們最關(guān)注的是第三個部分

當程序訪問資源時,主體程序必須要通過selinux策略內(nèi)的規(guī)則放行后,就可以與目標資源進行安全上下文的比對,若比對失敗則無法存取目標,若比對成功則可以開始存取目標,最終能否存取目標還要與文件系統(tǒng)的rwx權(quán)限的設(shè)定有關(guān)。所以啟用了selinux后出現(xiàn)權(quán)限不符的情況時,你就得一步一步的分析可能的問題了。

解決過程:

/var/log/message中的信息看起來比較費勁,里面有一句提示:

For complete SELinux messages run: sealert -l e73ba9e8-f74d-4835-9b53-85667546b28c

根據(jù)提示執(zhí)行:

# sealert -l e73ba9e8-f74d-4835-9b53-85667546b28c
SELinux is preventing /usr/bin/mongod from write access on the directory /data/mongodb/log.

***** Plugin catchall_labels (83.8 confidence) suggests *******************

If you want to allow mongod to have write access on the log directory
Then 必須更改 /data/mongodb/log 中的標簽
Do
# semanage fcontext -a -t FILE_TYPE '/data/mongodb/log'

其中 FILE_TYPE 為以下內(nèi)容之一:mongod_log_t, mongod_tmp_t, mongod_var_lib_t, mongod_var_run_t, tmp_t, var_lib_t, var_log_t, var_run_t。

然后執(zhí)行:

restorecon -v '/data/mongodb/log'


***** Plugin catchall (17.1 confidence) suggests **************************
......

上面提示輸出中已經(jīng)包含了,解決方法:

# semanage fcontext -a -t mongo_log_t '/data/mongodb/log'
# restorecon -v '/data/mongodb/log'
restorecon reset /data/mongodb/log context unconfined_u:object_r:unlabeled_t:s0->unconfined_u:object_r:mongod_log_t:s0

上面命令執(zhí)行完畢后,就解決了/data/mongodb/log目錄的文件權(quán)限問題。

同樣的方法,再解決/data/mongodb/data和/data/mongodb/run目錄的問題。

啟動mongod,問題解決。

Nov 9 06:08:51 [localhost] systemd: Starting High-performance, schema-free document-oriented database...
Nov 9 06:08:51 [localhost] systemd: Started High-performance, schema-free document-oriented database.
Nov 9 06:08:51 [localhost] mongod: about to fork child process, waiting until server is ready for connections.
Nov 9 06:08:51 [localhost] mongod: forked process: 18218
Nov 9 06:08:51 [localhost] mongod: child process started successfully, parent exiting

P.S. 除了上面通過提示信息解決問題外,還有一個比較暴力的方法,直接關(guān)閉SELinux,但是不太建議。

# setenforce 0
# getenforce
Permissive

上面是臨時關(guān)閉,如果是永久關(guān)閉,就需要編輯/etc/selinux/config文件,將SELINUX=enforcing改為SELINUX=disabled,但是只有重啟后才會發(fā)揮作用。

總結(jié)

以上就是這篇文章的全部內(nèi)容了,希望本文的內(nèi)容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對腳本之家的支持。

相關(guān)文章

  • Mongodb安裝與配置筆記

    Mongodb安裝與配置筆記

    這篇文章主要介紹了Mongodb安裝與配置筆記,本文環(huán)境為Linux,講解了Mongodb安裝步驟、配置方法、服務(wù)啟動、后臺運行等內(nèi)容,需要的朋友可以參考下
    2014-09-09
  • MongoDB分頁查詢緩慢怎么辦

    MongoDB分頁查詢緩慢怎么辦

    在大數(shù)據(jù)應(yīng)用中,MongoDB的分頁查詢存在性能問題,特別是數(shù)據(jù)量大時,本文探討了性能下降的原因,并提出了多種優(yōu)化策略,如有效使用索引、基于索引的游標分頁、使用聚合框架、減少返回數(shù)據(jù)量、使用緩存機制等,旨在改善大規(guī)模數(shù)據(jù)場景下的查詢效率
    2024-09-09
  • MongoDB可視化工具mongodb-compass

    MongoDB可視化工具mongodb-compass

    這篇文章介紹了MongoDB的可視化工具mongodb-compass,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2022-06-06
  • MongoDB中的參數(shù)限制與閥值詳析

    MongoDB中的參數(shù)限制與閥值詳析

    這篇文章主要給大家介紹了關(guān)于MongoDB中參數(shù)限制與閥值的相關(guān)資料,文中通過示例代碼以及圖文介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面來一起學習學習吧
    2019-03-03
  • mongodb聚合_動力節(jié)點Java學院整理

    mongodb聚合_動力節(jié)點Java學院整理

    這篇文章主要為大家詳細介紹了mongodb聚合的相關(guān)資料,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2017-08-08
  • MongoDB安裝、基礎(chǔ)操作和聚合實例介紹

    MongoDB安裝、基礎(chǔ)操作和聚合實例介紹

    雖然MongoDB這些年很流行,但筆者之前沒研究過,現(xiàn)在有需求研究這類NoSQL的數(shù)據(jù)庫,是為了驗證其是否可被替換,本文給大家介紹MongoDB安裝、基礎(chǔ)操作和聚合實例詳解,感興趣的朋友一起看看吧
    2024-07-07
  • MongoDB插入數(shù)據(jù)的3種方法

    MongoDB插入數(shù)據(jù)的3種方法

    在MongoDB中,db.collection.insert()方法添加一個新文檔到集合中。另外,db.collection.update()方法和db.collection.save()方法也能通過upsert操作添加新文檔。upsert操作執(zhí)行更新現(xiàn)有文檔或者當文檔不存在時插入一個新文檔。
    2014-05-05
  • C#實現(xiàn)窗體中的各個控件同比自動放縮大小

    C#實現(xiàn)窗體中的各個控件同比自動放縮大小

    這篇文章主要介紹了C#實現(xiàn)窗體中的各個控件同比自動放縮大小,實現(xiàn)方式主要是利用panel控件為主題,對于每個控件的大小位置和字體這幾個屬性進行記錄,然后根據(jù)窗體改變的大小同時放縮,需要的朋友可以參考下
    2014-10-10
  • SpringBoot系列之MongoDB?Aggregations用法詳解

    SpringBoot系列之MongoDB?Aggregations用法詳解

    MongoDB?中使用聚合(Aggregations)來分析數(shù)據(jù)并從中獲取有意義的信息,本文重點給大家介紹SpringBoot系列之MongoDB?Aggregations用法,感興趣的朋友跟隨小編一起看看吧
    2022-02-02
  • 詳解Mongodb?多文檔聚合操作處理方法(Map-reduce?函數(shù))

    詳解Mongodb?多文檔聚合操作處理方法(Map-reduce?函數(shù))

    這篇文章主要介紹了Mongodb多文檔聚合操作處理方法(Map-reduce函數(shù)),本文通過示例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下
    2023-07-07

最新評論