現在window下面安裝了一遍,覺得很簡單。然后就到linux下面裝一遍,結果各種報錯,還是值得寫個博客理一理。
首先到其官網上下載最新穩定版,解壓到目錄,如/usr/local/mongodb
然后切換到mongodb下,創建data文件夾和logs文件;
安裝步驟:
- 進入/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
如果權限不夠自行設置一下文件權限
啟動MongoDB服務
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 錯誤!
解決辦法:
1、在64系統里執行32位程序如果出現/lib/ld-linux.so.2:
bad ELF interpreter: No such file or directory,安裝下glic即可
yum install glibc.i686
2、error while loading shared libraries: libz.so.1:
cannot open shared object file: No such file or directory
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
即可結束進程