1、从mongoDB官网(https://www.mongodb.com/download-center#community)下载最新安装包,解压到 /Users/echo
2、在mongodb目录下新建三个目录:data/db存放数据文件,etc存放配置文件mongod.conf,log存放日志mongd.log
echo@NinomaedeMacBook-Pro:~/mongodb-4.0.6$ ls -ltr
total 224
-rw-r--r--@ 1 echo staff 16726 2 5 13:14 MPL-2
-rw-r--r--@ 1 echo staff 30608 2 5 13:14 LICENSE-Community.txt
-rw-r--r--@ 1 echo staff 57190 2 5 13:15 THIRD-PARTY-NOTICES
-rw-r--r--@ 1 echo staff 2601 2 5 13:15 README
drwxr-xr-x@ 15 echo staff 510 3 3 12:45 bin
drwxr-xr-x 3 echo staff 102 3 3 12:46 data
drwxr-xr-x 3 echo staff 102 3 3 12:48 log
drwxr-xr-x 3 echo staff 102 3 3 12:52 etc
mongod.conf 内容如下:
#mongodb config file
dbpath=/Users/echo/mongodb-4.0.6/data/db/
logpath=/Users/echo/mongodb-4.0.6/log/mongod.log
logappend = true
port = 27017
fork = true
auth = true
3、配置完成后把mongo加入环境变量后并生效
echo 'export PATH=/Users/echo/mongodb-4.0.6/bin:$PATH'>>~/.bash_profile
. ~/.bash_profile
4、启动服务:
mongod --config /Users/echo/mongodb-4.0.6/etc/mongod.conf
网友评论