centos配置mongodb
时间: 2023-12-06 16:34:53 浏览: 75
以下是在CentOS上配置MongoDB的步骤:
1. 修改相关目录的用户组:
```
chown -R mongod:mongod /usr/mongodb
chown -R mongod:mongod /opt/mongodb/4.0.6/data
chown -R mongod:mongod /opt/mongodb/4.0.6/logs
```
2. 关闭防火墙:
```
systemctl stop firewalld.service
```
查看防火墙状态:
```
systemctl status firewalld
```
3. 配置MongoDB启动项脚本:
```
vi /usr/lib/systemd/system/mongod.service
```
在文件中添加以下内容:
```
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target
[Service]
User=mongod
Group=mongod
EnvironmentFile=-/etc/sysconfig/mongod
ExecStart=/usr/bin/mongod $OPTIONS run
PIDFile=/var/run/mongodb/mongod.pid
ExecReload=/bin/kill -s HUP $MAINPID
Restart=always
PrivateTmp=true
[Install]
WantedBy=multi-user.target
```
4. 启动MongoDB服务:
```
systemctl daemon-reload
systemctl start mongod.service
```
5. 配置数据库用户:
```
mongo
use admin
db.createUser({user:"username",pwd:"password",roles:[{role:"root",db:"admin"}]})
```
如果浏览器输入MongoDB地址出现以下信息,说明启动成功:
```
It looks like you are trying to access MongoDB over HTTP on the native driver port.
```
阅读全文