在新装的CentOS7上,安装了MongoDB3.4
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了在新装的CentOS7上,安装了MongoDB3.4,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含4904字,纯文字阅读大概需要8分钟。
内容图文
![在新装的CentOS7上,安装了MongoDB3.4](/upload/InfoBanner/zyjiaocheng/494/38f4d28eb15b4aaf98f85e1eb67d7ed2.jpg)
问题描述:
在新装的CentOS7上,安装了MongoDB3.4,挂载了一个大的数据盘后,修改/etc/mongo.conf,将配置文件中的log和data目录放在新的数据盘下,并修改文件的访问权限。改完后的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
.....
文件权限:
# 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
执行systemctl start mongod命令后,查看状态发现并没有启动,查看/var/log/message,发现以下错误
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的防护功能,阻止了访问。
解决过程:
/var/log/message中的信息看起来比较费劲,里面有一句提示:
For complete SELinux messages run: sealert -l e73ba9e8-f74d-4835-9b53-85667546b28c
根据提示执行:
# 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 为以下内容之一: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。
然后执行:
restorecon -v ‘/data/mongodb/log‘
***** Plugin catchall (17.1 confidence) suggests **************************
......
上面提示输出中已经包含了,解决方法:
# 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
上面命令执行完毕后,就解决了/data/mongodb/log目录的文件权限问题。
同样的方法,再解决/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] www.6788878.cn systemd: Started High-performance, schema-free document-oriented database.
Nov 9 06:08:51 [localhost] mongod: www.xucaizxyl.com about to fork child process, waiting until server is ready for connections.
Nov 9 06:08:51 [localhost] mongod: www.huanggua130.cn forked process: 18218
Nov 9 06:08:51 [localhost] mongod: www.wanhengyl157.com child process started successfully, parent exiting
P.S. 除了上面通过提示信息解决问题外,还有一个比较暴力的方法,直接关闭SELinux,但是不太建议。
# setenforce 0
# getenforce
Permissive
上面是临时关闭,如果是永久关闭,就需要编辑/etc/selinux/config文件,将SELINUX=enforcing改为SELINUX=disabled,但是只有重启后才会发挥作用。
在新装的CentOS7上,安装了MongoDB3.4
标签:orm for cal mis linux append 查看 info manage
本文系统来源:http://www.cnblogs.com/wanmeiyule/p/7824698.html
内容总结
以上是互联网集市为您收集整理的在新装的CentOS7上,安装了MongoDB3.4全部内容,希望文章能够帮你解决在新装的CentOS7上,安装了MongoDB3.4所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。