您好,登錄后才能下訂單哦!
本篇內(nèi)容主要講解“MongoDB怎么安裝并配置”,感興趣的朋友不妨來看看。本文介紹的方法操作簡(jiǎn)單快捷,實(shí)用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“MongoDB怎么安裝并配置”吧!
系統(tǒng)環(huán)境:
[root@D2-LZY245 ~]# cat /etc/centos-release
CentOS Linux release 7.2.1511 (Core)
如果是RHEL6版本,則需要先升級(jí)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
安裝包及版本:
下載地址:https://www.mongodb.com/download-cente
[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
創(chuàng)建安裝目錄:
[root@D2-LZY245 ~]# mkdir /usr/local/mongodb
解壓安裝包:
[root@D2-LZY245 ~]# tar -xvzf mongodb-linux-x86_64-rhel70-3.4.7.tgz
移動(dòng)解壓后的文件到安裝目錄:
[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
創(chuàng)建數(shù)據(jù)庫目錄和日志文件:
[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
創(chuàng)建參數(shù)文件:
[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
啟動(dòng):
[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
配置開機(jī)啟動(dòng):
[root@D2-LZY245 ~]# vi /etc/rc.d/rc.local
/usr/local/mongodb/bin/mongod –f /usr/local/mongodb/mongodb.conf
當(dāng)MongoDB服務(wù)啟動(dòng)后,可以使用mongo命令連接數(shù)據(jù)庫。
[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.
#查詢所有數(shù)據(jù)庫:
> show databases;
admin 0.000GB
local 0.000GB
#關(guān)閉數(shù)據(jù)庫。
> use admin
switched to db admin
> db.shutdownServer();
或者:
[root@oeldb1 ~]# mongod -f /usr/local/mongodb/mongodb.conf --shutdown
killing process with pid: 11580
到此,相信大家對(duì)“MongoDB怎么安裝并配置”有了更深的了解,不妨來實(shí)際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。