Mongodb包在默认的Ubuntu存储库中是不可使用的。首先需要导入包管理系统使用的公钥。
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
更新apt资源库
sudo apt update sudo apt upgrade -y
创建列表文件
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
sudo apt update
echo "deb http://security.ubuntu.com/ubuntu focal-security main" | sudo tee /etc/apt/sources.list.d/focal-security.list sudo apt-get update sudo apt-get install libssl1.1
sudo apt install -y mongodb-org
sudo systemctl start mongod # start mongodbsudo systemctl status mongod # check status of mongodb
添加服务在系统启动的时候开启mongodb
sudo systemctl enable mongod
rm /tmp/mongodb-27017.sock
db.createUser({ user: "db_yapi", pwd: "db_yapi", roles: [ {role: "readWrite", db: "db_yapi" } ] }) db.grantRolesToUser("db_yapi", [{ role: "dbAdmin", db: "db_yapi" }]) db.auth("db_yapi", "sdjd820ejJJHy72h") db.grantRolesToUser( "db_yapi", [ { role: "userAdmin", db: "db_yapi" } ] ); db.createUser( { user:"root", pwd:"123456", roles:[{role:"root",db:"admin"}] } ); db.auth("root", "123456")