本文记录一下在CentOS 6.7上,yum安装Mongodb-server
安装Mongodb-server
使用yum install mongodb-server命令安装mongodb server~~~
[root@dev18 ~]# yum install mongodb-server
Loaded plugins: fastestmirror, security
Setting up Install Process
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package mongodb-server.x86_64 0:2.4.14-4.el6 will be installed
--> Processing Dependency: v8 for package: mongodb-server-2.4.14-4.el6.x86_64
--> Processing Dependency: libv8.so.3()(64bit) for package: mongodb-server-2.4.14-4.el6.x86_64
--> Processing Dependency: libtcmalloc.so.4()(64bit) for package: mongodb-server-2.4.14-4.el6.x86_64
--> Processing Dependency: libboost_thread-mt.so.5()(64bit) for package: mongodb-server-2.4.14-4.el6.x86_64
--> Processing Dependency: libboost_system-mt.so.5()(64bit) for package: mongodb-server-2.4.14-4.el6.x86_64
--> Processing Dependency: libboost_program_options-mt.so.5()(64bit) for package: mongodb-server-2.4.14-4.el6.x86_64
--> Processing Dependency: libboost_iostreams-mt.so.5()(64bit) for package: mongodb-server-2.4.14-4.el6.x86_64
--> Processing Dependency: libboost_filesystem-mt.so.5()(64bit) for package: mongodb-server-2.4.14-4.el6.x86_64
--> Running transaction check
---> Package boost-filesystem.x86_64 0:1.41.0-27.el6 will be installed
---> Package boost-iostreams.x86_64 0:1.41.0-27.el6 will be installed
---> Package boost-program-options.x86_64 0:1.41.0-27.el6 will be installed
---> Package boost-system.x86_64 0:1.41.0-27.el6 will be installed
---> Package boost-thread.x86_64 0:1.41.0-27.el6 will be installed
---> Package gperftools-libs.x86_64 0:2.0-11.el6.3 will be installed
--> Processing Dependency: libunwind.so.8()(64bit) for package: gperftools-libs-2.0-11.el6.3.x86_64
---> Package v8.x86_64 1:3.14.5.10-25.el6 will be installed
--> Processing Dependency: libicuuc.so.42()(64bit) for package: 1:v8-3.14.5.10-25.el6.x86_64
--> Processing Dependency: libicui18n.so.42()(64bit) for package: 1:v8-3.14.5.10-25.el6.x86_64
--> Processing Dependency: libicudata.so.42()(64bit) for package: 1:v8-3.14.5.10-25.el6.x86_64
--> Running transaction check
---> Package libicu.x86_64 0:4.2.1-12.el6 will be installed
---> Package libunwind.x86_64 0:1.1-3.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===========================================================================================================================
Package Arch Version Repository Size
===========================================================================================================================
Installing:
mongodb-server x86_64 2.4.14-4.el6 epel 5.1 M
Installing for dependencies:
boost-filesystem x86_64 1.41.0-27.el6 ISO 47 k
boost-iostreams x86_64 1.41.0-27.el6 ISO 39 k
boost-program-options x86_64 1.41.0-27.el6 ISO 108 k
boost-system x86_64 1.41.0-27.el6 ISO 26 k
boost-thread x86_64 1.41.0-27.el6 ISO 43 k
gperftools-libs x86_64 2.0-11.el6.3 epel 246 k
libicu x86_64 4.2.1-12.el6 ISO 4.9 M
libunwind x86_64 1.1-3.el6 epel 55 k
v8 x86_64 1:3.14.5.10-25.el6 epel 3.0 M
Transaction Summary
===========================================================================================================================
Install 10 Package(s)
Total download size: 14 M
Installed size: 46 M
Is this ok [y/N]: y
输入y
Is this ok [y/N]: y
Downloading Packages:
(1/10): gperftools-libs-2.0-11.el6.3.x86_64.rpm | 246 kB 00:00
(2/10): libunwind-1.1-3.el6.x86_64.rpm | 55 kB 00:00
(3/10): mongodb-server-2.4.14-4.el6.x86_64.rpm | 5.1 MB 00:00
(4/10): v8-3.14.5.10-25.el6.x86_64.rpm | 3.0 MB 00:00
(5/10): boost-iostreams-1.41.0-27.el6.x86_64.rpm | 39 kB 00:00
(6/10): boost-filesystem-1.41.0-27.el6.x86_64.rpm | 47 kB 00:00
(7/10): boost-thread-1.41.0-27.el6.x86_64.rpm | 43 kB 00:00
(8/10): boost-program-options-1.41.0-27.el6.x86_64.rpm | 108 kB 00:00
(9/10): boost-system-1.41.0-27.el6.x86_64.rpm | 26 kB 00:00
(10/10): libicu-4.2.1-12.el6.x86_64.rpm | 4.9 MB 00:00
---------------------------------------------------------------------------------------------------------------------------
Total 4.8 MB/s | 14 MB 00:02
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : boost-system-1.41.0-27.el6.x86_64 1/10
Installing : boost-filesystem-1.41.0-27.el6.x86_64 2/10
Installing : libicu-4.2.1-12.el6.x86_64 3/10
Installing : 1:v8-3.14.5.10-25.el6.x86_64 4/10
Installing : boost-program-options-1.41.0-27.el6.x86_64 5/10
Installing : boost-thread-1.41.0-27.el6.x86_64 6/10
Installing : boost-iostreams-1.41.0-27.el6.x86_64 7/10
Installing : libunwind-1.1-3.el6.x86_64 8/10
Installing : gperftools-libs-2.0-11.el6.3.x86_64 9/10
Installing : mongodb-server-2.4.14-4.el6.x86_64 10/10
Verifying : mongodb-server-2.4.14-4.el6.x86_64 1/10
Verifying : gperftools-libs-2.0-11.el6.3.x86_64 2/10
Verifying : libunwind-1.1-3.el6.x86_64 3/10
Verifying : 1:v8-3.14.5.10-25.el6.x86_64 4/10
Verifying : boost-iostreams-1.41.0-27.el6.x86_64 5/10
Verifying : boost-filesystem-1.41.0-27.el6.x86_64 6/10
Verifying : boost-thread-1.41.0-27.el6.x86_64 7/10
Verifying : boost-program-options-1.41.0-27.el6.x86_64 8/10
Verifying : boost-system-1.41.0-27.el6.x86_64 9/10
Verifying : libicu-4.2.1-12.el6.x86_64 10/10
Installed:
mongodb-server.x86_64 0:2.4.14-4.el6
Dependency Installed:
boost-filesystem.x86_64 0:1.41.0-27.el6 boost-iostreams.x86_64 0:1.41.0-27.el6
boost-program-options.x86_64 0:1.41.0-27.el6 boost-system.x86_64 0:1.41.0-27.el6
boost-thread.x86_64 0:1.41.0-27.el6 gperftools-libs.x86_64 0:2.0-11.el6.3
libicu.x86_64 0:4.2.1-12.el6 libunwind.x86_64 0:1.1-3.el6
v8.x86_64 1:3.14.5.10-25.el6
Complete!
可以看到安装Complete!
启动mongodb-server
使用service mongod start命令来启动mongo-server。
[root@dev18 ~]# service mongod start
Starting mongod: [ OK ]
[root@dev18 ~]#
验证MongoDB是否成功启动
我们可以检查日志内容来看,MongoDB是否成功启动~~
日志文件路径/var/log/mongodb/mongod.log,如果可以看到类似如下的结果:
[initandlisten] waiting for connections on port <port>
则表明MongoDB已经成功启动。
Wed Feb 15 08:16:08.784 [initandlisten] MongoDB starting : pid=4782 port=27017 dbpath=/var/lib/mongodb 64-bit host=dev18.gzhl.zhhl
Wed Feb 15 08:16:08.784 [initandlisten] db version v2.4.14
Wed Feb 15 08:16:08.784 [initandlisten] git version: nogitversion
Wed Feb 15 08:16:08.784 [initandlisten] build info: Linux buildvm-11.phx2.fedoraproject.org 4.7.2-201.fc24.x86_64 #1 SMP Fri Aug 26 15:58:40 UTC 2016 x86_64 BOOST_LIB_VERSION=1_41
Wed Feb 15 08:16:08.784 [initandlisten] allocator: tcmalloc
Wed Feb 15 08:16:08.784 [initandlisten] options: { bind_ip: "127.0.0.1", command: [ "run" ], config: "/etc/mongodb.conf", dbpath: "/var/lib/mongodb", fork: "true", journal: "true", logpath: "/var/log/mongodb/mongodb.log", nohttpinterface: "true", pidfilepath: "/var/run/mongodb/mongodb.pid", port: 27017, quiet: true }
Wed Feb 15 08:16:08.787 [initandlisten] journal dir=/var/lib/mongodb/journal
Wed Feb 15 08:16:08.787 [initandlisten] recover : no journal files present, no recovery needed
Wed Feb 15 08:16:08.863 [initandlisten] allocating new ns file /var/lib/mongodb/local.ns, filling with zeroes...
Wed Feb 15 08:16:08.909 [FileAllocator] allocating new datafile /var/lib/mongodb/local.0, filling with zeroes...
Wed Feb 15 08:16:08.909 [FileAllocator] creating directory /var/lib/mongodb/_tmp
Wed Feb 15 08:16:08.912 [FileAllocator] done allocating datafile /var/lib/mongodb/local.0, size: 64MB, took 0 secs
Wed Feb 15 08:16:08.913 [initandlisten] waiting for connections on port 27017
通过上述的日志文件内容,我们可以知道MongoDB已经成功启动~~
GUI工具连接MongoDB
本文采用mongobooster可视化工具来连接MongoDB,输入相关的ip地址,localhost改成MongoDB安装的机器ip即可。
遇到连接Mongo服务失败的错误信息。
遇到如上信息是因为mongodb的配置文件中bind_ip的默认ip地址为127.0.0.1,而我的客户端和mongo服务器不是同一台机器,最终导致失败~~
可以通过vim /etc/mongodb.conf命令来打开配置文件查看。
为了方便测试,我们先注释掉bind_ip。不过在实际使用中,为了安全性,不应该注释掉这个配置项~~~
注释掉bind_ip之后,我们可以重启服务~~
[root@dev18 usr]# service mongod stop
Stopping mongod: [ OK ]
[root@dev18 usr]# service mongod start
Starting mongod: [ OK ]
[root@dev18 usr]#
重新连接,连接成功~~~