记一次Ubuntu22安装MongoDB8并同步本地数据过程
1. 效果展示
2. 安装MongoDB 8
根据官方文档https://www.mongodb.com/zh-cn/docs/manual/tutorial/install-mongodb-on-ubuntu/一顿操作即可
2.1 配置微调支持远程访问
修改配置文件,默认/etc/mongod.conf
# network interfaces
net:port: 27017bindIp: 0.0.0.0
2.2 新增admin用户鉴权访问
在配置文件中,我们启动权限控制
security:authorization: enabled
通过命令mongosh
,连接到MongoDB,切换数据库use admin
,然后创建用户
# 创建用户
db.createUser({user: "admin",pwd: "yourPassword", roles: [{ role: "root", db: "admin" }]
})
# 查看创建的用户
db.getUsers()
2.3 重启服务远程连接
systemctl restart mongod
mongosh -u admin -p ****** --authenticationDatabase admin --port 27017
远程通过Navicat等工具即可连接
3. 数据dump与restore
# 数据dump出来
mongodump --host 127.0.0.1 --port 27017 --username admin --password ****** --authenticationDatabase admin --db stock --out /home/shenjian/stock --gzip# 数据restore到远程服务器
mongorestore --host 192.163.0.9 --port 27017 --username admin --password ****** --authenticationDatabase admin --db stock /home/shenjian/stock/stock --gzip