mac install mongodb

mac install mongodb

一、准备环境

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通过brew命令下载的文件都存在/usr/local/Cellar/文件夹下

同时也会在/usr/loacl/etc下生成一个mongod.conf配置文件

配置:

Mac使用brew方式安装软件默认存放在/usr/local/Cellar目录下,同时也会在/usr/loacl/etc下生成配置文件:

Mac配置环境变量:

cd ~

echo $PATH

一般环境变量在以下文件:

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

#数据目录

dbpath=/usr/local/Cellar/mongodb/4.0.3_1/data

#日志路径

logpath=/usr/local/Cellar/mongodb/4.0.3_1/logs/mongo.log

#日志采用追加模式,日志会追加到现有的日志文件

logappend=true

#启用日志文件,默认启用

journal=true

#过滤无效日志

quiet=true

#是否后台启动

fork=true

#默认端口号

port=27017

#本机无法连接远程机器添加

bind_ip=0.0.0.0

启动:

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进程号

结束!!!

你可能感兴趣的:(mac install mongodb)