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

 

便可结束进程
相关文章
相关标签/搜索