CentOS 6.5下通过yum安装MongoDB记录

来源:互联网 发布:java ssh协议jar包 编辑:程序博客网 时间:2024/05/22 08:02

最近想尝试一下英特尔的基于WebRTC协同通信开发套件,其中的CS_WebRTC_Conference_Server_MCU依赖MongoDB。

MongoDB是什么?


MongoDB 是一个基于分布式文件存储的数据库。由 C++ 语言编写。旨在为 WEB 应用提供可扩展的高性能数据存储解决方案。

MongoDB 是一个介于关系数据库和非关系数据库之间的产品,是非关系数据库当中功能最丰富,最像关系数据库的。

安装MongoDB

参考:https://docs.mongodb.org/getting-started/shell/tutorial/install-mongodb-on-red-hat/

https://docs.mongodb.org/getting-started/shell/tutorial/install-on-linux/

1、创建repo

vi /etc/yum.repos.d/mongodb-org-3.2.repo

[plain] view plain copy
  1. [mongodb-org-3.2]  
  2. name=MongoDB Repository  
  3. baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/  
  4. gpgcheck=0  
  5. enabled=1  

2、安装MongoDB和相关工具

sudo yum install -y mongodb-org

3、启动MongoDB

sudo service mongod start
4、验证MongoDB是否启动成功

cat /var/log/mongodb/mongod.log

查看是否有一句:[initandlisten] waiting for connections on port <port>

其中<port>是在/etc/mongod.conf中配置的,默认情况下是27017端口。

还有另一种方式:

[plain] view plain copy
  1. # sudo service mongod status  
  2. Redirecting to /bin/systemctl status  mongod.service  
  3. ● mongod.service - High-performance, schema-free document-oriented database  
  4.    Loaded: loaded (/usr/lib/systemd/system/mongod.service; disabled; vendor preset: disabled)  
  5.    Active: active (running) since 一 2016-09-12 09:50:16 CST; 15s ago  
  6.   Process: 8787 ExecStart=/usr/bin/mongod $OPTIONS run (code=exited, status=0/SUCCESS)  
  7.  Main PID: 8842 (mongod)  
  8.    CGroup: /system.slice/mongod.service  
  9.            └─8842 /usr/bin/mongod --quiet -f /etc/mongod.conf run  
  10.   
  11. 9月 12 09:50:13 192.168.1.155 systemd[1]: Starting High-performance, schema-free document-oriented database...  
  12. 9月 12 09:50:14 192.168.1.155 mongod[8787]: about to fork child process, waiting until server is ready for connections.  
  13. 9月 12 09:50:14 192.168.1.155 mongod[8787]: forked process: 8842  
  14. 9月 12 09:50:16 192.168.1.155 mongod[8787]: child process started successfully, parent exiting  
  15. 9月 12 09:50:16 192.168.1.155 systemd[1]: Started High-performance, schema-free document-oriented database.  
会看到“Active: active (running)”,说明正在运行。

没有运行的情况:

[plain] view plain copy
  1. # sudo service mongod status  
  2. Redirecting to /bin/systemctl status  mongod.service  
  3. ● mongod.service - High-performance, schema-free document-oriented database  
  4.    Loaded: loaded (/usr/lib/systemd/system/mongod.service; disabled; vendor preset: disabled)  
  5.    Active: inactive (dead)  
Active: inactive (dead)

5、使MongoDB开机自动启动

sudo chkconfig mongod on

6、停止MongoDB

sudo service mongod stop

7、重启MongoDB

sudo service mongod restart

服务器配置: /etc/mongod.conf

[plain] view plain copy
  1. # mongo.conf     
  2.     
  3. #where to log     
  4. logpath=/var/log/mongo/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. directoryperdb=true  
  15. # Enables periodic logging of CPU utilization and I/O wait     
  16. #启用定期记录CPU利用率和 I/O 等待     
  17. #cpu = true    
  18.     
  19. # Turn on/off security.  Off is currently the default    
  20. # 是否以安全认证方式运行,默认是不认证的非安全方式     
  21. #noauth = true    
  22. #auth = true    
  23.     
  24. # Verbose logging output.     
  25. # 详细记录输出     
  26. #verbose = true    
  27.     
  28. # Inspect all client data for validity on receipt (useful for    
  29. # developing drivers)用于开发驱动程序时的检查客户端接收数据的有效性     
  30. #objcheck = true    
  31.     
  32. # Enable db quota management 启用数据库配额管理,默认每个db可以有8个文件,可以用quotaFiles参数设置     
  33. #quota = true    
  34. # 设置oplog记录等级     
  35. # Set oplogging level where n is     
  36. #   0=off (default)     
  37. #   1=W     
  38. #   2=R     
  39. #   3=both     
  40. #   7=W+some reads     
  41. #oplog = 0    
  42.     
  43. # Diagnostic/debugging option 动态调试项     
  44. #nocursors = true    
  45.     
  46. # Ignore query hints 忽略查询提示     
  47. #nohints = true    
  48. # 禁用http界面,默认为localhost:28017    
  49. # Disable the HTTP interface (Defaults to localhost:27018).这个端口号写的是错的     
  50. #nohttpinterface = true    
  51.     
  52. # 关闭服务器端脚本,这将极大的限制功能     
  53. # Turns off server-side scripting.  This will result in greatly limited     
  54. # functionality     
  55. #noscripting = true    
  56. # 关闭扫描表,任何查询将会是扫描失败     
  57. # Turns off table scans.  Any query that would do a table scan fails.     
  58. #notablescan = true    
  59. # 关闭数据文件预分配     
  60. # Disable data file preallocation.     
  61. #noprealloc = true    
  62. # 为新数据库指定.ns文件的大小,单位:MB     
  63. # Specify .ns file size for new databases.     
  64. # nssize = <size>     
  65.     
  66. # Accout token for Mongo monitoring server.     
  67. #mms-token = <token>     
  68. # mongo监控服务器的名称     
  69. # Server name for Mongo monitoring server.     
  70. #mms-name = <server-name>     
  71. # mongo监控服务器的ping 间隔     
  72. # Ping interval for Mongo monitoring server.     
  73. #mms-interval = <seconds>     
  74.     
  75. # Replication Options 复制选项     
  76.     
  77. # in replicated mongo databases, specify here whether this is a slave or master 在复制中,指定当前是从属关系     
  78. #slave = true    
  79. #source = master.example.com     
  80. # Slave only: specify a single database to replicate     
  81. #only = master.example.com     
  82. # or     
  83. #master = true    
  84. #source = slave.example.com    

进入Mongo命令行

[plain] view plain copy
  1. # mongo  
  2. MongoDB shell version: 2.6.12  
  3. connecting to: test  
  4. Welcome to the MongoDB shell.  
  5. For interactive help, type "help".  
  6. For more comprehensive documentation, see  
  7.     http://docs.mongodb.org/  
  8. Questions? Try the support group  
  9.     http://groups.google.com/group/mongodb-user  
  10. Server has startup warnings:   
  11. 2016-09-12T09:50:14.195+0800 [initandlisten]   
  12. 2016-09-12T09:50:14.195+0800 [initandlisten] ** WARNING: Readahead for /var/lib/mongodb is set to 4096KB  
  13. 2016-09-12T09:50:14.195+0800 [initandlisten] **          We suggest setting it to 256KB (512 sectors) or less  
  14. 2016-09-12T09:50:14.195+0800 [initandlisten] **          http://dochub.mongodb.org/core/readahead  
  15. >   

小结

通过yum安装是非常简单方便的,

不需要纠结依赖项的问题。

更多内容请参考官方文档。


转载自:http://blog.csdn.net/testcs_dn/article/details/50698572

原创粉丝点击