Mac MongoDB安裝
一、安裝
MongoDB的安裝方法有很多,本文以官方文檔中的兩種方法為準(zhǔn)。
1. 手動(dòng)安裝MongoDB Edition
? 也可以使用終端下載:
? curl -O https://fastdl.mongodb.org/osx-ssl/mongodb-osx-ssl-x86_64-3.4.10.tgz
-
解壓到安裝目錄
默認(rèn)目錄為
/usr/local
,解壓完成后修改文件夾名稱為(mongodb)刪掉后面的版本號(hào)闯捎,這一步也可以使用終端來完成:# 1. 解壓文件 tar -zxvf mongodb-osx-ssl-x86_64-3.4.10.tgz # 2. 新建mongodb文件夾 mkdir -p mongodb # 3. 將mongodb拷貝到新文件夾 cp -R -n mongodb-osx-ssl-x86_64-3.4.10/ mongodb
?
-
將安裝目錄添加到系統(tǒng)環(huán)境變量中
在終端中輸入:
export PATH=/usr/local/mongodv/bin:$PATH
如果你的mongodb不在此路徑中安裝椰弊,那么將上面path后面的路徑替換為mongodb的安裝路徑许溅。
注意:這樣添加環(huán)境變量的方式只在當(dāng)前打開的終端中有用瓤鼻,要想永久配置該變量請(qǐng)使用下面方法:- 打開當(dāng)前用戶環(huán)境變量配置文件:在終端中輸入
sudo vi ~/.bash_profile
- 在文檔中加入你的安裝路徑
export PATH=$PATH:/usr/local/mongodv/bin
,保存即可贤重。(英文輸入狀態(tài)下按字母i
茬祷,進(jìn)行編輯;按esc
后輸入:wq
保存離開
$ sudo vi ~/.bash_profile export PATH=$PATH:/usr/local/mongodv/bin ~ ~ ~
終端中使用
source .bash_profile
更新配置并蝗,使配置文件生效(此步驟可以用重啟終端代替)-
使用
echo $PATH
查看當(dāng)前系統(tǒng)環(huán)境變量$ echo $PATH /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:/usr/local/mongodb/bin
- 打開當(dāng)前用戶環(huán)境變量配置文件:在終端中輸入
2. 使用Homebrew
安裝MongoDB Binaries
-
首先更新你的
brew
brew update
-
安裝
MongoDB
使用終端:
brew install mongodb # TLS / SSL支持 brew install mongodb --with-openssl # 最新開發(fā)版本 brew install mongodb --devel
二祭犯、運(yùn)行MongoDB
-
在運(yùn)行
MongoDB
之前需要先啟動(dòng)mongod
進(jìn)程創(chuàng)建數(shù)據(jù)庫存儲(chǔ)目錄
/data/db
:sudo mkdir -p /data/db
,目錄路徑可以自定義-
啟動(dòng)
mongod
終端:
mongod # 如果上一步自定義了存儲(chǔ)路徑則需要使用 --dbpath 滚停,例如 mongod --dbpath /Volumes/documents/mango/db # 如果沒有創(chuàng)建全局路徑 PATH沃粗,需要進(jìn)入以下目錄 cd /usr/local/mongodb/bin && ./mongod
一切正常會(huì)顯示:
Last login: Thu Nov 23 10:23:48 on ttys000 promote:~ Keriy$ mongod --dbpath /Volumes/documents/mango/db 2017-11-23T11:00:24.635+0800 I CONTROL [initandlisten] MongoDB starting : pid=1038 port=27017 dbpath=/Volumes/documents/mango/db 64-bit host=promote.cache-dns.local 2017-11-23T11:00:24.635+0800 I CONTROL [initandlisten] db version v3.4.10 2017-11-23T11:00:24.635+0800 I CONTROL [initandlisten] git version: 078f28920cb24de0dd479b5ea6c66c644f6326e9 2017-11-23T11:00:24.635+0800 I CONTROL [initandlisten] OpenSSL version: OpenSSL 0.9.8zh 14 Jan 2016 2017-11-23T11:00:24.635+0800 I CONTROL [initandlisten] allocator: system 2017-11-23T11:00:24.635+0800 I CONTROL [initandlisten] modules: none 2017-11-23T11:00:24.635+0800 I CONTROL [initandlisten] build environment: 2017-11-23T11:00:24.635+0800 I CONTROL [initandlisten] distarch: x86_64 2017-11-23T11:00:24.636+0800 I CONTROL [initandlisten] target_arch: x86_64 2017-11-23T11:00:24.636+0800 I CONTROL [initandlisten] options: { storage: { dbPath: "/Volumes/documents/mango/db" } } 2017-11-23T11:00:24.639+0800 I - [initandlisten] Detected data files in /Volumes/documents/mango/db created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'. 2017-11-23T11:00:24.640+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1536M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0), 2017-11-23T11:00:25.235+0800 I CONTROL [initandlisten] 2017-11-23T11:00:25.235+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2017-11-23T11:00:25.235+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2017-11-23T11:00:25.235+0800 I CONTROL [initandlisten] 2017-11-23T11:00:25.235+0800 I CONTROL [initandlisten] 2017-11-23T11:00:25.256+0800 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/Volumes/documents/mango/db/diagnostic.data' 2017-11-23T11:00:25.257+0800 I NETWORK [thread1] waiting for connections on port 27017
?
-
運(yùn)行
MongoDB
終端:
mongo # 如果沒有創(chuàng)建全局路徑 PATH,需要進(jìn)入以下目錄 cd /usr/local/mongodb/bin && ./mongo
一切正常會(huì)顯示:
$ mongo MongoDB shell version v3.4.10 connecting to: mongodb://127.0.0.1:27017 MongoDB server version: 3.4.10 Server has startup warnings: 2017-11-23T11:00:25.235+0800 I CONTROL [initandlisten] 2017-11-23T11:00:25.235+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database. 2017-11-23T11:00:25.235+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted. 2017-11-23T11:00:25.235+0800 I CONTROL [initandlisten] 2017-11-23T11:00:25.235+0800 I CONTROL [initandlisten] 2017-11-23T11:00:25.235+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000 >
-
停止進(jìn)程
終端中:
ctrl + c
三键畴、可視化管理工具
robomongo現(xiàn)在改名叫 Robo 3T 最盅。