installing MongoDB on the CentOS7 1 connect to CentOS7 server via SECURECRT; 2 Go to the/usr/local/directory: Cd/usr/local 3 Create the Tools directory under the current directory: Mkdir-p Tools 4 enter into 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 The mongodb-linux-x86_64-rhel70-3.2.4 folder and the files it belongs to are obtained after the decompression is completed; 7 Rename the mongodb-linux-x86_64-rhel70-3.2.4 file to mongodb3.2.4: MV mongodb-linux-x86_64-rhel70-3.2.4 mongodb3.2.4 8 go back to the top 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 enter into the/usr/local/mongodb/mongodb3.2.4 directory: CD mongodb/mongodb3.2.4 11 Create a directory in the/usr/local/mongodb/mongodb3.2.4/bin/directory that holds the log: Mkdir-p Data/test/logs 12 Create a directory in the/usr/local/mongodb/mongodb3.2.4/bin/directory that holds the data files: Mkdir-p data/test/db 13 Enter the Bin directory: CD bin/ 14 Creating the configuration file mongodb.conf: VI mongodb.conf
Write the following in mongodb.conf: # idae-mongodb Config start-2016-05-02 # Set up directory for data files DBPath =/usr/local/mongodb/mongodb3.2.4/bin/data/test/db # Set the directory where the log files are stored and their log file names 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 as daemon, i.e. run in background Fork = True # Nohttpinterface = True Nohttpinterface = True # idae-mongodb Config end-2016-05-02
Save and Exit by ": Wq" in the English state;
Parameter explanation: --dbpath database path (data file) --logpath log file path --master designated as the main machine --slave specified as Slave machine --source Specify the IP address of the host machine --POLOGSIZE specifies that the log file size does not exceed 64M. Because Resync is very large and time-consuming, it is best to avoid resync by setting a sufficiently large oplogsize (the default oplog size is 5% of the size of the free disk). --logappend at the end of the log file, that is, write the log using the Append method --journal Enable logging --port Enable port numbers --fork running in the background --ONLY specifies which database to replicate only --slavedelay refers to the time interval from which replication is detected --auth If you need to verify permissions login (username and password) --syncdelay data written to hard disk (seconds), 0 is not waiting, write directly --notablescan table Scan not allowed --maxconns Maximum number of concurrent connections, default 2000 --PIDFILEPATH Specifies the process file, does not specify that no process file is generated --BIND_IP bind IP, bind only IP Access service after binding 15 Start 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 in parametric style: ./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 possible that the path inconsistency problem is configured in mongodb.conf; If the following error is reported: Error:child process failed, exited with error number 100 It is likely that there is no normal shutdown, so you can delete the Mongod.lock file 15 Viewing the MongoDB process: PS aux |grep MongoDB 16 viewing the running logs for MongoDB services: Tail-200f/usr/local/mongodb/mongodb3.2.4/bin/data/test/logs/mongodb.log 17 Check if the port has been started: NETSTAT-LANP | grep 27017 18 to kill the MongoDB process, you can close the MongoDB service: Kill-15 PID PID can be found through step 16 19 If the following conditions occur warning:failed to connect to 127.0.0.1:27017, reason:errno:111 Connection refused There are two ways to solve this: 18.1 If the database appears to be unable to connect the reason, may be the data directory under the Mongod.lock file problem, can be repaired with the following command: ./bin/mongod--repair 18.2 or delete Mongod.lock directly Rm-f/usr/local/mongodb/data/db/mongod.lock Then start the MongoDB service: ./mongod--config mongodb.conf If the above two is still not resolved, it is the path file, we can delete the/usr/local/mongodb/mongodb3.2.4/bin/data directory and its subdirectories, and take the absolute path way: ./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-boot 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 commands for clients: Db.version (); # View the MongoDB version Use test; # into the specified data, here is the test database 22 in the/usr/local/mongodb/mongodb3.2.4/bin/directory, type the following command, open a MONGODB client program, open a MongoDB shell client, the shell client is also a Java Script Editor, you can enter any JavaScript scripts: ./mongo Connect to test database by default 23 Enter ip:27017 in the browser, such as: http://101.201.212.129:27017/ Can view the version information of MongoDB; |