-
下载mongodb源码,并解压:
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-4.0.11.tgz tar -zxvf mongodb-linux-x86_64-ubuntu1604-4.0.11.tgz
-
创建mongo专属目录,拷贝bin下文件到mongodb目录下bin中:
mkdir /usr/local/mongodb cd /usr/local/mongodb mkdir bin cp .../mongodb-linux-x86_64-ubuntu1604-4.0.11/bin/* ./bin/
-
创建数据库文件目录、日志目录、配置文件:
mkdir data touch mongodb.log touch mongodb.conf
-
配置文件内容:
dbpath=/usr/local/mongodb/data logpath=/usr/local/mongodb/mongodb.log logappend=true journal=true fork=true bind_ip = 127.0.0.1 port = 27017 noauth = true #auth = true
-
将mongo添加path:
#打开profile vi /etc/profile #输入下面内容: MONGO_DB="/usr/local/mongodb" PATH=$MONGO_DB/bin:$PATH: export PATH #加载配置 source /etc/profile
-
启动mongodb:
/usr/local/mongodb/bin/mongod --config /usr/local/mongodb/mongodb.conf
#启动后会看到: about to fork child process, waiting until server is ready for connections. forked process: 1361 child process started successfully, parent exiting