Install the package
Go back to the Xshell console and enter the download command
wget /linux/mongodb-linux-x86_64-rhel70-4.2.3.tgz
At this time, mongodb-linux-x86_64-rhel70-4.2.3.tgz will be downloaded in the current working directory.
Unzip the installation package
and enter the following command
tar -zxvf mongodb-linux-x86_64-rhel70-4.2.3.tgz
Cut the decompressed directory to a new directory mongodb
mv mongodb-linux-x86_64-rhel70-4.2.3 mongodb
Create a database directory
The data of MongoDB is stored in the db directory of the data directory, but this directory will not be automatically created during the installation process, so you need to manually create the data directory and create the db directory in the data directory. Let's create a new data/db directory under mongodb
Here I also put the data directory under mongodb/mongodb
cd mongodb
mkdir -p data/db
Create a log directory
or continue to create a subdirectory log in the mongodb directory, and subsequent mongodb log files will be stored in this directory
mkdir log
Create a configuration file directory
Still under mongodb, we need to create an etc subdirectory, and create mongodb.conf in the subdirectory. Important: The mongodb.conf file is very important. If its configuration is wrong, mongodb will fail to start
mkdir etc
After creating the etc configuration file directory, we enter ls to view the information in the mongodb directory
vim ./etc/mongodb.conf
Enter the following content in the newly created mongodb.conf
dbpath=/opt/mongodb/data/db #数据文件存放目录
logpath=/opt/mongodb/log/mongodb.log #日志文件
port=27017 #端口
fork=true #以守护程序的方式启用,即在后台运行
journal=false
bind_ip=*
Start Mongodb
The newly installed Mongodb does not have a user name and password at this time, directly cd the working directory to the bin directory under the mongodb directory
cd bin
pwd execute the following command in the /root/mongodb/bin working directory to start Mongodb
./mongod --config /opt/mongodb/etc/mongodb.conf
netstat -lanp | grep "27017"
ps -ef | grep mongodb*