linux下安装mongodb,以及解决安装报错问题

现在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

 

即可结束进程
posted @ 2017-07-14 14:33  从此以往  阅读(11657)  评论(0编辑  收藏  举报