ubuntu18.04安装mongoDB 4.2

 

在终端输入GPK码

wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -

添加mongoDB源

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list

sudo apt update

Install MongoDB Server

 sudo apt install mongodb-org=4.2.1 mongodb-org-server=4.2.1 mongodb-org-shell=4.2.1 mongodb-org-mongos=4.2.1 mongodb-org-tools=4.2.1

配置启动

 sudo vim /etc/systemd/system/mongodb.service

 填入以下内容

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target

[Service]
User=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf

[Install]
WantedBy=multi-user.target

启动

sudo systemctl start mongodb

连接mongo

mongo

添加用户

db.createUser({user: "admin", pwd: "123456",roles: [ { role: "userAdminAnyDatabase", db: "admin"} ]})

 

你可能感兴趣的:(Ubuntu)