MongoDB 基础(四)Red Hat Enterprise 6.4 x64 安装MongDB 3.0及配置

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mongodb-org  
  2. 该包为元数据包,安装时将自动安装以下4个组件包  
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. mongodb-org-server  
  2. 该包包含mongod守护进程、相关配置和初始脚本  
  3.   
  4. mongodb-org-mongos  
  5. 该包包含mongos守护进程  
  6.   
  7. mongodb-org-shell  
  8. 该包包含mongo shell  
  9.    
  10. mongodb-org-tools  
  11. 该包包含以下mongodb工具:  
  12. mongoimport bsondump, mongodump,mongoexport, mongofiles, mongooplog, mongoperf, mongorestore, mongostat, andmongotop.  


1. 创建yum源仓库文件:
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. vi /etc/yum.repos.d/mongodb-org-3.0.repo  
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. [mongodb-org-3.0]  
  2. name=MongoDB Repository  
  3. baseurl=http://repo.mongodb.org/yum/redhat/6/mongodb-org/3.0/x86_64/  
  4. gpgcheck=0  
  5. enabled=1  


2. 安装MongoDB包和相关工具:

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. yum install -y mongodb-org  


要是安装指定版本的MongoDB,应独立指定每个组件包和附加在包名后面的版本号,如:

sudo yum install -y mongodb-org-3.0.2 mongodb-org-server-3.0.2 mongodb-org-shell-3.0.2 mongodb-org-mongos-3.0.2 mongodb-org-tools-3.0.2


也可以定义任何可用的MongoDB版本,当有更新的版本时yum将自动更新Mongodb包。为了防止无意的的更新,可以在/etc/yum.conf中使用exclude指令,如:
exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools


3. 相关配置:

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. 如果开启了防火墙,必须配置SELinux允许MongoDB运行在Red Hat系统或者CentOS Linux。  
  2. 管理员应该设置以下3个选项:  
  3.   
  4. 1. 允许端口27017访问(没有则先下载工具semanage):  
  5. yum -y install policycoreutils-python  
  6. semanage port -a -t mongod_port_t -p tcp 27017  
  7.   
  8.   
  9. 2. 在配置文件/etc/selinux/config设置SELinux模式为permissive:  
  10. vi /etc/selinux/config  
  11.   
  12. SELINUX=enforcing   
  13. 改为  
  14. SELINUX=permissive  
  15.   
  16.   
  17. 3. 彻底禁用SELinux:  
  18. SELINUX=disabled  

Mongodb实例默认存储数据的数据文件路径为/var/lib/mongo,存储日志文件路径为/var/log/mongodb ,使用mongod账户运行。也可以在文件/etc/mongod.conf 配置数据文件和日志文件的目录。
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. vi /etc/mongod.conf  
[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. # mongod.conf  
  2.   
  3. #where to log  
  4. logpath=/var/log/mongodb/mongod.log  
  5.   
  6. logappend=true  
  7.   
  8. # fork and run in background  
  9. fork=true  
  10.   
  11. #port=27017  
  12.   
  13. dbpath=/var/lib/mongo  
  14.   
  15. # location of pidfile  
  16. pidfilepath=/var/run/mongodb/mongod.pid  
  17.   
  18. # Listen to local interface only. Comment out to listen on all interfaces.  
  19. bind_ip=127.0.0.1  
  20.   
  21. # Disables write-ahead journaling  
  22. # nojournal=true  
  23.   
  24. # Enables periodic logging of CPU utilization and I/O wait  
  25. #cpu=true  
  26.   
  27. # Turn on/off security.  Off is currently the default  
  28. #noauth=true  
  29. #auth=true  
  30.   
  31. # Verbose logging output.  
  32. #verbose=true  
  33.   
  34. # Inspect all client data for validity on receipt (useful for  
  35. # developing drivers)  
  36. #objcheck=true  
  37.   
  38. # Enable db quota management  
  39. #quota=true  
  40.   
  41. # Set oplogging level where n is  
  42. #   0=off (default)  
  43. #   1=W  
  44. #   2=R  
  45. #   3=both  
  46. #   7=W+some reads  
  47. #diaglog=0  
  48.   
  49. # Ignore query hints  
  50. #nohints=true  
  51.   
  52. # Enable the HTTP interface (Defaults to port 28017).  
  53. #httpinterface=true  
  54.   
  55. # Turns off server-side scripting.  This will result in greatly limited  
  56. # functionality  
  57. #noscripting=true  
  58.   
  59. # Turns off table scans.  Any query that would do a table scan fails.  
  60. #notablescan=true  
  61.   
  62. # Disable data file preallocation.  
  63. #noprealloc=true  
  64.   
  65. # Specify .ns file size for new databases.  
  66. # nssize=<size>  
  67.   
  68. # Replication Options  
  69.   
  70. # in replicated mongo databases, specify the replica set name here  
  71. #replSet=setname  
  72. # maximum size in megabytes for replication operation log  
  73. #oplogSize=1024  
  74. # path to a key file storing authentication info for connections  
  75. # between replica set members  
  76. #keyFile=/path/to/keyfile  


4. 运行mongodb

[plain]  view plain copy 在CODE上查看代码片 派生到我的代码片
  1. 设置Mongodb随系统自启动:  
  2. chkconfig mongod on  
  3.   
  4.   
  5. 启用Mongodb服务:  
  6. service mongod start  
  7.   
  8.   
  9. 验证Mongodb已成功启动:(查看日志是否有等待连接的信息)  
  10. tail -5 /var/log/mongodb/mongod.log  
  11.   
  12. [initandlisten] waiting for connections on port <port>  

此时也看到数据已经生成:



直接在命令行输入 mongo 可进入数据库中:



至此,完成!~

官方参考:Install MongoDB on Red Hat Enterprise or CentOS Linux


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值