Install MongoDB on CentOS7
Install MongoDB on CentOS7
1. Connect to the CentOS7 server through SecureCRT;
2. Go to the/usr/local/directory:
Cd/usr/local
3. Create the tools directory in the current directory:
Mkdir-p tools
4. Go to the tools directory:
Cd tools
5 download the mongodb-linux-x86_64-rhel70-3.2.4.tgz file that matches the CentOS system:
Wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.4.tgz
6 unzip the mongodb-linux-x86_64-rhel70-3.2.4.tgz File:
Tar-zxvf mongodb-linux-x86_64-rhel70-3.2.4.tgz
Decompress the package to obtain the mongodb-linux-x86_64-rhel70-3.2.4 folder and its files;
7 rename the mongodb-linux-x86_64-rhel70-3.2.4 file to mongodb3.2.4:
Music mongodb-linux-x86_64-rhel70-3.2.4 mongodb3.2.4
8. Return to the upper-level directory and create the mongodb directory:
Cd ../
Mkdir-p mongodb
9. Move the mongodb3.2.4 file from the/usr/local/tools directory to the/usr/local/mongodb directory:
Mv tools/mongodb3.2.4/mongodb/
10. Go to the/usr/local/mongodb/mongodb3.2.4 directory:
Cd mongodb/mongodb3.2.4
11 create a log storage directory in the/usr/local/mongodb/mongodb3.2.4/bin/directory:
Mkdir-p data/test/logs
12 create a directory for storing data files in the/usr/local/mongodb/mongodb3.2.4/bin/directory:
Mkdir-p data/test/db
13. Go to the bin directory:
Cd bin/
14. Create the configuration file mongodb. conf:
Vi mongodb. conf
Write the following content in mongodb. conf:
# Idae-MongoDB config start-2016-05-02
# Set the directory for storing data files
Dbpath =/usr/local/mongodb/mongodb3.2.4/bin/data/test/db
# Set the log file storage directory and Log File Name
Logpath =/usr/local/mongodb/mongodb3.2.4/bin/data/test/logs/mongodb. log
# Set the port number (the default port number is 27017)
Port = 27017
# Set to run in daemon mode, that is, running in the background
Fork = true
# Nohttpinterface = true
Nohttpinterface = true
# Idae-MongoDB config end-2016-05-02
Save and quit by ": wq" in English;
Parameter description:
-- Dbpath database path (data file)
-- Logpath: Log File Path
-- Master is specified as the master machine.
-- Slave is specified as the slave machine
-- Source: Specifies the IP address of the host.
-- PologSize: the size of the specified log file cannot exceed 64 MB. because resync is very large and time-consuming, it is best to set a large enough oplogSize to avoid resync (the default oplog size is 5% of the idle disk size ).
-- Add at the end of the logappend log file, that is, use the append method to write logs.
-- Journal enable log
-- Port enables the port number
-- Fork runs in the background
-- Only specifies which database to copy
-- Slavedelay indicates the interval between slave replication detection.
-- Does auth need to verify the permission to log on (user name and password)
-- Syncdelay: the time (in seconds) when data is written to the hard disk. If the value is 0, data is directly written without waiting.
-- Notablescan does not allow table scanning.
-- MaxConns maximum number of concurrent connections, 2000 by default
-- Pidfilepath specifies the process file. If it is not specified, no process file is generated.
-- Bind_ip: bind an IP address. Only bound IP addresses can access the service.
15 start the mongodb service:
15.1 start with a custom mongodb configuration file:
./Mongod -- config mongodb. conf
15.2 start mongodb in Repair Mode:
./Mongod -- repair-f mongodb. conf
15.3 start with parameters:
. /Mongod/usr/local/mongodb/mongodb3.2.4/bin/mongod -- dbpath =/usr/local/mongodb/mongodb3.2.4/bin/data/test/db -- logpath =/usr/local /mongodb/mongodb3.2.4/bin/data/test/logs/mongodb. log -- fork
If the following error is reported:
ERROR: child process failed, exited with error number 1
It is likely that the path configured in mongodb. conf is inconsistent;
If the following error is reported:
ERROR: child process failed, exited with error number 100
It is likely that the file is not properly closed, so you can delete the mongod. lock file.
15. view the mongodb process:
Ps aux | grep mongodb
16. view the mongodb Service Running log:
Tail-200f/usr/local/mongodb/mongodb3.2.4/bin/data/test/logs/mongodb. log
17. Check whether the port has been started:
Netstat-lanp | grep 27017
18. Kill the mongodb process and shut down the mongodb service:
Kill-15 PID
You can view the PID in Step 16.
19 if the following occurs:
Warning: Failed to connect to 127.0.0.1: 27017, reason: errno: 111 Connection refused
You can use either of the following methods:
18.1 if the database fails to connect to the database, the issue may be caused by the mongod. lock file in the data directory. You can use the following command to fix the problem:
./Bin/mongod -- repair
18.2 or directly Delete mongod. lock
Rm-f/usr/local/mongodb/data/db/mongod. lock
Then start the mongodb service:
./Mongod -- config mongodb. conf
If the above two parts still cannot be resolved, it is the path file. We can delete the/usr/local/mongodb/mongodb3.2.4/bin/data DIRECTORY And Its subdirectories and adopt the absolute path method:
. /Mongod/usr/local/mongodb/mongodb3.2.4/bin/mongod -- dbpath =/usr/local/mongodb/mongodb3.2.4/bin/data/test/db -- logpath =/usr/local /mongodb/mongodb3.2.4/bin/data/test/logs/mongodb. log -- fork
20 Add the mongodb service to the self-starting file:
Vi/etc/rc. local
Append the following command to the end of the file:
/Usr/local/mongodb/mongodb3.2.4/bin/mongod -- config mongodb. conf
Save and exit:
: Wq!
21 common client commands:
Db. version (); # view the mongodb version
Use test; # enter the specified data. Here is the test database.
22 In the/usr/local/mongodb/mongodb3.2.4/bin/directory, type the following command to open a mongodb client program, that is, open a mongodb shell client, this shell client is also a JavaScript editor that can be used to input any JavaScript script:
./Mongo
Connect to the test database by default
23 enter IP: 27017 in the browser, for example:
Http: // 101.201.212.129: 27017/
You can view MongoDB version information;
For more MongoDB tutorials, see the following:
CentOS compilation and installation of php extensions for MongoDB and mongoDB
CentOS 6 install MongoDB and server configuration using yum
Install MongoDB2.4.3 in Ubuntu 13.04
MongoDB beginners must read (both concepts and practices)
MongoDB Installation Guide for Ubunu 14.04
MongoDB authoritative Guide (The Definitive Guide) in English [PDF]
Nagios monitoring MongoDB sharded cluster service practice
Build MongoDB Service Based on CentOS 6.5 Operating System
MongoDB details: click here
MongoDB: click here
This article permanently updates the link address: