Centos7環境下安裝mongodb
阿新 • • 發佈:2018-07-23
程序啟動 lib pri 二進制 http 開機 true 代碼 clas
1、下載
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-3.6.3.tgz
2、解壓
tar zxvf mongodb-linux-x86_64-amazon-3.6.3.tgz
3、移動
mv mongodb-linux-x86_64-amazon-3.6.3 /usr/local/mongodb
備註:不用編譯,本身就是編譯後的二進制執行文件
4、添加配置文件
vim /usr/local/mongodb/bin/mongodb.conf
復制下面代碼
# 數據庫文件路徑 dbpath=/usr/local/mongodb/data/db/ # 日誌文件路徑 logpath=/usr/local/mongodb/data/log/mongodb.log # 是否追加日誌 logappend=true # 端口 port=27017 # 是否後臺程序啟動 fork=true # 是否啟動授權認證 auth=true
備註:需創建數據庫、日誌目錄
5、配置mongodb服務
vim /lib/systemd/system/mongodb.service
復制如下代碼
[Unit] Description=mongodb After=network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStart=/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/bin/mongodb.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/usr/local/mongodb/bin/mongod --shutdown --config /usr/local/mongodb/bin/mongodb.conf PrivateTmp=true [Install] WantedBy=multi-user.target
6、開機啟動
# 開機啟動 systemctl enable mongodb.service # 啟動服務 systemctl start mongodb.service # 停止服務 systemctl stop mongodb.service
Centos7環境下安裝mongodb