MongoDB之安裝並配置

stonebox1122發表於2017-08-24
系統環境:
[root@D2-LZY245 ~]# cat /etc/centos-release
CentOS Linux release 7.2.1511 (Core)

如果是RHEL6版本,則需要先升級openssl:
[root@oeldb1 ~]# rpm -qa | grep openssl
openssl-devel-1.0.1e-57.el6.x86_64
openssl098e-0.9.8e-17.0.1.el6_2.2.x86_64
openssl-1.0.1e-57.el6.x86_64

安裝包及版本:
下載地址:
[root@D2-LZY245 ~]# ll mongodb-linux-x86_64-rhel70-3.4.7.tgz
-rw-rw-r-- 1 root root 100670645 Aug 10 17:06 mongodb-linux-x86_64-rhel70-3.4.7.tgz

建立安裝目錄:
[root@D2-LZY245 ~]# mkdir /usr/local/mongodb

解壓安裝包:
[root@D2-LZY245 ~]# tar -xvzf mongodb-linux-x86_64-rhel70-3.4.7.tgz

移動解壓後的檔案到安裝目錄:
[root@D2-LZY245 ~]# mv mongodb-linux-x86_64-rhel70-3.4.7/* /usr/local/mongodb/
[root@D2-LZY245 ~]# ll /usr/local/mongodb/
total 120
drwxrwxr-x 2 root root  4096 Aug 10 17:11 bin
-rw-r--r-- 1 root root 34520 Aug  8 03:37 GNU-AGPL-3.0
-rw-r--r-- 1 root root 16726 Aug  8 03:37 MPL-2
-rw-r--r-- 1 root root  1359 Aug  8 03:37 README
-rw-r--r-- 1 root root 55625 Aug  8 03:37 THIRD-PARTY-NOTICES

配置PATH:
[root@D2-LZY245 ~]# grep PATH .bash_profile
PATH=$PATH:$HOME/bin
export PATH
export CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH:/usr/local/mongodb/bin/

[root@D2-LZY245 ~]# source .bash_profile

建立資料庫目錄和日誌檔案:
[root@D2-LZY245 ~]# mkdir /usr/local/mongodb/db
[root@D2-LZY245 ~]# mkdir /usr/local/mongodb/log
[root@D2-LZY245 ~]# touch /usr/local/mongodb/log/mongodb.log

建立引數檔案:
[root@D2-LZY245 ~]# vim /usr/local/mongodb/mongodb.conf
dbpath=/usr/local/mongodb/db
logpath=/usr/local/mongodb/log/mongodb.log
logappend=true
noauth=true
port=27017
fork=true

啟動:
[root@D2-LZY245 ~]# mongod -f /usr/local/mongodb/mongodb.conf
about to fork child process, waiting until server is ready for connections.
forked process: 12610
child process started successfully, parent exiting

配置開機啟動:
[root@D2-LZY245 ~]# vi /etc/rc.d/rc.local
/usr/local/mongodb/bin/mongod –f /usr/local/mongodb/mongodb.conf

當MongoDB服務啟動後,可以使用mongo命令連線資料庫。
[root@oeldb1 ~]# mongo
MongoDB shell version v3.4.7
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.7
Welcome to the MongoDB shell.

#查詢所有資料庫:
> show databases;
admin  0.000GB
local  0.000GB

#關閉資料庫。
> use admin
switched to db admin
> db.shutdownServer();

或者:
[root@oeldb1 ~]# mongod -f /usr/local/mongodb/mongodb.conf --shutdown
killing process with pid: 11580

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/28536251/viewspace-2144058/,如需轉載,請註明出處,否則將追究法律責任。

相關文章