1官網下載: https://www.mongodb.com/download-center/communitylinux
2上傳至目錄 /opt/mongoDb 下mongodb
3解壓數據庫
tar zxvf mongodb-linux-x86_64-4.0.5.tgz
4添加配置文件vim
vim /opt/mongoDB/mongodb-linux-x86_64-4.0.5/bin/mongodb.conf
# 數據庫文件路徑 dbpath = /opt/mongoDB/mongodb-linux-x86_64-4.0.5/data # 日誌文件路徑 logpath = /opt/mongoDB/mongodb-linux-x86_64-4.0.5/logs/mongodb.log # 是否追加日誌 logappend=true # 端口 port=27017 # 是否後臺程序啓動 fork=true # 是否啓動受權認證 auth=true # 開啓連接權限 bind_ip=0.0.0.0
5配置mongodb服務app
vim /lib/systemd/system/mongodb.service
[Unit] Description=mongodb After=network.target remote-fs.target nss-lookup.target [Service] Type=forking ExecStart=/opt/mongoDB/mongodb-linux-x86_64-4.0.5/bin/mongod --config /opt/mongoDB/mongodb-linux-x86_64-4.0.5/bin/mongodb.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/opt/mongoDB/mongodb-linux-x86_64-4.0.5/bin/mongod --shutdown --config /opt/mongoDB/mongodb-linux-x86_64-4.0.5/bin/mongodb.conf PrivateTmp=true [Install] WantedBy=multi-user.target
6設置權限spa
chmod 754 mongodb.service 日誌
7啓動關閉服務,設置開機啓動code
#啓動服務
blog
systemctl start mongodb.service
ip#關閉服務
systemctl stop mongodb.service
#開機啓動
systemctl enable mongodb.service
8建立數據庫&用戶
mongo 登陸
use admin
db.createUser({user: "admin",pwd: "123456",roles:[{role: "userAdminAnyDatabase",db: "admin"}]})
db.auth('admin', '123456')use tdsdb.createUser({user: "ljyctds",pwd: "ljyctds",roles:[{role: "dbOwner",db: "tds"}]})