MongoDB提供了几个安装包:
- mongodb-org:负责安装下面四个包的基础包;
- mongodb-org-server:包含mongod后台程序、以及相关的配置文件和启动脚本;
- mongodb-org-mongos:包含mongos后台程序;
- mongodb-org-shell:包含mongo shell;
- mongodb-org-tools:包含这些工具:mongoimport bsondump, mongodump, mongoexport, mongofiles, mongooplog, mongoperf, mongorestore, mongostat, and mongotop;
安装步骤:
1、添加repo:
SUSE:
# zypper addrepo --no-gpgcheck https://repo.mongodb.org/zypper/suse/$(sed -rn 's/VERSION=.*([0-9]{2}).*/\1/p' /etc/os-release)/mongodb-org/3.2/x86_64/ mongodb
Adding repository 'mongodb' ...........................................................................................................................................................[done]
Repository 'mongodb' successfully added
Enabled: Yes
Autorefresh: No
GPG check: No
URI: https://repo.mongodb.org/zypper/suse/12/mongodb-org/3.2/x86_64/
CentOS:
#
vi /etc/yum.repos.d/mongodb-org-3.2.repo
添加:
[mongodb-org-3.2]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/
gpgcheck=0
enabled=1
2、开始安装(自动下载):
SUSE:
#
zypper -n install mongodb-org
Building repository 'mongodb' cache ...................................................................................................................................................[done]
Loading repository data...
Reading installed packages...
Resolving package dependencies...
The following 5 NEW packages are going to be installed:
mongodb-org mongodb-org-mongos mongodb-org-server mongodb-org-shell mongodb-org-tools
……
CentOS:
# yum install -y mongodb-org
……
3、锁定版本(防止自动升级,一定要在第2步安装完成后再做这一步)
SUSE:
#
zypper addlock mongodb-org-3.2.3 mongodb-org-server-3.2.3 mongodb-org-shell-3.2.3 mongodb-org-mongos-3.2.3 mongodb-org-tools-3.2.3
Specified locks have been successfully added.
CentOS:
添加:
exclude=mongodb-org,mongodb-org-server,mongodb-org-shell,mongodb-org-mongos,mongodb-org-tools
4、修改文件存放路径:
把缺省路径dbPath /var/lib/mongo改掉
#
vi /etc/mongod.conf
storage:
dbPath:
/opt/mongo
创建新路径:
#
mkdir -p
/opt/mongo
(
很重要)修改dbPath的owner和group属性,跟原来的dbPath(
/var/lib/mongo)一样,即“mongod”
:
#
chown mongod /opt/mongo
#
chgrp mongod /opt/mongo
5、启动:
#
service mongod start
查看是否启动成功:
#
service mongod status
mongod.service - LSB: Mongod
Loaded: loaded (/etc/init.d/mongod)
Active: active (running) since Fri 2016-02-19 18:27:34 CST; 1min 14s ago
Process: 28651 ExecStart=/etc/init.d/mongod start (code=exited, status=0/SUCCESS)
CGroup: /system.slice/mongod.service
└─28667 /usr/bin/mongod -f /etc/mongod.conf
Feb 19 18:27:34 linux-uxqf mongod[28651]: Starting mongod: ..done
查看log看具体的成功或错误信息:
#
tail -f /var/log/mongodb/mongod.log
如果成功,log中最后会显示:
[initandlisten] waiting for connections on port 27017
使服务随着系统启动自动启动:
#
chkconfig mongod on
其他相关命令:
停止服务:
service mongod stop
重启服务:
service mongod restart
卸载:
#
service mongod stop
SUSE:#
zypper remove $(rpm -qa | grep mongodb-org)
CentOS:#
yum erase $(rpm -qa | grep mongodb-org)
#
rm -r /var/log/mongodb
#
rm -r <data_dir>