美文网首页MongoDB集中营
Centos7配置MongodDB服务

Centos7配置MongodDB服务

作者: 爱恨_交加 | 来源:发表于2020-07-25 18:45 被阅读0次

目的:在安装好MongoDB后注册服务,使用systemctl控制MongoDB服务

1、在 /lib/systemd/system 目录下创建名称为 mongodb 的服务(自定义服务名)

cd /lib/systemd/system
vi mongodb.service

2、在 mongodb.service 中输入如下信息:

note:命令 mongod 和 配置文件 mongod.conf (自己定义的配置文件) 所在的路径替换为自己的,并且要求是绝对路径,其它不需要变动。

[Unit]

Description=mongodb
After=network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
ExecStart=/opt/module/mongodb/server/bin/mongod -f /opt/module/mongodb/conf/mongod.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/opt/module/mongodb/server/bin/mongod --shutdown -f /opt/module/mongodb/conf/mongod.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

3、设置 mongodb.service 权限

chmod 754 mongodb.service

至此,MongoDB服务配置完成~~

其中MongoDB的配置文件mongod.conf的基本内容如下:

note:应该指定这几个最基本的参数,其中fork应该存在并且设置为true,否则执行 systemctl start mongodb.service 会超时失败

dbpath=/opt/module/mongodb/data
logpath=/opt/module/mongodb/logs/mongodb.log
port=27017
fork=true
#auth=true

systemctl命令

systemctl start|restart|stop|status|enable|disable service_name

# 启动服务
systemctl start service_name
# 停止服务
systemctl stop service_name
# 重启服务
systemctl restart service_name
# 服务状态
systemctl status service_name
# 开启启动
systemctl enable service_name
# 禁止开机启动
systemctl disable service_name

参考:
https://www.cnblogs.com/sunday294/p/6907992.html
http://www.jinbuguo.com/systemd/systemd.service.html

相关文章

网友评论

    本文标题:Centos7配置MongodDB服务

    本文链接:https://www.haomeiwen.com/subject/olymlktx.html