linux下安裝mongodb,以及解決安裝報錯問題

如今window下面安裝了一遍,以爲很簡單。而後就到linux下面裝一遍,結果各類報錯,仍是值得寫個博客理一理。linux

 

首先到其官網上下載最新穩定版,解壓到目錄,如/usr/local/mongodbc++

 

而後切換到mongodb下,建立data文件夾和logs文件;mongodb

 

安裝步驟:app

 

  • 進入/usr/local目錄下
  • cd /usr/local

     

  • 建立mongodb文件夾,做爲安裝目標文件夾
    mkdir mongodb

     

  • 解壓縮文件,而且移動到mongodb文件夾下
    tar -zxvf mongodb-linux-x86_64-2.6.7.tgz

     

  • 移動解壓縮後的文件夾下的全部文件到mongodb文件夾下
    cd mongodb-linux-x86_64-2.6.7
    mv * /usr/local/mongodb

     

  • 建立data文件夾用於存放數據,建立logs文件用於存放文件
    cd /usr/local/mongodb
    mkdir data
    touch logs

 

若是權限不夠自行設置一下文件權限ide

 

啓動MongoDB服務ui

cd bin
./mongod -dbpath=/usr/local/mongodb/data -logpath=/usr/local/mongodb/logs

 這個時候若是出現  ./mongod: /lib/ld-linux.so.2: bad ELF interpreter: No such file or directory 錯誤!this

解決辦法spa

一、在64系統裏執行32位程序若是出現/lib/ld-linux.so.2: 
bad ELF interpreter: No such file or directory,安裝下glic便可
code

 

 yum install glibc.i686



二、error while loading shared libraries: libz.so.1: 
cannot open shared object file: No such file or directory
blog

 

 yum install zlib.i686

 

 

 而後繼續啓動MongoDB服務

cd bin
./mongod -dbpath=/usr/local/mongodb/data -logpath=/usr/local/mongodb/logs

這個時候若是出現  error while loading shared libraries: libstdc++.so.6: cannot open shared object file: No such file or directory  錯誤!

 

解決辦法:執行命令: yum whatprovides libstdc++.so.6 

yum whatprovides libstdc++.so.6 
[root@iZ2ze7dyjfik9i0bgl5o1cZ mongodb]# yum whatprovides libstdc++.so.6
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
libstdc++-4.4.7-18.el6.i686 : GNU Standard C++ Library
Repo        : base
Matched from:
Other       : libstdc++.so.6



libstdc++-4.4.7-18.el6.i686 : GNU Standard C++ Library
Repo        : installed
Matched from:
Other       : Provides-match: libstdc++.so.6

[root@iZ2ze7dyjfik9i0bgl5o1cZ mongodb]# yum install libstdc++-4.4.7-3.el6.i686

這個時候若是出現 以下錯誤:

 

Error:  Multilib version problems found. This often means that the root

       cause is something else and multilib version checking is just

       pointing out that there is a problem. Eg.:

      

         1. You have an upgrade for libstdc++ which is missing some

            dependency that another package requires. Yum is trying to

            solve this by installing an older version of libstdc++ of the

            different architecture. If you exclude the bad architecture

            yum will tell you what the root cause is (which package

            requires what). You can try redoing the upgrade with

            --exclude libstdc++.otherarch ... this should give you an error

            message showing the root cause of the problem.

      

         2. You have multiple architectures of libstdc++ installed, but

            yum can only see an upgrade for one of those arcitectures.

            If you don't want/need both architectures anymore then you

            can remove the one with the missing update and everything

            will work.

      

         3. You have duplicate versions of libstdc++ installed already.

            You can use "yum check" to get yum show these errors.

      

       ...you can also use --setopt=protected_multilib=false to remove

       this checking, however this is almost never the correct thing to

       do as something else is very likely to go wrong (often causing

       much more problems).

      

       Protected multilib versions: libstdc++-4.4.7-18.el6.i686 != libstdc++-4.4.7-4.el6.x86_64

 

 是由於 多個庫共存衝突

解決辦法:

 

 [root@iZ2ze7dyjfik9i0bgl5o1cZ mongodb]# yum install libstdc++-4.4.7-3.el6.i686 --setopt=protected_multilib=false

 

再次啓動MongoDB服務

cd bin
./mongod -dbpath=/usr/local/mongodb/data -logpath=/usr/local/mongodb/logs

完成!

 

 

後臺服務啓動

./mongod -dbpath=/usr/local/mongodb/data -logpath=/usr/local/mongodb/logs --fork

後臺權限啓動

./mongod -dbpath=/usr/local/mongodb/data -logpath=/usr/local/mongodb/logs --fork --auth
 

 如今mongodb就能啓動成功了。若是已經啓動,則能夠先終止,等配置完在從新啓動。

 

注意,上述咱們啓動MongoDB都是手動使用mongod來啓動,這樣關閉計算機後,下次再進來它又沒啓動了,因此還得手動啓動,所以,爲避免這種繁瑣的工做,能夠把mongod放到服務自啓動項中,這樣計算機一開啓mongod服務也就啓動了。  
編輯/etc/rc.local,加入下述代碼而後再保存便可。  
 
1.#add mongonDB service

2.rm -rf /data/mongodb_data/* 
&& /usr/local/mongodb/bin/mongod  --dbpath=/data/mongodb_data/ --logpath=/data/mongodb_log/mongodb.log --logappend&  

 
咱們重啓計算機再看MongoDB是否啓動,重啓後能夠直接使用 mongo命令登陸,最終發現是能夠成功的。    另外,咱們使用mongo命令登陸MongoDB還要轉到mongo命令所在目錄再執行./mongo,這樣是否是有些麻煩?所以,咱們能夠簡化這點,將該命令文件copy到/usr/bin下,這樣就能夠在任何目錄下使用mongo命令了。 
netstat -anp

找到mongodb的pid 如3303

kill -9 3303

 

便可結束進程
相關文章
相關標籤/搜索