發現更方便的安裝方法,直接下載壓縮包,解壓後把目錄放到/usr/local目錄下,然後在把mongodb/bin加入到path中。這樣就可以使用了:
參考:http://www.runoob.com/mongodb/mongodb-linux-install.html
下載完安裝包,並解壓 tgz(以下示範的是 64 位元 Linux上的安裝) 。curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.6.tgz # 下載tar -zxvf mongodb-linux-x86_64-3.0.6.tgz # 解壓mv mongodb-linux-x86_64-3.0.6/ /usr/local/mongodb # 將解壓包拷貝到指定目錄MongoDB 的可執行檔位於 bin 目錄下,所以可以將其添加到 PATH 路徑中:export PATH=<mongodb-install-directory>/bin:$PATH< mongodb-install-directory > 為你 MongoDB 的安裝路徑。如本文的 /usr/local/mongodb
剛開始參照官網(https://docs.mongodb.org/master/tutorial/install-mongodb-on-red-hat/)上的步驟來安裝,但是總是訪問不了,提示http連線逾時,大概是被牆了,因為ping 這個網域名稱也不通。後來打算從源碼開始安裝,從github下載源碼之後又有python版本跟yum之間依賴的問題不好解決,伺服器上的軟體版本都太老了,一籌莫展之後發現官網上還有之前更早的版本,比如2.6的,索性就試試吧
建立/etc/yum.repos.d/mongodb-org-2.6.repo,寫入如下內容
[mongodb-org-2.6]name=MongoDB 2.6 Repositorybaseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/gpgcheck=0enabled=1
因為
To install a specific release of MongoDB, specify each component package individually and append the version number to the package name, as in the following example
所以在http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/RPMS/ 裡面找到2.6的檔案,比如mongodb-org-2.6.0-1,執行
yum install -y mongodb-org-2.6.0-1
系統會各種dependency都給安上
Setting up Install ProcessResolving Dependencies--> Running transaction check---> Package mongodb-org.x86_64 0:2.6.0-1 set to be updated--> Processing Dependency: mongodb-org-tools = 2.6.0 for package: mongodb-org--> Processing Dependency: mongodb-org-shell = 2.6.0 for package: mongodb-org--> Processing Dependency: mongodb-org-server = 2.6.0 for package: mongodb-org--> Processing Dependency: mongodb-org-mongos = 2.6.0 for package: mongodb-org--> Running transaction check---> Package mongodb-org-mongos.x86_64 0:2.6.0-1 set to be updated---> Package mongodb-org-server.x86_64 0:2.6.0-1 set to be updated---> Package mongodb-org-shell.x86_64 0:2.6.0-1 set to be updated---> Package mongodb-org-tools.x86_64 0:2.6.0-1 set to be updated--> Finished Dependency ResolutionDependencies Resolved============================================================================================================================================= Package Arch Version Repository Size=============================================================================================================================================Installing: mongodb-org x86_64 2.6.0-1 mongodb-org-2.6 4.6 kInstalling for dependencies: mongodb-org-mongos x86_64 2.6.0-1 mongodb-org-2.6 6.8 M mongodb-org-server x86_64 2.6.0-1 mongodb-org-2.6 8.9 M mongodb-org-shell x86_64 2.6.0-1 mongodb-org-2.6 4.2 M mongodb-org-tools x86_64 2.6.0-1 mongodb-org-2.6 88 MTransaction Summary=============================================================================================================================================Install 5 Package(s)Upgrade 0 Package(s)Total download size: 108 MDownloading Packages:(1/5): mongodb-org-2.6.0-1.x86_64.rpm | 4.6 kB 00:00 (2/5): mongodb-org-shell-2.6.0-1.x86_64.rpm | 4.2 MB 00:06 (3/5): mongodb-org-mongos-2.6.0-1.x86_64.rpm | 6.8 MB 00:06 (4/5): mongodb-org-server-2.6.0-1.x86_64.rpm | 8.9 MB 00:08 (5/5): mongodb-org-tools-2.6.0-1.x86_64.rpm | 88 MB 00:57 ---------------------------------------------------------------------------------------------------------------------------------------------Total 1.3 MB/s | 108 MB 01:21 Running rpm_check_debugRunning Transaction TestFinished Transaction TestTransaction Test SucceededRunning Transaction Installing : mongodb-org-server 1/5 Installing : mongodb-org-shell 2/5 Installing : mongodb-org-mongos 3/5 Installing : mongodb-org-tools 4/5 Installing : mongodb-org 5/5 Installed products updated.Installed: mongodb-org.x86_64 0:2.6.0-1 Dependency Installed: mongodb-org-mongos.x86_64 0:2.6.0-1 mongodb-org-server.x86_64 0:2.6.0-1 mongodb-org-shell.x86_64 0:2.6.0-1 mongodb-org-tools.x86_64 0:2.6.0-1 Complete!
啟動後如果遇到空間不足的問題,可以參考這裡(http://stackoverflow.com/questions/14584393/why-getting-error-mongod-dead-but-subsys-locked-and-insufficient-free-space-for)
我在執行service mongod start 時提示source: command not found ,只好執行 /etc/init.d/mongod start 或者/sbin/service mongod start 來啟動mongod。