安装mongodb 遇到的坑

安装mongodb

wget https://repo.mongodb.org/yum/redhat/8/mongodb-org/4.4/x86_64/RPMS/mongodb-org-server-4.4.0-1.el8.x86_64.rpm

yum -ivh mongodb-org-server-4.4.0-1.el8.x86_64.rpm

配置

vi /etc/mongod.conf
重点注意
storage:
  dbPath: /data/mongod
net:
  port: 27017
  bindIp: 192.168.1.158

启动

systemctl start mongod
Job for mongod.service failed because the control process exited with error code.
See "systemctl status mongod.service" and "journalctl -xe" for details.

报错日志在 /var/log/mongod
"error":"IllegalOperation: Attempted to create a lock file on a read-only directory: /data/mongod
这说明没有权限

chmod 777 /data/mongod

问题依然

chown mongod:mongod /data/mongod

问题依然
通过官方文档找到:

On RHEL 7.0, if you change the data path, the default SELinux  
 policies will prevent mongod from having write access on the new  
 data path if you do not change the security context.  

默认目录/var/lib/mongo含有mongod_var_lib_t,这样selinux的安全策略有关。
解决方法是修改对应文件夹的security context

chcon -Rv --type=mongod_var_lib_t /data/mongod

问题得到解决

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。