mongodb3.4 在 centos 7 上部署

  1. https://docs.mongodb.com/master/tutorial/install-mongodb-on-amazon/ 使用yum 安装
  2. 修改部分配置文件

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    1. sudo vi /etc/mongod.conf 编辑配置文件 如下
    2. # mongod.conf
    3.
    4. # for documentation of all options, see:
    5. # http://docs.mongodb.org/manual/reference/configuration-options/
    6.
    7. # where to write logging data.
    8. systemLog:
    9. destination: file
    10. logAppend: true
    11. path: /var/log/mongod.log
    12.
    13. # Where and how to store data.
    14. storage:
    15. dbPath: /data/db
    16. journal:
    17. enabled: true
    18. # engine:
    19. # mmapv1:
    20. # wiredTiger:
    21.
    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.
    27. # network interfaces
    28. net:
    29. port: 27017
    30. bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
    31.
    32.
    33. security:
    34. authorization: enabled (关键部分 删除中文)
    35.
    36. #operationProfiling:
    37.
    38. #replication:
    39.
    40. #sharding:
    41.
    42. ## Enterprise-Only Options
    43.
    44. #auditLog:
    45.
    46. #snmp:
  3. 按照 https://docs.mongodb.com/manual/tutorial/enable-authentication/ 该网址中的内容使用 db.createUser() 创建一个用户

    中文翻译 http://www.cnblogs.com/qingtianyu2015/p/6148127.html

    备注:增删要增加readWrite 属性

  4. 重启数据库 ok

  5. 进入数据时要先
    1
    2
    use admin
    db.auth("myUserAdmin", "abc123" )