首先我们需要下载对应版本的mongodb
下载地址是:https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-4.0.4.tgz
首先约束下安装目录,我安装在/usr/local/mongo下
tar -zxvf mongodb-osx-ssl-x86_64-4.0.4.tgz sudo mv mongodb-osx-ssl-x86_64-4.0.4 /usr/local/mongo sudo chown -R 777 /usr/local/mongo
添加数据存放路径
sudo mkdir -p /usr/local/mongo/data
创建mongo日志目录
sudo mkdir -p /usr/local/mongo/logs sudo touch /usr/local/mongo/logs/mongod.log
添加mongo配置文件目录
sudo mkdir -p /usr/local/mongo/conf sudo vi /usr/local/mongo/conf/mongod.conf #添加以下内容 dbpath=/usr/local/mongo/data logpath=/usr/local/mongo/logs/mongod.log logappend =true port=27017 fork=true #auth=true
启动方式
cd /usr/local/mongo/bin sudo ./mongod --bind_ip 127.0.0.1 -f /usr/local/mongodb/conf/mongodb.conf