一、准备工作:
运行yum命令查看MongoDB的包信息
[root@vm ~]# yum info mongo-10gen
</div>
(提示没有相关匹配的信息,)
说明你的centos系统中的yum源不包含MongoDB的相关资源,所以要在使用yum命令安装MongoDB前需要增加yum源,也就是在 /etc/yum.repos.d/目录中增加 *.repo yum源配置文件,以下分别是针对centos 64位和32位不同的系统的MongoDB yum 源配置内容:
我们这里就将该文件命名为:/etc/yum.repos.d/10gen.repo
For 64-bit yum源配置:
vi /etc/yum.repos.d/10gen.repo
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64
gpgcheck=0
</div>
For 32-bit yum源配置:
vi /etc/yum.repos.d/10gen.repo
[10gen]
name=10gen Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/i686
gpgcheck=0
</div>
根据自己的系统选择相应的配置内容
查看系统是32位还是64位的方法:
$ uname -a
</div>
含有x86_64的那说明是64位的,例如我的centos6.0 64bit系统执行这个命令后显示:
Linux vm.centos6 2.6.32-71.29.1.el6.x86_64 #1 SMP Mon Jun 27 19:49:27 BST 2011 x86_64 x86_64 x86_64 GNU/Linux
</div>
做好yum源的配置后,如果配置正确执行下面的命令便可以查询MongoDB相关的信息:
查看mongoDB的服务器包的信息
[root@vm ~]# yum info mongo-10gen-server
****(省略多行不重要的信息)*********
Available Packages
Name : mongo-10gen-server
Arch : x86_64
Version : 1.8.2
Release : mongodb_1
Size : 4.7 M
Repo : 10gen
Summary : mongo server, sharding server, and support scripts
URL : http://www.mongodb.org
License : AGPL 3.0
Description: Mongo (from “huMONGOus”) is a schema-free document-oriented
: database.
:
: This package provides the mongo server software, mongo sharding
: server softwware, default configuration files, and init.d scripts.
[root@vm ~]#
</div>
查看客户端工具的信息
[root@vm ~]# yum info mongo-10gen
Loaded plugins: fastestmirror
**(省略多行不重要的信息)**
Installed Packages
Name : mongo-10gen
Arch : x86_64
Version : 1.8.2
Release : mongodb_1
Size : 55 M
Repo : 10gen
Summary : mongo client shell and tools
URL : http://www.mongodb.org
License : AGPL 3.0
Description: Mongo (from “huMONGOus”) is a schema-free document-oriented
: database. It features dynamic profileable queries, full indexing,
: replication and fail-over support, efficient storage of large
: binary data objects, and auto-sharding.
:
: This package provides the mongo shell, import/export tools, and
: other client utilities.
[root@vm ~]#
</div>
二、安装MongoDB的服务器端和客户端工具
1.安装服务器端:
[root@vm ~]# yum install mongo-10gen-server
[root@vm ~]# ls /usr/bin/mongo(tab键)
mongo mongod mongodump mongoexport mongofiles mongoimport mongorestore mongos mongostat
———————————————–
</div>
这些就是MongoDB的程序文件
因为mongo-10gen-server包依赖于mongo-10gen,所以安装了服务器后就不需要单独安装客户端工具包mongo-10gen了
2.单独安装可客户端:
[root@vm ~]# yum install mongo-10gen
</div>
3.检查
[root@vm ~]# /etc/init.d/mongod
Usage: /etc/init.d/mongod {start|stop|status|restart|reload|force-reload|condrestart}
[root@vm ~]# /etc/init.d/mongod status
mongod (pid 1341) is running…
[root@vm ~]#
</div>
说明安后服务器端已经在运行了
4.服务器配置: /etc/mongod.conf
[root@vm ~]# cat /etc/mongod.conf
# mongo.conf
#where to log
logpath=/var/log/mongo/mongod.log
logappend=true #以追加方式写入日志
# fork and run in background
fork = true
#port = 27017 #端口
dbpath=/var/lib/mongo #数据库文件保存位置
# Enables periodic logging of CPU utilization and I/O wait
#启用定期记录CPU利用率和 I/O 等待
#cpu = true
# Turn on/off security. Off is currently the default
# 是否以安全认证方式运行,默认是不认证的非安全方式
#noauth = true
#auth = true
# Verbose logging output.
# 详细记录输出
#verbose = true
# Inspect all client data for validity on receipt (useful for
# developing drivers)用于开发驱动程序时的检查客户端接收数据的有效性
#objcheck = true
# Enable db quota management 启用数据库配额管理,默认每个db可以有8个文件,可以用quotaFiles参数设置
#quota = true
# 设置oplog记录等级
# Set oplogging level where n is
# 0=off (default)
# 1=W
# 2=R
# 3=both
# 7=W+some reads
#oplog = 0
# Diagnostic/debugging option 动态调试项
#nocursors = true
# Ignore query hints 忽略查询提示
#nohints = true
# 禁用http界