当前位置:   article > 正文

docker 安装mongodb_docker mongodb

docker mongodb
  1. docker search mongo
  2. docker pull mongo:4.2.0
  3. docker run --name mongo -p 27017:27017 -v /mnt/mongodb/data:/data/db -v /mnt/mongodb/backup:/data/backup -d mongo:4.2.0
  4. 登录:
  5. docker exec -it mongo mongo admin
  6. db.createUser({ user:'root',pwd:'123',roles:[ { role:'userAdminAnyDatabase', db: 'admin'}]});
  7. 远程访问,mongodb 的容器当中操作修改bindIP
  8. docker exec -it mongo bash
  9. apt-get update
  10. apt-get install nano
  11. nano /etc/mongod.conf.orig
  12. # 修改bindIP为0.0.0.0
  13. 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),

 

单例复本集搭建:

  1. 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"
  2. docker exec -it mongo mongo admin
  3. cfg={"_id":"rs0","members":[{"_id":0,"host":"192.168.31.132:27017"}]}
  4. rs.initiate(cfg)
  5. 创建用户:
  6. db.createUser({ user:'root',pwd:'123',roles:[ { role:'userAdminAnyDatabase', db: 'admin'}]});
  7. 远程访问,mongodb 的容器当中操作修改bindIP
  8. docker exec -it mongo bash
  9. nano /etc/mongod.conf.orig
  10. # 修改bindIP为0.0.0.0
  11. bindIp: 0.0.0.0

单例复本集搭建:(如果同一台服务器已搭建单例)

  1. 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"
  2. docker exec -it mongo2 mongo admin
  3. cfg={"_id":"rs0","members":[{"_id":0,"host":"192.168.31.132:27018"}]}
  4. rs.initiate(cfg)
  5. 创建用户:
  6. db.createUser({ user:'root',pwd:'123',roles:[ { role:'userAdminAnyDatabase', db: 'admin'}]});
  7. 远程访问,mongodb 的容器当中操作修改bindIP
  8. docker exec -it mongo2 bash
  9. apt-get update
  10. apt-get install nano
  11. nano /etc/mongod.conf.orig
  12. # 修改bindIP为0.0.0.0
  13. bindIp: 0.0.0.0

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/笔触狂放9/article/detail/358603
推荐阅读
相关标签
  

闽ICP备14008679号