CentOS 中使用 yum 安裝 mongodb


 

 

(一)准備工作

 

注意: 灰色背景均為命令行輸入

 

首先確保你的yum包含mongodb相關資源,運行下面命令查看

yum info mongo-10gen

如果沒有找到相關資源信息,那需要你自己把mongodb的源添加進去.

 

如何添加mongodb的源,首先需要確定你的操作系統是 32位還是 64位?

 

如何確定?使用下面的命令

uname -a

如果輸出的信息包含 x86_64 說明你的系統是64位,如果不包含說明是32位系統.不同版本的系統對應創建如下相關的源信息.

 

執行如下命令創建源

cd /etc/yum.repos.d/

nano 10gen.repo  //創建一個源文件 10gen.repo  你可以使用vi ,vim 命令等

 

32位:(把下面信息粘貼到 10gen.repo 文件里)

[10gen]  

name=10gen Repository  

baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686  

gpgcheck=0 

 

 

64位:(把下面的信息粘貼到 10gen.repo 文件里)

[10gen]  

name=10gen Repository  

baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64  

gpgcheck=0

 

你可以運行下面的命令來查看mongoDB的服務器包的信息是否生效

 

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.  

 

你可以運行下面的命令來查看mongoDB的客戶端包信息是否生效

 

yum info mongo-10gen  

(你看到下面的信息說明已經生效)

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.  

           

           

(二)開始安裝

 

1.mongodb 服務器端安裝,運行下面命令

yum install mongo-10gen-server  

可能需要你確認是否下載安裝,輸入y 並回車

 

2.mongodb 客戶端安裝,運行下面命令

yum install mongo-10gen

同樣可能需要你的確認,同上.

 

3.

經過一段時間的等待你看看到安裝成功的提示.這是需要檢查一下是否安裝成功,查看配置文件中的數據庫目錄和log文件目錄,確保你當前系統存在此目錄和文件,保證你的mongodb

使用的端口是被系統允許的且沒有被占用.

服務器配置文件在這里 /etc/mongod.conf,

 

查看默認配置運行下面的一條命令

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 命令來查看  

 

4.啟動mongodb,運行下面的命令

service mongod start

 

chkconfig mongod on

 

5.如果你要啟動客戶端,直接運行命令

mongo


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM