centos7配置MongoDB开机启动

我的环境

centos版本

[root@localhost /]# cat /etc/centos-release
CentOS Linux release 7.6.1810 (Core) 

mongodb信息

版本号:6.0.5
服务端绝对路径:/usr/local/mongodb/server/bin/mongod
配置文件绝对路径:/usr/local/mongodb/mongo.conf

开机脚本

#进入系统服务目录,创建mongod.service文件

[root@localhost /]# cd /usr/lib/systemd/system
[root@localhost system]# vi mongod.service

脚本内容

[Unit]
Description=Mongodb
After=network.target remote-fs.target nss-lookup.target

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

[Install]
WantedBy=multi-user.target

配置完成保存,在当前**/usr/lib/systemd/system**目录可以看到完整的文件信息,表示已经创建完成

-rw-r--r--. 1 root root  368 May 13 13:41 mongod.service

开启服务

执行systemctl enable mongod添加到开机启动

[root@localhost system]# systemctl enable mongod
Created symlink from /etc/systemd/system/multi-user.target.wants/mongod.service to /usr/lib/systemd/system/mongod.service.
[root@localhost system]# 

常用的命令

# 重启
systemctl restart mongod

# 查看状态
systemctl status mongod

# 关闭服务
systemctl stop mongod

# 启动服务
systemctl start mongod

# 禁止开机启动
systemctl disable mongod
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值