Mongodb~Linux環境下(xia)的部署~服(fu)務的部署與自動化(hua)
事實上redis安(an)裝(zhuang)程(cheng)序(xu)挺好,直接幫我們生成了(le)(le)服務,直接可以(yi)使用(yong)systemctl去啟動它(ta),而mongodb在這方(fang)面沒有(you)那么智能,需要我們去編寫自(zi)己的服務腳(jiao)本(ben)了(le)(le),然后把它(ta)加到(dao)開機自(zi)啟動里面就可以(yi)了(le)(le),主要的過(guo)程(cheng)分為以(yi)下(xia)幾個步驟:
mongodb我(wo)安(an)裝(zhuang)在了/root/tools目錄下
一 配置(zhi)文件,ANSI,記事本編寫(xie),UTF8可能有(you)問題
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
三 服務命令
#文(wen)件權限 chmod 754 mongodb.service #啟(qi)動(dong)服(fu)務(wu) systemctl start mongodb.service #關閉(bi)服(fu)務(wu) systemctl stop mongodb.service #開機啟(qi)動(dong) systemctl enable mongodb.service
這你(ni)幾步之后,我們的mongodb服務就(jiu)做好了(le)!
感謝各位閱讀!