如今window下面安裝了一遍,以爲很簡單。而後就到linux下面裝一遍,結果各類報錯,仍是值得寫個博客理一理。linux
首先到其官網上下載最新穩定版,解壓到目錄,如/usr/local/mongodbc++
而後切換到mongodb下,建立data文件夾和logs文件;mongodb
安裝步驟:app
cd /usr/local
mkdir mongodb
tar -zxvf mongodb-linux-x86_64-2.6.7.tgz
cd mongodb-linux-x86_64-2.6.7 mv * /usr/local/mongodb
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
這個時候若是出現 以下錯誤:
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
便可結束進程