(一)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客戶端
登錄官網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