1、下载MongoDB程序包(RHEL 7 Linux 64-bit x64)
[root@mongodb /]# wget -P/usr/local/src/ https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.1.tgz
2、解压程序包:
[root@mongodb /]# tar -xzvf mongodb-linux-x86_64-rhel70-4.0.1.tgz -C /usr/local/src/
[root@mongodb /]# mv /usr/local/src/mongodb-linux-x86_64-rhel70-4.0.1 /usr/local/mongodb
3、创建程序运行所需的目录:
[root@mongodb /]# mkdir /usr/local/mongodb/etc /usr/local/mongodb/data /usr/local/mongodb/log
4、创建MongoDB配置文件:
[root@mongodb /]# vim /usr/local/mongodb/etc/mongod.conf dbpath = /usr/local/mongodb/data/
logpath = /usr/local/mongodb/log/mongodb.log
pidfilepath = /usr/local/mongodb/log/mongodb.pid
bind_ip = 127.0.0.1
port = 27017
fork = true
5、启动MongoDB程序:
[root@mongodb /]# /usr/local/mongodb/bin/mongod -f /usr/local/mongodb/etc/mongod.conf
6、MongoDB添加到系统环境变量:
[root@mongodb /]# sed -i '$a export MONGODB_HOME=/usr/local/mongodb\nexport PATH=$MONGODB_HOME/bin:$PATH' \
/etc/profile
[root@mongodb /]# source /etc/profile
7、MongoDB客户端登录:
[root@mongodb /]# mongo
MongoDB shell version v4.0.1
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.1
[THE END]