Replica set installation

1. Decompress the downloaded package:

$tar – ZXVF mongo – Linux – x86_64-3.4.17. TGZ

Links to download address: pan.baidu.com/s/1mmcyWpri… Extraction code: ONFO

2. Change the folder name

$mongo mv – Linux – x86_64-3.4.17. TGZ mongodb27107

3. Create a database directory, configuration file directory, and log directory

$ mkdir -p mongodb27107/data/db

$ mkdir -p mongodb27107/config

4. Create the mongo.conf configuration file

$ touch mongo.conf

Add the following configuration

Dbpath = / home/mvtech/mongodb27017 / data/db / # data storage directory

The logpath = / home/mvtech/mongodb27017 / data/mongo. # log log file directory

Pidfilepath = / home/mvtech/mongodb27017 / data/mongo. Pid # pid port file

Port = 27017 # mongo port

Logappend =true # Write to log file in append mode, default false, overwrite

Fork =true # background run

Journal =true # With logging enabled, MongoDB data operations will be written to the journal folder

OplogSize =2048 #

Smallfiles =true # Use smaller default files

ReplSet = HeatDB # Name of a replica set. The name of the replica set must be the same

Mongodb27107 — mongodb27107 — mongodb27107 — mongodb27107 — Mongodb27107 — Mongodb27107 — Mongodb27107 — Mongodb27107 — Mongodb27107

6. Modify the mongo.conf file in all replication instances to the corresponding path.

7. Start the Mongo instance and go to the bin directory

$mongod – f/home/mvtech/mongodb27017 / config/mongo. Conf

Start other Mongo instances and modify the path by referring to the command above

8. Use MONG to connect to database for service.

$./mongo accesses default port 27017

$./mongo — port 27018 Access non-default ports

9. Initialize the replica set configuration

Replica set member configuration

cfg = {

MongoSet = ‘mongoSet’; mongoSet = ‘mongoSet’

members: [{

_id: 0,

Host: ‘172.18.247.114:27018 ‘, # Replica set member IP: port

Priority: 1 # Replica set member priority

},

{

_id: 1,

Host: ‘172.18.247.113:27017’,

priority: 1

},

{

_id: 2,

Host: ‘172.18.247.113:27018’,

priority: 1

}]

};

Initialize the configuration file

rs.initiate(cfg);

10. Query the replica set status

$ rs.status()

11. Perform the secondary node

$./mongo -host IP – port Specifies the port number

$./mongo -host 172.18.247.114 -port 27018

12. Run the following command on the secondary node: “errmsg” : “not master and slaveOk=false

$ rs.slaveOk();

13. Common operations on replica sets

www.cnblogs.com/ivictor/p/6…