(一)ubuntu系統上安裝Mongo資料庫
1. 準備安裝檔案
在mongo的官網點選download按鈕,找到Linux平台,選擇合适的檔案下載下傳,我下載下傳了:
mongodb-linux-x86_64-ubuntu1404-3.6.2.tgz
2. 安裝
其實這個檔案解壓就好,我在/opt檔案夾下建立了/mongo檔案夾,把安裝檔案放進去後進行解壓,講道理,現在就可以用了
3. 環境配置
這一步是為了在哪裡都可以調用mongo,而不是必須進入mongo的所在檔案夾
3.1 打開環境配置檔案
運作sudo gedit /etc/profile
3.2 對PATH進行配置
原本我的PATH長這樣的:
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
我添加了mongo的位置之後變成了這樣的:
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:/opt/mongo/mongodb-linux-x86_64-ubuntu1404-3.6.2/bin:$PATH
好了,儲存退出
3.3 使環境變量配置檔案生效
可以運作如下指令使得環境配置生效:
source /etc/profile
3.4 觀察是否安裝成功
好了,現在随便打開一個終端,輸入mongo -version,就可以顯示出mongo的版本了,代表安裝成功
(二)ubuntu系統上使用Mongo資料庫
mongo所在檔案夾下面有一個README檔案,打開檔案看到如下文字:
RUNNING
For command line options invoke:
$ ./mongod --help
To run a single server database:
$ sudo mkdir -p /data/db #this is the default database directory
$ ./mongod #this is the command to start the service of mongo,即可以開啟mongo服務
$
$ # The mongo javascript shell connects to localhost and test database by default:
$ ./mongo #this is the command to access the service of mongo,即可以連接配接mongo服務
> help
(三)ubuntu系統上安裝使用Robo 3T的mongo用戶端
1. 下載下傳安裝包
登入官網https://robomongo.org/download,選擇Linux系統,下載下傳合适的檔案,我下載下傳了
robo3t-1.1.1-linux-x86_64-c93c6b0.tar.gz
2. 安裝
将安裝包拷貝在/opt下建立的檔案夾/robo3t下面,解壓
(四)MongoDB的其它使用場景
1. 導入json檔案爲新的collection
./mongoimport --db admin -c nvd --type json /home/hadoop/Documents/mongo_data/vul_data/nvd.json