安装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
问题得到解决