<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)