1.1 MongoDB安裝
在MacOS X系統(tǒng)中,采用Homebrew安裝MongoDB警医。打開終端(Terminal)色罚,輸入如下:
brew install mongodb
安裝完成后窟扑,MongoDB所在目錄為/usr/local/Cellar/mongodb
, 該目錄結(jié)構(gòu)如下:
[xinhuan@MacBook-Pro] ~$ tree /usr/local/Cellar/mongodb/
/usr/local/Cellar/mongodb/
└── 3.4.7
├── INSTALL_RECEIPT.json
├── README
├── bin
│ ├── bsondump
│ ├── mongo
│ ├── mongod
│ ├── mongodump
│ ├── mongoexport
│ ├── mongofiles
│ ├── mongoimport
│ ├── mongooplog
│ ├── mongoperf
│ ├── mongoreplay
│ ├── mongorestore
│ ├── mongos
│ ├── mongostat
│ └── mongotop
└── homebrew.mxcl.mongodb.plist
2 directories, 17 files
[xinhuan@MacBook-Pro] ~$
默認(rèn)的配置文件為/usr/local/etc/mongod.conf
,配置文件內(nèi)容如下:
systemLog:
destination: file
path: /usr/local/var/log/mongodb/mongo.log
logAppend: true
storage:
dbPath: /usr/local/var/mongodb
net:
bindIp: 127.0.0.1
1.2 啟動MongoDB服務(wù)進(jìn)程
打開終端袋马,輸入如下:
mongod -f /usr/local/etc/mongod.conf
然后初澎,按回車鍵,就啟動了MongoDB服務(wù)進(jìn)程虑凛。
1.3 客戶端連接MongoDB
重新打開終端碑宴,輸入:mongo
,然后回車桑谍,顯示如下:
[xinhuan@MacBook-Pro] ~$ mongo
MongoDB shell version v3.4.7
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.7
Server has startup warnings:
2017-09-05T00:59:42.419+0800 I CONTROL [initandlisten]
2017-09-05T00:59:42.419+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2017-09-05T00:59:42.419+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2017-09-05T00:59:42.419+0800 I CONTROL [initandlisten]
2017-09-05T00:59:42.419+0800 I CONTROL [initandlisten]
2017-09-05T00:59:42.419+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
>
則表明連接成功延柠。
1.4 關(guān)閉MongoDB服務(wù)進(jìn)程
(1) 服務(wù)端直接關(guān)閉1.2中的服務(wù)進(jìn)程
(2) 客戶端使用管理員命令關(guān)閉
-
選擇admin數(shù)據(jù)庫
use admin;
-
關(guān)閉MongoDB服務(wù)
db.shutdownServer();
運行示例如下:
> use admin;
switched to db admin
> db.shutdownServer();
server should be down...
2017-09-05T01:19:29.094+0800 I NETWORK [thread1] trying reconnect to 127.0.0.1:27017 (127.0.0.1) failed
2017-09-05T01:19:29.095+0800 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, in(checking socket for error after poll), reason: Connection refused
2017-09-05T01:19:29.095+0800 I NETWORK [thread1] reconnect 127.0.0.1:27017 (127.0.0.1) failed failed
>