CentOS系統下MongoDB安裝及配置教程_MongoDB

來源:互聯網
上載者:User

一、準備工作:
運行yum命令查看MongoDB的包資訊

複製代碼 代碼如下:

[root@vm ~]# yum info mongo-10gen

(提示沒有相關匹配的資訊,)

說明你的centos系統中的yum源不包含MongoDB的相關資源,所以要在使用yum命令安裝MongoDB前需要增加yum源,也就是在 /etc/yum.repos.d/目錄中增加 *.repo yum源設定檔,以下分別是針對centos 64位和32位不同的系統的MongoDB yum 源配置內容:

我們這裡就將該檔案命名為:/etc/yum.repos.d/10gen.repo

For 64-bit yum源配置:

複製代碼 代碼如下:

vi /etc/yum.repos.d/10gen.repo

[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0


For 32-bit yum源配置:
複製代碼 代碼如下:

vi /etc/yum.repos.d/10gen.repo

[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
gpgcheck=0


根據自己的系統選擇相應的配置內容

查看系統是32位還是64位的方法:

複製代碼 代碼如下:

$ uname -a

含有x86_64的那說明是64位的,例如我的centos6.0 64bit系統執行這個命令後顯示:
複製代碼 代碼如下:

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

做好yum源的配置後,如果配置正確執行下面的命令便可以查詢MongoDB相關的資訊:

查看mongoDB的伺服器包的資訊

複製代碼 代碼如下:

[root@vm ~]# yum info mongo-10gen-server
****(省略多行不重要的資訊)*********
Available Packages
Name : mongo-10gen-server
Arch : x86_64
Version : 1.8.2
Release : mongodb_1
Size : 4.7 M
Repo : 10gen
Summary : mongo server, sharding server, and support scripts
URL : http://www.mongodb.org
License : AGPL 3.0
Description: Mongo (from “huMONGOus”) is a schema-free document-oriented
: database.
:
: This package provides the mongo server software, mongo sharding
: server softwware, default configuration files, and init.d scripts.

[root@vm ~]#


查看用戶端工具的資訊
複製代碼 代碼如下:

[root@vm ~]# yum info mongo-10gen
Loaded plugins: fastestmirror
**(省略多行不重要的資訊)**
Installed Packages
Name : mongo-10gen
Arch : x86_64
Version : 1.8.2
Release : mongodb_1
Size : 55 M
Repo : 10gen
Summary : mongo client shell and tools
URL : http://www.mongodb.org
License : AGPL 3.0
Description: Mongo (from “huMONGOus”) is a schema-free document-oriented
: database. It features dynamic profileable queries, full indexing,
: replication and fail-over support, efficient storage of large
: binary data objects, and auto-sharding.
:
: This package provides the mongo shell, import/export tools, and
: other client utilities.

[root@vm ~]#

二、安裝MongoDB的伺服器端和用戶端工具

1.安裝伺服器端:

複製代碼 代碼如下:

[root@vm ~]# yum install mongo-10gen-server
[root@vm ~]# ls /usr/bin/mongo(tab鍵)
mongo mongod mongodump mongoexport mongofiles mongoimport mongorestore mongos mongostat

———————————————–


這些就是MongoDB的程式檔案

因為mongo-10gen-server包依賴於mongo-10gen,所以安裝了伺服器後就不需要單獨安裝用戶端工具包mongo-10gen了

2.單獨安裝可用戶端:

複製代碼 代碼如下:

[root@vm ~]# yum install mongo-10gen

3.檢查
複製代碼 代碼如下:

[root@vm ~]# /etc/init.d/mongod
Usage: /etc/init.d/mongod {start|stop|status|restart|reload|force-reload|condrestart}
[root@vm ~]# /etc/init.d/mongod status
mongod (pid 1341) is running…
[root@vm ~]#

說明安後伺服器端已經在運行了

4.伺服器配置: /etc/mongod.conf

複製代碼 代碼如下:

[root@vm ~]# cat /etc/mongod.conf
# mongo.conf
 
#where to log
logpath=/var/log/mongo/mongod.log
 
logappend=true #以追加方式寫入日誌
 
# fork and run in background
fork = true
 
#port = 27017 #連接埠
 
dbpath=/var/lib/mongo #資料庫檔案儲存位置
 
# Enables periodic logging of CPU utilization and I/O wait
#啟用定期記錄CPU利用率和 I/O 等待
#cpu = true
 
# Turn on/off security.  Off is currently the default
# 是否以安全認證方式運行,預設是不認證的非安全方式
#noauth = true
#auth = true
 
# Verbose logging output.
# 詳細記錄輸出
#verbose = true
 
# Inspect all client data for validity on receipt (useful for
# developing drivers)用於開發驅動程式時的檢查用戶端接收資料的有效性
#objcheck = true
 
# Enable db quota management 啟用資料庫配額管理,預設每個db可以有8個檔案,可以用quotaFiles參數設定
#quota = true
# 設定oplog記錄等級
# Set oplogging level where n is
#   0=off (default)
#   1=W
#   2=R
#   3=both
#   7=W+some reads
#oplog = 0
 
# Diagnostic/debugging option 動態調試項
#nocursors = true
 
# Ignore query hints 忽略查詢提示
#nohints = true
# 禁用http介面,預設為localhost:28017
# Disable the HTTP interface (Defaults to localhost:27018).這個連接埠號碼寫的是錯的
#nohttpinterface = true
 
# 關閉伺服器端指令碼,這將極大的限制功能
# Turns off server-side scripting.  This will result in greatly limited
# functionality
#noscripting = true
# 關閉掃描表,任何查詢將會是掃描失敗
# Turns off table scans.  Any query that would do a table scan fails.
#notablescan = true
# 關閉資料檔案預分配
# Disable data file preallocation.
#noprealloc = true
# 為新資料庫指定.ns檔案的大小,單位:MB
# Specify .ns file size for new databases.
# nssize = <size>
 
# Accout token for Mongo monitoring server.
#mms-token = <token>
# mongo監控伺服器的名稱
# Server name for Mongo monitoring server.
#mms-name = <server-name>
# mongo監控伺服器的ping 間隔
# Ping interval for Mongo monitoring server.
#mms-interval = <seconds>
 
# Replication Options 複製選項
 
# in replicated mongo databases, specify here whether this is a slave or master 在複製中,指定當前是從屬關係
#slave = true
#source = master.example.com
# Slave only: specify a single database to replicate
#only = master.example.com
# or
#master = true
#source = slave.example.com
[root@vm ~]#
 
以上是預設的設定檔中的一些參數,更多參數可以用 mongod -h 命令來查看
 
[root@vm ~]# mongod -h
Allowed options:
 
General options:
  -h [ --help ]          show this usage information
  --version              show version information
  -f [ --config ] arg    configuration file specifying additional options 指定啟動設定檔路徑
  -v [ --verbose ]       be more verbose (include multiple times for more
                         verbosity e.g. -vvvvv)
  --quiet                quieter output
  --port arg             specify port number 連接埠
  --bind_ip arg          comma separated list of ip addresses to listen on -
                         all local ips by default 綁定ip,可以多個
  --maxConns arg         max number of simultaneous connections 最大並發串連數
  --logpath arg          log file to send write to instead of stdout - has to
                         be a file, not directory 記錄檔路徑
  --logappend            append to logpath instead of over-writing 日誌寫入方式
  --pidfilepath arg      full path to pidfile (if not set, no pidfile is
                         created) pid檔案路徑
  --keyFile arg          private key for cluster authentication (only for
                         replica sets)叢集認證私密金鑰,僅適用於複本集
  --unixSocketPrefix arg alternative directory for UNIX domain sockets
                         (defaults to /tmp)替代目錄
  --fork                 fork server process
  --auth                 run with security 使用認證方式運行
  --cpu                  periodically show cpu and iowait utilization 定期顯示的CPU和IO等待利用率
  --dbpath arg           directory for datafiles 資料庫檔案路徑
  --diaglog arg          0=off 1=W 2=R 3=both 7=W+some reads oplog記錄等級
  --directoryperdb       each database will be stored in a separate directory
                         每個資料庫儲存到單獨目錄
  --journal              enable journaling 記錄日誌,建議開啟,在異常宕機時可以恢複一些資料
  --journalOptions arg   journal diagnostic options
  --ipv6                 enable IPv6 support (disabled by default)
  --jsonp                allow JSONP access via http (has security
                         implications)允許JSONP通過http訪問,該方式存在安全隱患
  --noauth               run without security 不帶安全認證的方式
  --nohttpinterface      disable http interface 禁用http介面
  --noprealloc           disable data file preallocation - will often hurt
                         performance 禁用資料檔案的預分配,往往會損害效能
  --noscripting          disable scripting engine 禁用指令碼引擎
  --notablescan          do not allow table scans 不允許表掃描
  --nounixsocket         disable listening on unix sockets禁止unix sockets監聽
  --nssize arg (=16)     .ns file size (in MB) for new databases 為新資料設定.ns檔案的大小
  --objcheck             inspect client data for validity on receipt 檢查在收到用戶端的資料的有效性
  --profile arg          0=off 1=slow, 2=all
  --quota                limits each database to a certain number of files (8
                         default)啟用資料庫配額管理,預設每個db可以有8個檔案,可以用quotaFiles參數設定
  --quotaFiles arg       number of files allower per db, requires --quota
  --rest                 turn on simple rest api 開啟rest api
  --repair               run repair on all dbs 修複所有資料庫
  --repairpath arg       root directory for repair files - defaults to dbpath修複檔案的根目錄,默
                         認為dbpath指定的目錄
  --slowms arg (=100)    value of slow for profile and console log
  --smallfiles           use a smaller default file size
  --syncdelay arg (=60)  seconds between disk syncs (0=never, but not
                         recommended)與硬碟同步資料的時間,預設60秒,0表示不同步到硬碟(不建議)
  --sysinfo              print some diagnostic system information列印一些診斷系統資訊
  --upgrade              upgrade db if needed 如果必要,將資料庫檔案升級到新的格式
                        (<=1.0到1.1+升級時所需的)
 
Replication options:    複製選項
  --fastsync            indicate that this instance is starting from a dbpath
                        snapshot of the repl peer 從一個dbpath快照開始同步
  --autoresync          automatically resync if slave data is stale 自動同步,如果從機的資料不是新的
                        自動同步
  --oplogSize arg       size limit (in MB) for op log oplog的大小
 
Master/slave options:   主/從配置選項
  --master              master mode 主模式
  --slave               slave mode  從屬模式
  --source arg          when slave: specify master as <server:port>從屬伺服器上指定主伺服器地址
  --only arg            when slave: specify a single database to replicate從屬伺服器上指定要複製的
                        資料庫
  --slavedelay arg      specify delay (in seconds) to be used when applying
                        master ops to slave 指定從主伺服器上同步資料的時間間隔 單位秒
 
Replica set options:    複本集選項
  --replSet arg         arg is <setname>[/<optionalseedhostlist>]
                        參數:<名稱>[<種子主機列表>]
 
Sharding options:       分區設定選項
  --configsvr           declare this is a config db of a cluster; default port
                        27019; default dir /data/configdb 聲明這是一個叢集的設定資料庫,
                        預設的連接埠是27019 預設的路徑是/data/configdb
  --shardsvr            declare this is a shard db of a cluster; default port
                        27018 聲明這是叢集的一個分區資料庫,預設連接埠為27018
  --noMoveParanoia      turn off paranoid saving of data for moveChunk.  this
                        is on by default for now, but default will switch
                        關閉偏著儲存大塊資料。現在它是預設的,但是會變換
 
[root@vm ~]#

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.