Download and install Mongodb

1. Go to /usr/local/src

cd /usr/local/src
Copy the code

2. Wget download

Wget HTTP: / / https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.6.0.tgzCopy the code

3. Tar decompress

Tar ZXVF mongo - Linux - x86_64 - server. The TGZCopy the code

4. Move the decompressed files to the installation directory

Mv mongo - Linux - x86_64 - server/usr /local/mongodb
Copy the code

2. Mongodb startup and configuration

1. Create a folder for storing data and log files and modify its permissions to add read and write permissions

cd /usr/local/mongodb
sudo mkdir -p data/db

sudo chmod -R 777 data/db

sudo mkdir logs

cd logs

touch mongodb.log
Copy the code

2. Start and configure mongodb

cd /usr/local/mongodb/bin Go to the bin directory
sudo vi mongodb.conf Add the mongodb.conf configuration file
Copy the code

Insert the following:

dbpath = /usr/local/mongodb/data/db # Directory for storing data files
logpath = /usr/local/mongodb/logs/mongodb.log # Directory for storing log files
port = 27017 # port
fork = true # daemon enabled, that is, run in the background
nohttpinterface = true
Copy the code

3. Start the Mongod database service as a configuration file

cd /usr/local/mongodb/bin
./mongod -f mongodb.conf
Copy the code

4. Connect to the database

./mongo
Copy the code

Problems and solutions

ERROR: Child process failed, exited with ERROR number 1

Solution: This error is caused by the dbpath file permissions,data and logs directory permissions 777 can be. If a message is displayed indicating that the folder behind the file does not exist when you run the permission assignment command, chmod -r may be changed to uppercase. In another case, error message “CHmod: invalid mode: ‘-r'” is displayed after the command is executed. This is because the “-” in front of the chmod parameter R is incorrect. The solution is to modify the “-” in front of the R.