最近公司使用到了 mongodb ,很久没有使用过了,记录一下安装步骤吧,方便以后安装使用。

安装包说明:

mongodb-org

完整包,包含下面4个安装包

mongodb-org-server

包含mongod的进程,启动配置和初始化脚本

mongodb-org-mongos

包含mongod的进程.

mongodb-org-shell

Mongo shell

mongodb-org-tools

MongoDB tools: mongoimport bsondump, mongodump,mongoexport, mongofiles, mongooplog, mongoperf, mongorestore, mongostat, and mongotop.

Mongodb 安装使用说明:

**1、**创建一个yum 源

vi /etc/yum.repos.d/mongodb-org-3.2.repo

在repo 文件中添加

[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc

2、安装****yum ****

sudo yum install -y mongodb-org

如果需要指定版本,也可以这么安装

sudo yum install -y mongodb-org-3.2.6 mongodb-org-server-3.2.6 mongodb-org-shell-3.2.6 mongodb-org-mongos-3.2.6 mongodb-org-tools-3.2.6

由于公司的网络一直有问题,最后选择了 rpm 包安装。

[root@new-cdh1 mongodbsoft]# rpm -ivh mongodb-org-*
warning: mongodb-org-3.2.6-1.el6.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID ea312927: NOKEY
Preparing… ########################################### [100%]
1:mongodb-org-tools ########################################### [ 20%]
2:mongodb-org-shell ########################################### [ 40%]
3:mongodb-org-server ########################################### [ 60%]
4:mongodb-org-mongos ########################################### [ 80%]
5:mongodb-org ########################################### [100%]

3、启动 mongodb

sudo service mongod start
[root@new-cdh1 mongo]# service mongod start
Starting mongod: [ OK ]
[root@new-cdh1 mongo]#

4、添加开机启动

[root@new-cdh1 mongo]# chkconfig mongod on

完全卸载mongod

1、停止mongod

[root@new-cdh1 ~]# service mongod stop
Stopping mongod: [ OK ]
[root@new-cdh1 ~]# chkconfig mongod off

2、卸载安装包

[root@new-cdh1 ~]# yum erase $(rpm -qa | grep mongodb-org)
Loaded plugins: fastestmirror
Setting up Remove Process
Resolving Dependencies
–> Running transaction check
—> Package mongodb-org.x86_64 0:3.2.6-1.el6 will be erased
—> Package mongodb-org-mongos.x86_64 0:3.2.6-1.el6 will be erased
—> Package mongodb-org-server.x86_64 0:3.2.6-1.el6 will be erased
—> Package mongodb-org-shell.x86_64 0:3.2.6-1.el6 will be erased
—> Package mongodb-org-tools.x86_64 0:3.2.6-1.el6 will be erased
–> Finished Dependency Resolution

Dependencies Resolved

============================================================================================================================================================================================================================================
Package Arch Version Repository Size

Removing:
mongodb-org x86_64 3.2.6-1.el6 installed 0.0
mongodb-org-mongos x86_64 3.2.6-1.el6 installed 16 M
mongodb-org-server x86_64 3.2.6-1.el6 installed 34 M
mongodb-org-shell x86_64 3.2.6-1.el6 installed 20 M
mongodb-org-tools x86_64 3.2.6-1.el6 installed 136 M

Transaction Summary

Remove 5 Package(s)

Installed size: 206 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Erasing : mongodb-org-3.2.6-1.el6.x86_64 1/5
Erasing : mongodb-org-server-3.2.6-1.el6.x86_64 2/5
warning: /var/log/mongodb/mongod.log saved as /var/log/mongodb/mongod.log.rpmsave
warning: /etc/mongod.conf saved as /etc/mongod.conf.rpmsave
Erasing : mongodb-org-shell-3.2.6-1.el6.x86_64 3/5
Erasing : mongodb-org-mongos-3.2.6-1.el6.x86_64 4/5
Erasing : mongodb-org-tools-3.2.6-1.el6.x86_64 5/5
Verifying : mongodb-org-shell-3.2.6-1.el6.x86_64 1/5
Verifying : mongodb-org-tools-3.2.6-1.el6.x86_64 2/5
Verifying : mongodb-org-mongos-3.2.6-1.el6.x86_64 3/5
Verifying : mongodb-org-server-3.2.6-1.el6.x86_64 4/5
Verifying : mongodb-org-3.2.6-1.el6.x86_64 5/5

Removed:
mongodb-org.x86_64 0:3.2.6-1.el6 mongodb-org-mongos.x86_64 0:3.2.6-1.el6 mongodb-org-server.x86_64 0:3.2.6-1.el6 mongodb-org-shell.x86_64 0:3.2.6-1.el6 mongodb-org-tools.x86_64 0:3.2.6-1.el6

Complete!
[root@new-cdh1 ~]#

2、删除垃圾数据(data目录和log 目录)

[root@new-cdh1 ~]# rm -rf /var/log/mongodb
[root@new-cdh1 ~]# rm -rf /var/lib/mongo

END