<mongodb在linux上的部署>
事实上redis安装程序挺好,直接帮我们生成了服务,直接可以使用systemctl去启动它,而mongodb在这方面没有那么智能,需要我们去编写自己的服务脚本了,然后把它加到开机自启动里面就可以了,主要的过程分为以下几个步骤:
mongodb我安装在了/root/tools目录下
一 配置文件,ANSI,记事本编写,UTF8可能有问题
dbpath=/root/tools/mongodb-linux-x86_64-amazon-3.4.2/db
logpath=/root/tools/mongodb-linux-x86_64-amazon-3.4.2/log/mongo.log
logappend=true
port=27017
fork=true
nohttpinterface=true
auth=false
二 服务文件,文件位于:/usr/lib/systemd/system
[Unit]
Description=mongodb
After=network.target remote-fs.target nss-lookup.target
[Service]
Type=forking
ExecStart=/root/tools/mongodb-linux-x86_64-amazon-3.4.2/bin/mongod --config /root/tools/mongodb-linux-x86_64-amazon-3.4.2/bin/mongodb.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/root/tools/mongodb-linux-x86_64-amazon-3.4.2/bin/mongod --shutdown --config /root/tools/mongodb-linux-x86_64-amazon-3.4.2/bin/mongodb.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target
三 服务命令
#文件权限
chmod 754 mongodb.service
#启动服务
systemctl start mongodb.service
#关闭服务
systemctl stop mongodb.service
#开机启动
systemctl enable mongodb.service
这你几步之后,我们的mongodb服务就做好了!
感谢各位阅读!
作者:仓储大叔,张占岭,
荣誉:微软MVP
QQ:853066980
支付宝扫一扫,为大叔打赏!
![](https://img.laitimes.com/img/__Qf2AjLwojIjJCLyojI0JCLicEUK5CN0EzNfdUTJ91bvwFN4gzNzIzLclmcvx2Lc12bj91cn9Gbi52YvwVbvNmLzd2bsJmbj5ycldWYtl2Lc9CX6MHc0RHaiojIsJye.jpg)