MongoDB安裝(Standalone on SUSE、CentOS)
阿新 • • 發佈:2018-12-24
MongoDB提供了幾個安裝包:
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
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:
# vi /etc/yum.conf
新增:
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>
- 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;
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]