(一)基礎環境設置
操做系統版本 :centos-7.4
MongoDB版本:MongoDB 4.2 社區版linux
(1)關閉防火牆
mongodb
# 關閉防火牆 [root@mongodbenterprise lib]# systemctl stop firewalld.service # 禁止firewall開機啓動 [root@mongodbenterprise lib]# systemctl disable firewalld.service # 確認防火牆爲not running狀態 [root@mongodbenterprise lib]# firewall-cmd --state not running
(2)關閉selinux
vim
[root@mongodbenterprise lib]# vim /etc/selinux/config
SELINUX=disabled
(3)安裝依賴包centos
yum install -y libcurl openssl
(二)安裝MongoDB
安裝路徑規劃:
安裝路徑:/opt/mongo-4.2/
數據文件路徑:/mongo/data/
錯誤日誌路徑:/mongo/log/mongodb.log
配置文件:/mongo/mongodb.confcurl
(1)下載安裝包url
須要注意的是,redhat/centos是相似的Linux系統,能夠簡單地理解爲:centos是redhat的社區版。所以直接下載os爲redhat7的tar包便可。spa
(2)解壓安裝包
操作系統
[root@mongoserver ~]# ls anaconda-ks.cfg mongodb-linux-x86_64-rhel70-4.2.7.tgz [root@mongoserver ~]# tar -xzvf mongodb-linux-x86_64-rhel70-4.2.7.tgz [root@mongoserver ~]# ls anaconda-ks.cfg mongodb-linux-x86_64-rhel70-4.2.7 mongodb-linux-x86_64-rhel70-4.2.7.tgz
(3)安裝MongoDB
tar包是不須要安裝的,解壓到安裝位置便可,個人安裝位置是/opt/mongo-4.2日誌
[root@mongoserver ~]# ls anaconda-ks.cfg mongodb-linux-x86_64-rhel70-4.2.7 mongodb-linux-x86_64-rhel70-4.2.7.tgz [root@mongoserver ~]# mv mongodb-linux-x86_64-rhel70-4.2.7 /opt/ [root@mongoserver ~]# cd /opt [root@mongoserver opt]# ls mongodb-linux-x86_64-rhel70-4.2.7 [root@mongoserver opt]# mv mongodb-linux-x86_64-rhel70-4.2.7/ mongodb-4.2 [root@mongoserver opt]# ls mongodb-4.2
(4)添加配置文件/mongo/mongodb.confcode
[root@mongoserver ~]# vim /mongo/mongodb.conf # mongod.conf # for documentation of all options, see: # http://docs.mongodb.org/manual/reference/configuration-options/ # where to write logging data. systemLog: destination: file logAppend: true path: /mongo/log/mongodb.log # Where and how to store data. storage: dbPath: /mongo/data journal: enabled: true # engine: # wiredTiger: # how the process runs processManagement: fork: true # fork and run in background pidFilePath: /mongo/mongod.pid # location of pidfile timeZoneInfo: /usr/share/zoneinfo # network interfaces net: port: 27017 bindIp: 0.0.0.0 # Enter 0.0.0.0,:: to bind to all IPv4 and IPv6 addresses or, alternatively, use the net.bindIpAll setting.
建立相關路徑:
mkdir -p /mongo/log/ mkdir -p /mongo/data/
(5)將mongo的目錄添加到PATH中,以便於操做系統能識別到mongo命令
[root@mongoserver ~]# vim /etc/profile # 在文件末尾添加 PATH=$PATH:$HOME/bin:/opt/mongodb-4.2/bin # 使profile中的參數生效 [root@mongoserver ~]# source /etc/profile
(6)建立運行用戶mongod
[root@mongoserver ~]# groupadd mongod [root@mongoserver ~]# useradd -g mongod mongod 受權: [root@mongoserver ~]# chown -R mongod:mongod /mongo
(7)運行MongoDB
[root@mongoserver log]# mongod -config /mongo/mongodb.conf about to fork child process, waiting until server is ready for connections. forked process: 2137 child process started successfully, parent exiting # 或下面的方式 mongod -f /mongo/mongodb.conf
(8)查看運行狀態
[root@mongoserver log]# ps -ef|grep mongo root 2036 1 8 01:03 ? 00:00:00 mongod -config /mongo/mongodb.conf root 2072 1309 0 01:03 pts/0 00:00:00 grep --color=auto mongo
(9)關閉MongoDB
[root@mongoserver log]# mongod --shutdown --config /mongo/mongodb.conf killing process with pid: 2082
【完】