mac install mongodb
一、準(zhǔn)備環(huán)境
gaodongdeMacBook-Pro:~ gaodong$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.12.6
BuildVersion: 16G29
1、mac安裝homebrew
? ? ? /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2、homebrew安裝MongoDB?
brew list
brew search mongodb
brew install mongodb
brew install mongodb --devel安裝最新版本
安裝在/usr/local/Cellar/mongodb/4.0.3_1通過(guò)brew命令下載的文件都存在/usr/local/Cellar/文件夾下
同時(shí)也會(huì)在/usr/loacl/etc下生成一個(gè)mongod.conf配置文件
配置:
Mac使用brew方式安裝軟件默認(rèn)存放在/usr/local/Cellar目錄下,同時(shí)也會(huì)在/usr/loacl/etc下生成配置文件:
Mac配置環(huán)境變量:
cd ~
echo $PATH
一般環(huán)境變量在以下文件:
cat /etc/profile
cat /etc/paths
cat ~/.bash_profile
#vi ~/.bash_profile
我配置到:/etc/.bash_profile
sudo vim /etc/.bash_profile
export PATH=/usr/local/Cellar/mongodb/4.0.3_1/bin:${PATH}
export MONGO_PATH=/usr/local/Cellar/mongodb/4.0.3_1
export PATH=$PATH:$MONGO_PATH/bin
source /etc/.bash_profile?
echo $PATH
mongod
cd /usr/local/Cellar/mongodb/4.0.3_1
?mkdir data logs
配置文件:
sudo vim /usr/local/etc/mongod.conf
#數(shù)據(jù)目錄
dbpath=/usr/local/Cellar/mongodb/4.0.3_1/data
#日志路徑
logpath=/usr/local/Cellar/mongodb/4.0.3_1/logs/mongo.log
#日志采用追加模式,日志會(huì)追加到現(xiàn)有的日志文件
logappend=true
#啟用日志文件,默認(rèn)啟用
journal=true
#過(guò)濾無(wú)效日志
quiet=true
#是否后臺(tái)啟動(dòng)
fork=true
#默認(rèn)端口號(hào)
port=27017
#本機(jī)無(wú)法連接遠(yuǎn)程機(jī)器添加
bind_ip=0.0.0.0
啟動(dòng):
mongod -f /usr/local/etc/mongod.conf
查看日志:
tail -f /usr/local/Cellar/mongodb/4.0.3_1/logs/mongo.log
> use blog
switched to db blog
> db.createCollection("users")
2019-02-07T11:24:52.551+0800 I NETWORK? [js]trying reconnect to 127.0.0.1:27017 failed
2019-02-07T11:24:52.553+0800 I NETWORK? [js]reconnect 127.0.0.1:27017 ok
{ "ok" : 1 }
> db.users.insert({user_name:"admin",user_password:"123456"})
WriteResult({ "nInserted" : 1 })
>
ps -ef|grep mongo
kill進(jìn)程號(hào)
結(jié)束?。?!