下载

采用rpm包的方式安装:
官网地址:https://www.mongodb.com/try/download/community
服务端:选择server
客户端:选择shell

image.png
image.png

安装服务端

  1. # 安装服务端
  2. rpm -Uvh mongodb-org-server-5.0.1-1.el7.x86_64.rpm
  3. # 设置开机自启并启动
  4. systemctl enable --now mongod
  5. # 查看配置文件
  6. vim /etc/mongod.conf
  7. # mongod.conf
  8. # for documentation of all options, see:
  9. # http://docs.mongodb.org/manual/reference/configuration-options/
  10. # where to write logging data.
  11. systemLog:
  12. destination: file
  13. logAppend: true
  14. path: /var/log/mongodb/mongod.log
  15. # Where and how to store data.
  16. storage:
  17. dbPath: /var/lib/mongo
  18. journal:
  19. enabled: true
  20. # engine:
  21. # wiredTiger:
  22. # how the process runs
  23. processManagement:
  24. fork: true # fork and run in background
  25. pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
  26. timeZoneInfo: /usr/share/zoneinfo
  27. # network interfaces
  28. net:
  29. port: 27017
  30. bindIp: 127.0.0.1 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.

修改bindIp为 0.0.0.0 即可远程访问
重启mongodb发现报错:
image.png
Google一下说是要给/tmp/mongodb-27017.sock 修改文件所属,发现还是不行。
最后:

  1. #删除这个文件并重启,解决问题
  2. rm /tmp/mongodb-27017.sock -rf
  3. systemctl restart mongod

安装客户端

  1. #安装
  2. rpm -Uvh mongodb-org-shell-5.0.1-1.el7.x86_64.rpm
  3. #进入数据库
  4. ./mongo

查看数据库:
image.png
查看当前数据库:
image.png
切换数据库:
image.png