Summary of Mongodb parameter specification and common error handling

  • 2020-06-23 02:12:47
  • OfStack

This article is mainly about the Mongodb parameter description and common error handling related content, Shared for your reference and learning, the following is a detailed introduction:

1. Install MongoDB on CentOS7

1 Connect to CentOS7 server via SecureCRT;

2 Enter /usr/local/ directory:


cd /usr/local

3 Create the tools directory under the current directory:


mkdir -p tools

4 Enter the tools directory:


cd tools

5. Download es29EN-ES30en-x86_64-rhel70-3.2.4.tgz file matching CentOS system:


wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.4.tgz

6 unzip mongodb-ES39en-x86_64-rhel70-3.2.4.tgz file:


tar -zxvf mongodb-linux-x86_64-rhel70-3.2.4.tgz

After decompression, mongodb-ES48en-x86_64-rhel70-3.2.4 folder and its files;

7. Rename mongodb-ES54en-x86_64-rhel70-3.2.4 to mongodb3.2.4:


mv mongodb-linux-x86_64-rhel70-3.2.4 mongodb3.2.4

8 Returns to the previous level 1 directory and creates the mongodb directory:


cd ../
mkdir -p mongodb

9. Move the mongodb3.2.4 file from /usr/local/tools to /usr/local/mongodb:


mv tools/mongodb3.2.4/ mongodb/

10 to enter/usr local mongodb/mongodb3. 2.4 directory:


cd mongodb/mongodb3.2.4

11 in/usr local/mongodb/mongodb3. 2.4 / bin deposit/directory to create a log directory:


mkdir -p data/test/logs

12 in/usr/local/mongodb/mongodb3. 2.4 / bin/directory to create a directory where the data files:


mkdir -p tools
0

13 Enter the bin directory:


cd bin/

14. Create configuration file ES109en. conf:


vi mongodb.conf

In ES115en.conf, write the following:


mkdir -p tools
3

Press "wq" in English state to save and exit;

Parameter interpretation:

--dbpath database path (data file) --logpath log file path --master specifies the primary machine --slave is specified as slave --source specifies the IP address of the main machine pologSize specifies that the log file size does not exceed 64M. Since resync is very cumbersome and time consuming, it is best to avoid resync by setting an oplogSize large enough (the default oplog size is 5% of the free disk size). logappend - added at the end of the log file to write the log as an append --journal enables logging --port enables the port number --fork running in the background only specifies which database to copy only --slavedelay refers to the time interval from replication detection --auth Whether authentication permission login (username and password) is required --syncdelay data written to hard disk in seconds, 0 is written directly without waiting notablescan does not allow table scanning --maxConns maximum number of concurrent connections, default 2000 pidfilepath specifies the process file, or does not produce a process file if not specified --bind_ip binds IP. After binding, only the binding IP can access the service

15 Start mongodb Service:

15.1 Start as a custom mongodb profile:


mkdir -p tools
4

15.2 Start mongodb in repair mode:


mkdir -p tools
5

15.3 Start with parameter:


mkdir -p tools
6

If the following error is reported:


 ERROR: child process failed, exited with error number 1

It is likely that the path configured in ES176en. conf is not 1.

If the following error is reported:


 ERROR: child process failed, exited with error number 100

It is likely that there was no normal closure, so you can delete the ES185en.lock file

15 View the mongodb process:


mkdir -p tools
9

16 View the running log of mongodb service:


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 to close the mongodb service:


kill -15 PID

PID can be viewed in Step 16

19 If the following occurs


warning: Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused

It can be solved in the following two ways:

19.1 If the database cannot be connected as mentioned above, it may be the file problem of ES220en. lock in data directory, you can use the following command to fix it:


./bin/mongod --repair

19.2 Or 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 still not solve, is the path to the file, we can delete/usr/local mongodb/mongodb3. 2.4 / bin data directory and its subdirectories, together with the method of absolute path:


./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 bootstrap 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 of the client:


db.version(); #  To view  mongodb  The version of the 
use test; #  Go into the specified data, here is  test  The database 

22 in/usr local/mongodb/mongodb3. 2.4 / bin/directory, type the following command, open a mongodb client program, or open a mongodb shell client, this shell client is also a JavaScript editor, you can enter any JavaScript scripts:


./mongo

The default connection is to the test database

23 Enter IP:27017 in the browser, for example:

http://101.201.212.129:27017/

You can view the version information of MongoDB.

conclusion


Related articles: