在CentOS中使用 yum 安裝MongoDB及服務器端配置

轉自 http://blog.csdn.net/zhangfeng19880710/article/details/20166853mongodb

Java代碼   收藏代碼
  1. 1、準備工做:  
  2.   
  3.   運行yum命令查看MongoDB的包信息 [root@vm ~]# yum info mongo-10gen  
  4. (提示沒有相關匹配的信息,)  
  5. 說明你的centos系統中的yum源不包含MongoDB的相關資源,因此要在使用yum命令安裝MongoDB前須要增長yum源,也就是在 /etc/yum.repos.d/目錄中增長 *.repo yum源配置文件,如下分別是針對centos 64位和32位不一樣的系統的MongoDB yum 源配置內容:  
  6.   
  7. 咱們這裏就將該文件命名爲:/etc/yum.repos.d/10gen.repo  
  8.   
  9. For 64-bit yum源配置:  
  10.   
  11. vi /etc/yum.repos.d/10gen.repo  
  12.   
  13. [10gen]  
  14. name=10gen Repository  
  15. baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64  
  16. gpgcheck=0  
  17. For 32-bit yum源配置:  
  18.   
  19. vi /etc/yum.repos.d/10gen.repo  
  20.   
  21. [10gen]  
  22. name=10gen Repository  
  23. baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686  
  24. gpgcheck=0  
  25. 根據本身的系統選擇相應的配置內容  
  26.   
  27. 查看系統是32位仍是64位的方法:  
  28.   
  29. $ uname -a  
  30.   
  31. 含有x86_64的那說明是64位的,例如個人centos6.0 64bit系統執行這個命令後顯示:  
  32.   
  33. Linux vm.centos6 2.6.32-71.29.1.el6.x86_64 #1 SMP Mon Jun 27 19:49:27 BST 2011 x86_64 x86_64 x86_64 GNU/Linux  
  34.    
  35.   
  36. 作好yum源的配置後,若是配置正確執行下面的命令即可以查詢MongoDB相關的信息:  
  37.   
  38. 查看mongoDB的服務器包的信息  
  39.   
  40. [root@vm ~]# yum info mongo-10gen-server  
  41. ****(省略多行不重要的信息)*********  
  42. Available Packages  
  43. Name       : mongo-10gen-server  
  44. Arch       : x86_64  
  45. Version    : 1.8.2  
  46. Release    : mongodb_1  
  47. Size       : 4.7 M  
  48. Repo       : 10gen  
  49. Summary    : mongo server, sharding server, and support scripts   
  50. URL        : http://www.mongodb.org  
  51. License    : AGPL 3.0  
  52. Description: Mongo (from "huMONGOus") is a schema-free document-oriented  
  53.            : database.  
  54.            :  
  55.            : This package provides the mongo server software, mongo sharding  
  56.            : server softwware, default configuration files, and init.d scripts.  
  57.   
  58. [root@vm ~]#  
  59.    
  60.   
  61. 查看客戶端工具的信息  
  62.   
  63. [root@vm ~]# yum info mongo-10gen  
  64. Loaded plugins: fastestmirror  
  65. **(省略多行不重要的信息)**  
  66. Installed Packages  
  67. Name       : mongo-10gen  
  68. Arch       : x86_64  
  69. Version    : 1.8.2  
  70. Release    : mongodb_1  
  71. Size       : 55 M  
  72. Repo       : 10gen  
  73. Summary    : mongo client shell and tools   
  74. URL        : http://www.mongodb.org  
  75. License    : AGPL 3.0  
  76. Description: Mongo (from "huMONGOus") is a schema-free document-oriented  
  77.            : database. It features dynamic profileable queries, full indexing,  
  78.            : replication and fail-over support, efficient storage of large  
  79.            : binary data objects, and auto-sharding.  
  80.            :  
  81.            : This package provides the mongo shell, import/export tools, and  
  82.            : other client utilities.  
  83.   
  84. [root@vm ~]#  
  85.    
  86.   
  87. 2、安裝MongoDB的服務器端和客戶端工具  
  88.   
  89. 1.安裝服務器端:  
  90.   
  91. [root@vm ~]# yum install mongo-10gen-server  
  92. [root@vm ~]# ls /usr/bin/mongo(tab鍵)  
  93. mongo         mongod        mongodump     mongoexport   mongofiles    mongoimport   mongorestore  mongos        mongostat  
  94.   
  95. -----------------------------------------------  
  96. 這些就是MongoDB的程序文件  
  97. 由於mongo-10gen-server包依賴於mongo-10gen,因此安裝了服務器後就不須要單獨安裝客戶端工具包mongo-10gen了  
  98.   
  99.    
  100.   
  101. 2.單獨安裝可客戶端:  
  102.   
  103. [root@vm ~]# yum install mongo-10gen  
  104.    
  105.   
  106. 3.檢查  
  107.   
  108. [root@vm ~]# /etc/init.d/mongod  
  109. Usage: /etc/init.d/mongod {start|stop|status|restart|reload|force-reload|condrestart}  
  110. [root@vm ~]# /etc/init.d/mongod status  
  111. mongod (pid 1341) is running...  
  112. [root@vm ~]#  
  113. 說明安後服務器端已經在運行了  
  114.   
  115.    
  116.   
  117. 4.服務器配置: /etc/mongod.conf  
  118.   
  119. [root@vm ~]# cat /etc/mongod.conf  
  120. # mongo.conf  
  121.   
  122. #where to log  
  123. logpath=/var/log/mongo/mongod.log  
  124.   
  125. logappend=true #以追加方式寫入日誌  
  126.   
  127. # fork and run in background  
  128. fork = true  
  129.   
  130. #port = 27017 #端口  
  131.   
  132. dbpath=/var/lib/mongo #數據庫文件保存位置  
  133.   
  134. # Enables periodic logging of CPU utilization and I/O wait  
  135. #啓用按期記錄CPU利用率和 I/O 等待  
  136. #cpu = true  
  137.   
  138. # Turn on/off security.  Off is currently the default  
  139. # 是否以安全認證方式運行,默認是不認證的非安全方式  
  140. #noauth = true  
  141. #auth = true  
  142.   
  143. # Verbose logging output.  
  144. # 詳細記錄輸出  
  145. #verbose = true  
  146.   
  147. # Inspect all client data for validity on receipt (useful for  
  148. # developing drivers)用於開發驅動程序時的檢查客戶端接收數據的有效性  
  149. #objcheck = true  
  150.   
  151. # Enable db quota management 啓用數據庫配額管理,默認每一個db能夠有8個文件,能夠用quotaFiles參數設置  
  152. #quota = true  
  153. # 設置oplog記錄等級  
  154. # Set oplogging level where n is  
  155. #   0=off (default)  
  156. #   1=W  
  157. #   2=R  
  158. #   3=both  
  159. #   7=W+some reads  
  160. #oplog = 0  
  161.   
  162. # Diagnostic/debugging option 動態調試項  
  163. #nocursors = true  
  164.   
  165. # Ignore query hints 忽略查詢提示  
  166. #nohints = true  
  167. # 禁用http界面,默認爲localhost:28017  
  168. # Disable the HTTP interface (Defaults to localhost:27018).這個端口號寫的是錯的  
  169. #nohttpinterface = true  
  170.   
  171. # 關閉服務器端腳本,這將極大的限制功能  
  172. # Turns off server-side scripting.  This will result in greatly limited  
  173. # functionality  
  174. #noscripting = true  
  175. # 關閉掃描表,任何查詢將會是掃描失敗  
  176. # Turns off table scans.  Any query that would do a table scan fails.  
  177. #notablescan = true  
  178. # 關閉數據文件預分配  
  179. # Disable data file preallocation.  
  180. #noprealloc = true  
  181. # 爲新數據庫指定.ns文件的大小,單位:MB  
  182. # Specify .ns file size for new databases.  
  183. # nssize = <size>  
  184.   
  185. # Accout token for Mongo monitoring server.  
  186. #mms-token = <token>  
  187. # mongo監控服務器的名稱  
  188. # Server name for Mongo monitoring server.  
  189. #mms-name = <server-name>  
  190. # mongo監控服務器的ping 間隔  
  191. # Ping interval for Mongo monitoring server.  
  192. #mms-interval = <seconds>  
  193.   
  194. # Replication Options 複製選項  
  195.   
  196. # in replicated mongo databases, specify here whether this is a slave or master 在複製中,指定當前是從屬關係  
  197. #slave = true  
  198. #source = master.example.com  
  199. # Slave only: specify a single database to replicate  
  200. #only = master.example.com  
  201. # or  
  202. #master = true  
  203. #source = slave.example.com  
  204. [root@vm ~]#  
  205. 以上是默認的配置文件中的一些參數,更多參數能夠用 mongod -h 命令來查看  
  206.   
  207.    
  208.   
  209. [root@vm ~]# mongod -h  
  210. Allowed options:  
  211.   
  212. General options:  
  213.   -h [ --help ]          show this usage information  
  214.   --version              show version information  
  215.   -f [ --config ] arg    configuration file specifying additional options 指定啓動配置文件路徑  
  216.   -v [ --verbose ]       be more verbose (include multiple times for more  
  217.                          verbosity e.g. -vvvvv)  
  218.   --quiet                quieter output  
  219.   --port arg             specify port number 端口  
  220.   --bind_ip arg          comma separated list of ip addresses to listen on -  
  221.                          all local ips by default 綁定ip,能夠多個  
  222.   --maxConns arg         max number of simultaneous connections 最大併發鏈接數  
  223.   --logpath arg          log file to send write to instead of stdout - has to  
  224.                          be a file, not directory 日誌文件路徑  
  225.   --logappend            append to logpath instead of over-writing 日誌寫入方式  
  226.   --pidfilepath arg      full path to pidfile (if not set, no pidfile is  
  227.                          created) pid文件路徑  
  228.   --keyFile arg          private key for cluster authentication (only for  
  229.                          replica sets)集羣認證私鑰,僅適用於副本集  
  230.   --unixSocketPrefix arg alternative directory for UNIX domain sockets  
  231.                          (defaults to /tmp)替代目錄  
  232.   --fork                 fork server process  
  233.   --auth                 run with security 使用認證方式運行  
  234.   --cpu                  periodically show cpu and iowait utilization 按期顯示的CPU和IO等待利用率  
  235.   --dbpath arg           directory for datafiles 數據庫文件路徑  
  236.   --diaglog arg          0=off 1=W 2=R 3=both 7=W+some reads oplog記錄等級  
  237.   --directoryperdb       each database will be stored in a separate directory  
  238.                          每一個數據庫存儲到單獨目錄  
  239.   --journal              enable journaling 記錄日誌,建議開啓,在異常宕機時能夠恢復一些數據  
  240.   --journalOptions arg   journal diagnostic options  
  241.   --ipv6                 enable IPv6 support (disabled by default)  
  242.   --jsonp                allow JSONP access via http (has security  
  243.                          implications)容許JSONP經過http訪問,該方式存在安全隱患  
  244.   --noauth               run without security 不帶安全認證的方式  
  245.   --nohttpinterface      disable http interface 禁用http接口  
  246.   --noprealloc           disable data file preallocation - will often hurt  
  247.                          performance 禁用數據文件的預分配,每每會損害性能  
  248.   --noscripting          disable scripting engine 禁用腳本引擎  
  249.   --notablescan          do not allow table scans 不容許表掃描  
  250.   --nounixsocket         disable listening on unix sockets禁止unix sockets監聽  
  251.   --nssize arg (=16)     .ns file size (in MB) for new databases 爲新數據設置.ns文件的大小  
  252.   --objcheck             inspect client data for validity on receipt 檢查在收到客戶端的數據的有效性  
  253.   --profile arg          0=off 1=slow, 2=all  
  254.   --quota                limits each database to a certain number of files (8  
  255.                          default)啓用數據庫配額管理,默認每一個db能夠有8個文件,能夠用quotaFiles參數設置  
  256.   --quotaFiles arg       number of files allower per db, requires --quota  
  257.   --rest                 turn on simple rest api 開啓rest api  
  258.   --repair               run repair on all dbs 修復全部數據庫  
  259.   --repairpath arg       root directory for repair files - defaults to dbpath修復文件的根目錄,默  
  260.                          認爲dbpath指定的目錄  
  261.   --slowms arg (=100)    value of slow for profile and console log  
  262.   --smallfiles           use a smaller default file size  
  263.   --syncdelay arg (=60)  seconds between disk syncs (0=never, but not  
  264.                          recommended)與硬盤同步數據的時間,默認60秒,0表示不一樣步到硬盤(不建議)  
  265.   --sysinfo              print some diagnostic system information打印一些診斷系統信息  
  266.   --upgrade              upgrade db if needed 若是必要,將數據庫文件升級到新的格式  
  267.                         (<=1.0到1.1+升級時所需的)  
  268.   
  269. Replication options:    複製選項  
  270.   --fastsync            indicate that this instance is starting from a dbpath  
  271.                         snapshot of the repl peer 從一個dbpath快照開始同步  
  272.   --autoresync          automatically resync if slave data is stale 自動同步,若是從機的數據不是新的  
  273.                         自動同步  
  274.   --oplogSize arg       size limit (in MB) for op log oplog的大小  
  275.   
  276. Master/slave options:   主/從配置選項  
  277.   --master              master mode 主模式  
  278.   --slave               slave mode  從屬模式  
  279.   --source arg          when slave: specify master as <server:port>從屬服務器上指定主服務器地址  
  280.   --only arg            when slave: specify a single database to replicate從屬服務器上指定要複製的  
  281.                         數據庫  
  282.   --slavedelay arg      specify delay (in seconds) to be used when applying  
  283.                         master ops to slave 指定從主服務器上同步數據的時間間隔 單位秒  
  284.   
  285. Replica set options:    副本集選項  
  286.   --replSet arg         arg is <setname>[/<optionalseedhostlist>]  
  287.                         參數:<名稱>[<種子主機列表>]  
  288.   
  289. Sharding options:       分片設置選項  
  290.   --configsvr           declare this is a config db of a cluster; default port  
  291.                         27019; default dir /data/configdb 聲明這是一個集羣的配置數據庫,  
  292.                         默認的端口是27019 默認的路徑是/data/configdb  
  293.   --shardsvr            declare this is a shard db of a cluster; default port  
  294.                         27018 聲明這是集羣的一個分片數據庫,默認端口爲27018  
  295.   --noMoveParanoia      turn off paranoid saving of data for moveChunk.  this  
  296.                         is on by default for now, but default will switch  
  297.                         關閉偏着保存大塊數據。如今它是默認的,可是會變換  
  298.   
  299. [root@vm ~]#  
相關文章
相關標籤/搜索