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" )

Linux 简单命令

  • ls 出当前文件下的文件和文件夹
  • ls -l 显示详细的文件和文件夹信息
  • ls -la 显示详细的隐藏文件和文件夹信息
  • cd /home/hello/ 改变文件路径,进入hello文件夹下
  • pwd 显示自己所在的当前路径
  • cd .. 返回上级目录
  • rm xxx.js 删除xxx.js的文件
  • rm -r hello/ 删除当前当前目录下hello文件夹和里面的所有文件
  • top 查看当前进程情况(按z键查看变化情况,q退出)
  • ps aux 显示当前用户所有程序
  • ps aux | grep ssh 显示包含ssh的进程
  • ifconfig 显示本机的网络信息
  • systemctl 控制系统的服务
  • vi 进入vi编辑器
  • |—i 用vi打开文件后摁 i 进入编辑模式

    • |—insert 用insert切换 插入/替换
  • |— : vi进入查看模式后 显示命令行

    • |—wq 保存然后退出文件
    • |—q 退出文件
    • |—q! 不保存退出文件