安装
导入包管理系统使用的公钥
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
安装libssl
- 注意18.04.23版本好像会变,如果报错’./libssl1.1_1.1.1-1ubuntu2.1~18.04.22_amd64.deb’ is not a Debian format archive就去查看最新版本替换即可
curl -LO http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1-1ubuntu2.1~18.04.23_amd64.deb
不安装libssl会报错
mongodb-org-mongos : Depends: libssl1.1 (>= 1.1.1) but 1.1.0g-2ubuntu4 is to be installed
mongodb-org-server : Depends: libssl1.1 (>= 1.1.1) but 1.1.0g-2ubuntu4 is to be installed
安装mongodb
sudo apt install -y mongodb-org
启动mongodb
root@ubuntu:~# sudo systemctl start mongod
root@ubuntu:~# sudo systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor prese>
Active: active (running) since Thu 2023-11-30 15:06:29 CST; 6s ago
Docs: https://docs.mongodb.org/manual
Main PID: 5794 (mongod)
Memory: 67.2M
CPU: 1.096s
CGroup: /system.slice/mongod.service
└─5794 /usr/bin/mongod --config /etc/mongod.conf
Nov 30 15:06:29 ubuntu systemd[1]: Started MongoDB Database Server.
Nov 30 15:06:29 ubuntu mongod[5794]: {"t":{"$date":"2023-11-30T07:06:29.767Z"},>
lines 1-12/12 (END)
添加系统启动时自动开始
sudo systemctl enable mongod
注:6.0以上使用mongosh命令而不是mongo命令
查看防火墙开发端口
sudo ufw status numbered
启用防火墙:sudo ufw enable
禁用防火墙:sudo ufw disable
开放指定端口:sudo ufw allow <port>
关闭指定端口:sudo ufw delete allow <port>
添加用户
use admin
db.createUser({user:"admin",pwd:"123456",roles:[{role:"userAdminAnyDatabase",db:"admin"}]})
启用验证
security:
authorization:enabled
重新启动
security:
authorization:enabled