mongo cluster (copies) set up the process of recording

Mongo recently set up a cluster, recalls summary for recording.
The whole process mainly refer to the following two articles, but the process is not smooth, some issues need to record.
https://www.cnblogs.com/dba-devops/p/7130710.html
https://blog.csdn.net/thinktik/article/details/82118190

Select a server, the following steps, then the final copy scp command to other servers, easily and quickly.
I chose the installation binary packages, first tgz package uploaded to linux, then unpack.
Then create a folder data, logs, etc, are used to store data mongo, logs, configuration files.
New file logs directory touch mongo.log
new file under the etc directory mongo.conf

Editor vi mongo.conf
fill in the configuration:

= dbpath / usr / MongoDB / the Data 
logpath = / usr / MongoDB / logs / mongo.log 
logappend = to true 
. TECHNOLOGY INFORMATION = to true 
quiet = to true 
Port = 27017 
bind_ip = 0.0 . 0.0   # 0.5 instead 0.0 Access to listen to all ip .0 
fork = to true 
# name replica set 
replset = TCL

Since the first time configuration, I do not know what should be configured wrote, referring to a text of many articles, and ultimately my configuration above. Other articles in some configuration leading to mongo not start, an error that is specific configuration of a keyword is not recognized and so on. The specific environment specific treatment of it. Then we should relate to the specific configuration is just learning the mongo. The above-described basic data path, the log path, append mode, ports, whether running in the background and the like.

For convenience, mongo environment variables to configure it,

#java
export JAVA_HOME=/usr/java/jdk1.8.0_181-cloudera
export CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib
export PATH=$PATH:$JAVA_HOME/bin
export PATH=$PATH:/usr/mongodb/detailFileMongoDBv4.0/:/usr/mongodb/detailFileMongoDBv4.0/bin

Encounter a problem, suddenly found various linux command failure, suggesting command not found.
The reason is the environment variable writing problems, leading to system environment variables fail. Specific solutions Many articles have described, it is easy to search the content. No longer.

Mongo use the scp command to copy the files to another server and modify environment variables.
Start mongo server. To the bin directory under the mongo file directory;
./mongod -f /usr/mongodb/etc/mongo.conf
-f specify the configuration file you want to use (that is, above mongo.conf own configuration), start mongo.

After a successful start can use ps to view the status
[root @ master01 bin] # ps -ef | grep MongoDB
root 28412 7588 0 09:54 PTS / 0 = Auto MongoDB --color 00:00:00 grep
root 17932 1 0 Aug30 00? : 18: 02 ./mongod -f /usr/mongodb/etc/mongo.conf


Next, I follow the steps in the article, ready to write data to the mongo in:

Command: mongo mongo into the server
1, creating replica set configuration
config = {
    "the _id": "TCL",
    "Members": [
      {
        "the _id": 0,
        "Host": "xxx.xx.xx.xx: 27017 "
      },
      {
        " the _id ":. 1,
        " Host ":" xxx.xx.xx.xx: 27017 "
      },
      {
        " the _id ": 2,
        " Host ":" xxx.xx.xx.xx: 27017 "
      }
    ]  
  }

2, initialize the replica set
> rs.initiate (config)
At this point, appear "ok": 1,, success, failure, then there will errormsg tips. Successfully represents the replica set is set to succeed.
3, the current mongo from this machine, we can manually set it to host
TCL: the SECONDARY> rs.isMaster ()
4, see the replica set state
tcl: PRIMARY> rs.status ()

5, the verification synchronization
# build a library and the master library and inserted into a data table
TCL: a PRIMARY> use the testdb;
Switched DB to the testdb
TCL: a PRIMARY> db.synctable.insert ({name: "Verify"});
however it I side execution failed. Tip anomaly can not create user databases on a --configsvr instance "
specific reasons not understood, [there is to know little friends welcome correction] plus mongo.conf time has been modified, so decided to terminate the mongo process restart.

The next egg pain thing happened, I want to close mongo service, but because of mongo do not understand, do not pay sufficient attention to the old way directly kill -9. This time bad, mongo never get up. A start on the error:
could not Connect to Server 127.0.0.1:27017 src / mongo / shell / mongo.js: 91
and then search approach mongo abnormal closed realize that this process only to find, mongo can not kill -9 importance.

Most of the online approach is mongod.lock delete files in the data, as well as re-specified data directory ways to start:
./mongod --dbpath = / usr / local / MongoDB / the Data / db /,
in this way can really start but the current window is closed, as usual the old way, which is certainly not.
This article covers the above approach: as a detailed reference: https://blog.csdn.net/wangli61289/article/details/44459467

First, mongod.lock file in the data, must be removed in the first. Then, start the repair, the specified profile way to start the show:
./mongod -f /usr/mongodb/etc/mongo.conf --repair

If you do not specify the configuration file repair start, there will be an exception as follows: mongo default data directory in / mongo / data, so can not find this directory, an error.
'exception in initAndListen: NonExistentPath: Data directory / data / db not found, terminating.'

There, mongo off, be sure to switch to the admin database, and then shut down. https://www.cnblogs.com/gaopeng527/p/5117188.html
> use ADMIN;
Switched to DB ADMIN
> db.shutdownServer ();
Wed-Nov 14 06:07:33 DBClientCursor :: Call the init () failed
Wed-Nov Query failed 06:07:33 14: ADMIN $ {cmd the shutdown: 1.0}. to: 127.0.0.1:27017
Server Down ... Should BE
Wed-Nov 14 06:07:33 Trying to Reconnect 127.0.0.1:27017
Wed-Nov 14 06:07:33 reconnect 127.0.0.1:27017 failed couldnt connect to server 127.0.0.1:27017.

 

Continue to test data synchronization, data is written in the main library: [excerpt from https://blog.csdn.net/thinktik/article/details/82118190]

# Build a library and the master library and inserted into a data table
TCL: a PRIMARY> use the testdb;
Switched DB to the testdb
TCL: a PRIMARY> db.synctable.insert ({name: "Verify"});
WriteResult ({ "nInserted":. 1 })


# Enter from the library

# Error, normal. Because SECONDARY is not allowed to read and write may be performed rs.slaveOk (); releasing
TCL: SECONDARY>
TCL: SECONDARY> Show DBS;
2018-08-27T14: 13 is: 0800 + 17.963 E the QUERY [JS] Error: listDatabases failed: {
  "operationTime": Timestamp (1,535,350,391,. 1),
  "OK": 0,
  "ErrMsg": "Not Master and slaveOk = to false",
  "code": 13435,
  "CodeName": "NotMasterNoSlaveOk",
  "$ clusterTime": {
    "clusterTime": Timestamp (1,535,350,391,. 1),
    "Signature": {
      "the hash": binData (0, "AAAAAAAAAAAAAAAAAAAAAAAAAAA ="),
      "keyId": NumberLong (0)
    }
  }
}:


shellHelper.show@src/mongo/shell/utils.js:876:19
shellHelper@src/mongo/shell/utils.js:766:15
@(shellhelp2):1:1

 


# 解除限制
tcl:SECONDARY> rs.slaveOk();
tcl:SECONDARY> show dbs;
admin 0.000GB
config 0.000GB
local 0.000GB
testdb 0.000GB
tcl:SECONDARY> use testdb;
switched to db testdb
tcl:SECONDARY> db.synctable.find();
{ "_id" : ObjectId("5b8395ae80365b296a69ddc0"), "name" : "验证" }

 

Guess you like

Origin www.cnblogs.com/dxxdsw/p/11445931.html