如果感觉系统下的很慢,需要更换镜像源(如果还是很慢,可以重复的停止/更新执行命令)
vim /etc/apt/sources.list
更换镜像源(可以找适合自己的替换)
deb http://mirrors.tuna.tsinghua.edu.cn/debian/ buster main
deb-src http://mirrors.tuna.tsinghua.edu.cn/debian/ buster main
deb http://mirrors.cloud.aliyuncs.com/debian-security/ bullseye-security main
deb-src http://mirrors.cloud.aliyuncs.com/debian-security/ bullseye-security main
deb http://mirrors.cloud.aliyuncs.com/debian/ bullseye-updates main
deb-src http://mirrors.cloud.aliyuncs.com/debian/ bullseye-updates main
deb http://mirrors.cloud.aliyuncs.com/debian/ bullseye-backports main
deb-src http://mirrors.cloud.aliyuncs.com/debian/ bullseye-backports main
更新资源包
apt-get update
1.官网
https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-debian/
2.选择自己安装的系统
3.按照步骤
sudo apt-get install gnupg curl
curl -fsSL https://pgp.mongodb.com/server-7.0.asc | sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg --dearmor
echo "deb [ signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] http://repo.mongodb.org/apt/debian bullseye/mongodb-org/7.0 main" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-database hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-mongosh hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
4. 查看系统使用那个命令来管理服务(systemctl or service)
ps --no-headers -o comm 1
5. 管理mongodb服务
开启服务
sudo systemctl start mongod
重载服务(如果开启服务报错
Failed to start mongod.service: Unit mongod.service not found.
)则执行如下命令
sudo systemctl daemon-reload
查看服务状态
sudo systemctl status mongod
让服务以守护进程的方式运行
sudo systemctl enable mongod
停止服务
sudo systemctl stop mongod
重启服务
sudo systemctl restart mongod
进入mongodb (默认)
mongosh
6.卸载mongodb服务
停止服务
sudo systemctl stop mongod
卸载mongodb包
sudo apt-get purge mongodb-org*
删除mongodb相关文件夹
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
7.创建一个用户
db.createUser(
{
user: "mongo",
pwd: "klkdmfmpq",
roles: [ { role: "readWrite", db: "test" } ]
}
)
8.修改mongo远程连接权限,配置文件位置:/etc/mongod.conf
vim /etc/mongod.conf
文件内容
storage:
dbPath: /var/lib/mongodb
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 0.0.0.0
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
security:
authorization: enabled
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
重启服务
sudo systemctl restart mongod
开启 27017 服务端口
ufw allow 27017/tcp