CentOS 6.7上尝试采用yum安装MongoDB (yum install mongodb-org),出现No package mongodb-org available的问题,本文给出问题的解决方法,并成功安装Mongodb。
问题
使用yum install mongodb-org命令,安装MongoDB,出现No package mongodb-org available. 问题。具体信息如下:
[root@dev03 ~]# yum install mongodb-orgLoaded plugins: fastestmirrorSetting up Install ProcessLoading mirror speeds from cached hostfileNo package mongodb-org available.Error: Nothing to do
解决方法
出现上述问题的原因是缺少可用的mongodb-org包
(No package mongodb-org available.)。
解决方法:
在/etc/yum.repos.d/目录下,创建一个mongodb.repo文件,指定MongoDB资源库即可。
使用 vim /etc/yum.repos.d/mongodb.repo命令,创建并打开文件mongodb.repo,
[root@dev03 etc]# vim /etc/yum.repos.d/mongodb.repo
在mongodb.repo文件中,添加MongoDB资源,这里获取的Mongo-org版本为最新的3.4。如:
[mongodb-org-3.4]name=MongoDB Repositorybaseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/gpgcheck=1enabled=1gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
安装
配置好MongoDB相关的信息之后,重新使用yum install mongodb-org命令安装mongodb-org。
[root@dev03 etc]# yum install mongodb-orgLoaded plugins: fastestmirrorSetting up Install ProcessLoading mirror speeds from cached hostfilemongodb-org-3.4 | 2.5 kB 00:00 mongodb-org-3.4/primary_db | 18 kB 00:00 Resolving Dependencies--> Running transaction check---> Package mongodb-org.x86_64 0:3.4.2-1.el6 will be installed--> Processing Dependency: mongodb-org-tools = 3.4.2 for package: mongodb-org-3.4.2-1.el6.x86_64--> Processing Dependency: mongodb-org-shell = 3.4.2 for package: mongodb-org-3.4.2-1.el6.x86_64--> Processing Dependency: mongodb-org-server = 3.4.2 for package: mongodb-org-3.4.2-1.el6.x86_64--> Processing Dependency: mongodb-org-mongos = 3.4.2 for package: mongodb-org-3.4.2-1.el6.x86_64--> Running transaction check---> Package mongodb-org-mongos.x86_64 0:3.4.2-1.el6 will be installed---> Package mongodb-org-server.x86_64 0:3.4.2-1.el6 will be installed---> Package mongodb-org-shell.x86_64 0:3.4.2-1.el6 will be installed---> Package mongodb-org-tools.x86_64 0:3.4.2-1.el6 will be installed--> Finished Dependency ResolutionDependencies Resolved============================================================================================================================================================================================================================================================================== Package Arch Version Repository Size==============================================================================================================================================================================================================================================================================Installing: mongodb-org x86_64 3.4.2-1.el6 mongodb-org-3.4 5.8 kInstalling for dependencies: mongodb-org-mongos x86_64 3.4.2-1.el6 mongodb-org-3.4 12 M mongodb-org-server x86_64 3.4.2-1.el6 mongodb-org-3.4 20 M mongodb-org-shell x86_64 3.4.2-1.el6 mongodb-org-3.4 11 M mongodb-org-tools x86_64 3.4.2-1.el6 mongodb-org-3.4 49 MTransaction Summary==============================================================================================================================================================================================================================================================================Install 5 Package(s)Total download size: 91 MInstalled size: 257 MIs this ok [y/N]:
选择 y
Is this ok [y/N]: yDownloading Packages:(1/5): mongodb-org-3.4.2-1.el6.x86_64.rpm | 5.8 kB 00:00 (2/5): mongodb-org-mongos-3.4.2-1.el6.x86_64.rpm | 12 MB 00:01 (3/5): mongodb-org-server-3.4.2-1.el6.x86_64.rpm | 20 MB 00:00 (4/5): mongodb-org-shell-3.4.2-1.el6.x86_64.rpm | 11 MB 00:00 (5/5): mongodb-org-tools-3.4.2-1.el6.x86_64.rpm | 49 MB 00:01 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total 15 MB/s | 91 MB 00:06 warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID a15703c6: NOKEYRetrieving key from https://www.mongodb.org/static/pgp/server-3.4.ascImporting GPG key 0xA15703C6: Userid: "MongoDB 3.4 Release Signing Key" From : https://www.mongodb.org/static/pgp/server-3.4.ascIs this ok [y/N]:
选择 y
Is this ok [y/N]: yDownloading Packages:(1/5): mongodb-org-3.4.2-1.el6.x86_64.rpm | 5.8 kB 00:00 (2/5): mongodb-org-mongos-3.4.2-1.el6.x86_64.rpm | 12 MB 00:01 (3/5): mongodb-org-server-3.4.2-1.el6.x86_64.rpm | 20 MB 00:00 (4/5): mongodb-org-shell-3.4.2-1.el6.x86_64.rpm | 11 MB 00:00 (5/5): mongodb-org-tools-3.4.2-1.el6.x86_64.rpm | 49 MB 00:01 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------Total 15 MB/s | 91 MB 00:06 warning: rpmts_HdrFromFdno: Header V3 RSA/SHA1 Signature, key ID a15703c6: NOKEYRetrieving key from https://www.mongodb.org/static/pgp/server-3.4.ascImporting GPG key 0xA15703C6: Userid: "MongoDB 3.4 Release Signing Key" From : https://www.mongodb.org/static/pgp/server-3.4.ascIs this ok [y/N]: yRunning rpm_check_debugRunning Transaction TestTransaction Test SucceededRunning TransactionWarning: RPMDB altered outside of yum. Installing : mongodb-org-server-3.4.2-1.el6.x86_64 1/5 Installing : mongodb-org-shell-3.4.2-1.el6.x86_64 2/5 Installing : mongodb-org-mongos-3.4.2-1.el6.x86_64 3/5 Installing : mongodb-org-tools-3.4.2-1.el6.x86_64 4/5 Installing : mongodb-org-3.4.2-1.el6.x86_64 5/5 Verifying : mongodb-org-tools-3.4.2-1.el6.x86_64 1/5 Verifying : mongodb-org-mongos-3.4.2-1.el6.x86_64 2/5 Verifying : mongodb-org-shell-3.4.2-1.el6.x86_64 3/5 Verifying : mongodb-org-3.4.2-1.el6.x86_64 4/5 Verifying : mongodb-org-server-3.4.2-1.el6.x86_64 5/5 Installed: mongodb-org.x86_64 0:3.4.2-1.el6 Dependency Installed: mongodb-org-mongos.x86_64 0:3.4.2-1.el6 mongodb-org-server.x86_64 0:3.4.2-1.el6 mongodb-org-shell.x86_64 0:3.4.2-1.el6 mongodb-org-tools.x86_64 0:3.4.2-1.el6 Complete![root@dev03 etc]#
至此 mongo-org 3.4就安装完成了。
启动
使用 service mongod start命令启动Mongo 服务
[root@dev03 ~]# service mongod startStarting mongod: [ OK ][root@dev03 ~]#
一般情况下,基本上就成功安装和启动Mongo服务,可以开启Mongo之旅了。
但是,有可能之前进行过安装、删除Mongo的相关操作,这个时候使用service mongod start命令启动时,可能会遇到如下的问题:
Error starting mongod. /var/run/mongodb/mongod.pid exists.
[root@dev03 srv]# service mongod startError starting mongod. /var/run/mongodb/mongod.pid exists.[root@dev03 srv]#
使用vim /var/log/mongodb/mongod.log命令来查看日志,
Failed to unlink socket file /tmp/mongodb-27017.sock Operation not permitted
详细截图如下:
解决问题:
这个问题的出现,主要是权限的问题,使用如下命令授权一下,然后重新启动即可。
chown mongod:mongod /tmp/mongodb-27017.sock
chown mongod:mongod /tmp/mongodb-27017.sock
[root@dev03 ~]# chown mongod:mongod /tmp/mongodb-27017.sock[root@dev03 ~]# service mongod startStarting mongod: [ OK ][root@dev03 ~]#