1.下载安装包
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-amazon-3.6.0.tgz
2.解压缩
[root@localhost opt]# tar -zxvf mongodb-linux-x86_64-amazon-3.6.0.tgz
3.准备工作
[root@localhost opt]# cd /usr/local/
[root@localhost local]# mkdir mongodb
[root@localhost local]# cd mongodb
[root@localhost mongodb]# mkdir data
[root@localhost mongodb]# mkdir logs
[root@localhost mongodb]# mkdir etc
[root@localhost mongodb]# cd logs
[root@localhost logs]# touch mongo.log
[root@localhost logs]# vi /usr/local/mongodb/etc/mongo.conf
dbpath=/usr/local/mongodb/data
logpath=/usr/local/mongodb/logs/mongo.log
logappend=true
journal=true
quiet=true
port=27017
bind_ip=0.0.0.0
4.给mongodb新建一个软连接
[root@localhost logs]# ln -s /usr/local/mongodb/mongodb-linux-x86_64-3.6.0/bin/mongo /usr/local/bin/mongo
[root@localhost logs]# ln -s /usr/local/mongodb/mongodb-linux-x86_64-3.6.0/bin/mongd /usr/local/bin/mongod
5.移动解压包mongodb-linux-x86_64-amazon-3.6.0
到目录/usr/local/mongodb
[root@localhost opt]# pwd
/opt
[root@localhost mongodb-linux-x86_64-amazon-3.6.0]# mv mongodb-linux-x86_64-amazon-3.6.0 /usr/local/
6.切换目录
[root@localhost opt]# cd /usr/local/mongodb-linux-x86_64-amazon-3.6.0/
[root@localhost mongodb-linux-x86_64-amazon-3.6.0]# ls
bin GNU-AGPL-3.0 MPL-2 README THIRD-PARTY-NOTICES
7.启动mongodb
[root@localhost mongodb-linux-x86_64-amazon-3.6.0]# ./bin/mongod --config /usr/local/mongodb/etc/mongo.conf
about to fork child process, waiting until server is ready for connections.
forked process: 22915
child process started successfully, parent exiting
8.进入mongodb解压bin目录输入./mongo即可连接数据库
[root@localhost bin]# pwd
/usr/local/mongodb-linux-x86_64-amazon-3.6.0/bin
[root@localhost bin]# ./mongo
9.进入data目录查看数据库初始化文件
# 退出数据库
> exit
bye
# 切换目录
[root@localhost bin]# cd /usr/local/mongodb/data/
# 列出目录文件
[root@localhost data]# ls
10.查看log文件
[root@localhost data]# cd ..
[root@localhost mongodb]# cd logs/
[root@localhost logs]# ls
mongo.log
[root@localhost logs]# cat mongo.log
# 部分内容截图: