赞
踩
- docker search mongo
- docker pull mongo:4.2.0
- docker run --name mongo -p 27017:27017 -v /mnt/mongodb/data:/data/db -v /mnt/mongodb/backup:/data/backup -d mongo:4.2.0
- 登录:
- docker exec -it mongo mongo admin
- db.createUser({ user:'root',pwd:'123',roles:[ { role:'userAdminAnyDatabase', db: 'admin'}]});
- 远程访问,mongodb 的容器当中操作修改bindIP
- docker exec -it mongo bash
- apt-get update
- apt-get install nano
- nano /etc/mongod.conf.orig
- # 修改bindIP为0.0.0.0
- bindIp: 0.0.0.0
使用客户端连接:
如果勾选上ssl连接会报错
Error receiving request from client: SSLHandshakeFailed: SSL handshake received but server is started without SSL support. Ending connection from 192.168.31.108:63786 (connection id: 18),
单例复本集搭建:
- docker run -itd --name mongo -p 27017:27017 --restart=always -v /mnt/mongodb/data:/data/db -v /mnt/mongodb/backup:/data/backup -v /mnt/mongodb/log:/data/log mongo:4.2.0 --replSet "rs0"
- docker exec -it mongo mongo admin
- cfg={"_id":"rs0","members":[{"_id":0,"host":"192.168.31.132:27017"}]}
- rs.initiate(cfg)
-
- 创建用户:
- db.createUser({ user:'root',pwd:'123',roles:[ { role:'userAdminAnyDatabase', db: 'admin'}]});
-
- 远程访问,mongodb 的容器当中操作修改bindIP
- docker exec -it mongo bash
- nano /etc/mongod.conf.orig
- # 修改bindIP为0.0.0.0
- bindIp: 0.0.0.0
单例复本集搭建:(如果同一台服务器已搭建单例)
- docker run -itd --name mongo2 -p 27018:27017 --restart=always -v /mnt/mongodb2/data:/data/db -v /mnt/mongodb2/backup:/data/backup -v /mnt/mongodb2/log:/data/log mongo:4.2.0 --replSet "rs0"
- docker exec -it mongo2 mongo admin
- cfg={"_id":"rs0","members":[{"_id":0,"host":"192.168.31.132:27018"}]}
- rs.initiate(cfg)
-
- 创建用户:
- db.createUser({ user:'root',pwd:'123',roles:[ { role:'userAdminAnyDatabase', db: 'admin'}]});
-
- 远程访问,mongodb 的容器当中操作修改bindIP
- docker exec -it mongo2 bash
- apt-get update
- apt-get install nano
- nano /etc/mongod.conf.orig
- # 修改bindIP为0.0.0.0
- bindIp: 0.0.0.0
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。