1. 程式人生 > >【一】MongoDB安裝及配置

【一】MongoDB安裝及配置

.org root 終端 配置 conn tin serve cal 數據文件

一、MongoDB安裝

1、下載並解壓

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.2.0.tgz
tar zxvf mongodb-linux-x86_64-rhel62-3.2.0.tgz

2、移動到指定目錄下

mv mongodb-linux-x86_64-rhel62-3.2.0 /usr/local/mongodb

3、添加到PATH中

vim /etc/profile
export PATH=/usr/local/mongodb/bin:$PATH
source /etc/profile

二、MongoDB配置啟動

1、創建數據目錄和日誌目錄

默認下,mongodb的數據目錄在/data/db,如果放到其他目錄啟動時需要指定--dbpath參數。

mkdir -p /data/db
mkdir -p /data/log
touch /data/log/mongodb.log

2、啟動mongod服務

[[email protected] log]# mongod --dbpath=/data/db --fork --logpath=/data/log/mongodb.log  #默認啟動27017端口
about to fork child process, waiting until server is ready for connections.
forked process: 45134
child process started successfully, parent exiting

參數說明:

--dbpath           #數據文件存儲路徑
--fork             #用子進程在後臺啟動,否則一直占有終端,用該參數時,必須指定logpath參數
--logpath          #日誌文件的存儲路徑
--httpinterface    #網頁管理mongodb接口,之前版本默認是開啟的,由於安全性,本版本默認是關閉的,如需要加上該參數啟動

3、連接到mongodb

技術分享
[[email protected] ~]# mongo
MongoDB shell version: 3.2.0
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
    http://docs.mongodb.org/
Questions? Try the support group
    http://groups.google.com/group/mongodb-user
Server has startup warnings: 
2015-11-29T11:04:05.002+0800 I CONTROL  [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2015-11-29T11:04:05.002+0800 I CONTROL  [initandlisten] 
2015-11-29T11:04:05.002+0800 I CONTROL  [initandlisten] 
2015-11-29T11:04:05.003+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is ‘always‘.
2015-11-29T11:04:05.003+0800 I CONTROL  [initandlisten] **        We suggest setting it to ‘never‘
2015-11-29T11:04:05.003+0800 I CONTROL  [initandlisten] 
2015-11-29T11:04:05.003+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is ‘always‘.
2015-11-29T11:04:05.003+0800 I CONTROL  [initandlisten] **        We suggest setting it to ‘never‘
2015-11-29T11:04:05.003+0800 I CONTROL  [initandlisten] 
> 2+3
5
技術分享

4、關閉mongod服務

mongod --dbpath=/data/db --fork --logpath=/data/log/mongodb.log --shutdown

【一】MongoDB安裝及配置