Mongodb version 4.2 configuration de jeu de réplicas

ensemble de réplication commune

Architecture commune de l'environnement en ligne pour l'ensemble de réplique, peut être comprise comme un maître multi-esclave.

En bas: 1 à partir du maître 2

Mongodb version 4.2 configuration de jeu de réplicas

En bas: un arbitrage maître d'un

Mongodb version 4.2 configuration de jeu de réplicas

Informations sur le serveur:

Trois machines configurées comme 2 mémoire de stockage 16G nucléaire disque 100G

"hôte": "10.1.1.159:27020"
"hôte": "10.1.1.77:27020"
"hôte": « 10.1.1.178:27020

1, nous avons une des configurations de machines:

[root @ 10-1-1-159 ~] # wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.2.1.tgz
[root @ 10-1-1-159 ~ ] # tar -zxvf mongodb-linux-x86_64-rhel70-4.2.1.tgz C / data /
[root @ 10-1-1-159 ~] # mkdir / data / MongoDB / {données, journaux, pid, conf } -p
配置文件:

[root@10-1-1-159 ~]# cat /data/mongodb/conf/mongodb.conf
systemLog:
  destination: file
  logAppend: true
  path: /data/mongodb/logs/mongod.log

storage:
  dbPath: /data/mongodb/data
  journal:
    enabled: true
  directoryPerDB: true
  wiredTiger:
     engineConfig:
        cacheSizeGB: 8                    #如果一台机器启动一个实例这个可以注释选择默认,如果一台机器启动多个实例,需要设置内存大小,避免互相抢占内存
        directoryForIndexes: true

processManagement:
  fork: true
  pidFilePath: /data/mongodb/pid/mongod.pid

net:
  port: 27020
  bindIp: 10.1.1.159,localhost      #修改为本机IP地址
  maxIncomingConnections: 5000

#security:
  #keyFile: /data/mongodb/conf/keyfile
  #authorization: enabled
replication:
#   oplogSizeMB: 1024
   replSetName: rs02

2, configuration négative répliquées sur d'autres machines:

[root @ 10-1-1-159 ~] # scp -r / data / [email protected]: / data /
[root @ 10-1-1-159 ~] # scp -r / données /
[email protected] .1.178: / data /

La structure du répertoire:

[root@10-1-1-178 data]# tree mongodb
mongodb
├── conf
│   └── mongodb.conf
├── data
├── logs
└── pid

3, trois machines ont été exécutés:

groupadd mongod
useradd -g mongod mongod
yum install -y libcurl openssl glibc
cd / données
ln -s mongodb-linux-x86_64-rhel70-4.2.1 mongodb-4,2
chown -R mongod.mongod / données
sudo -u mongod / data / mongodb4 .2.1 / bin / mongod -f /data/mongodb/conf/mongodb.conf

Configurer ensemble de réplication:
nom réplique # RS02 de profil défini et cohérent replSetName

config = {_id: "RS02", les membres: [
                     {_id: 0, hôte: "10.1.1.159:27010", la priorité: 90}, 
                     {_id: 1, hôte: "10.1.1.77:27010", la priorité: 90 }, 
                    {_id: 2, hôte: "10.1.1.178:27010", arbiterOnly: true}
    ]
}

# Initialiser

rs.initiate (config); 

4, dans lequel une machine d'effectuer:

[root@10-1-1-159 ~]# /data/mongodb3.6.9/bin/mongo  10.1.1.159:27020
> use admin
switched to db admin
> config = { _id:"rs02", members:[
...                      {_id:0,host:"10.1.1.159:27020",priority:90},
...                      {_id:1,host:"10.1.1.77:27020",priority:90},
...                      {_id:2,host:"10.1.1.178:27020",arbiterOnly:true}
...               ]
... }
{
    "_id" : "rs02",
    "members" : [
        {
            "_id" : 0,
            "host" : "10.1.1.159:27020",
            "priority" : 90
        },
        {
            "_id" : 1,
            "host" : "10.1.1.77:27020",
            "priority" : 90
        },
        {
            "_id" : 2,
            "host" : "10.1.1.178:27020",
            "arbiterOnly" : true
        }
    ]
}
>
> rs.initiate(config);        初始化副本集########eeeerrrr  
{
    "ok" : 1,
    "operationTime" : Timestamp(1583907929, 1),
    "$clusterTime" : {
        "clusterTime" : Timestamp(1583907929, 1),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    }
}

5. Vérifier l'état du noeud

rs02:PRIMARY> rs.status()
{
    "set" : "rs02",
    "date" : ISODate("2020-03-13T07:11:09.427Z"),
    "myState" : 1,
    "term" : NumberLong(1),
    "syncingTo" : "",
    "syncSourceHost" : "",
    "syncSourceId" : -1,
    "heartbeatIntervalMillis" : NumberLong(2000),
    "optimes" : {
        "lastCommittedOpTime" : {
            "ts" : Timestamp(1584083465, 1),
            "t" : NumberLong(1)
        },
        "readConcernMajorityOpTime" : {
            "ts" : Timestamp(1584083465, 1),
            "t" : NumberLong(1)
        },
        "appliedOpTime" : {
            "ts" : Timestamp(1584083465, 1),
            "t" : NumberLong(1)
        },
        "durableOpTime" : {
            "ts" : Timestamp(1584083465, 1),
            "t" : NumberLong(1)
        }
    },
    "members" : [
        {
            "_id" : 0,
            "name" : "10.1.1.159:27020",
            "health" : 1,
            "state" : 1,
            "stateStr" : "PRIMARY",    #主节点
            "uptime" : 185477,
            "optime" : {
                "ts" : Timestamp(1584083465, 1),
                "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2020-03-13T07:11:05Z"),
            "syncingTo" : "",
            "syncSourceHost" : "",
            "syncSourceId" : -1,
            "infoMessage" : "",
            "electionTime" : Timestamp(1583907939, 1),
            "electionDate" : ISODate("2020-03-11T06:25:39Z"),
            "configVersion" : 1,
            "self" : true,
            "lastHeartbeatMessage" : ""
        },
        {
            "_id" : 1,
            "name" : "10.1.1.77:27020",
            "health" : 1,
            "state" : 2,
            "stateStr" : "SECONDARY",       #从节点
            "uptime" : 175540,
            "optime" : {
                "ts" : Timestamp(1584083465, 1),
                "t" : NumberLong(1)
            },
            "optimeDurable" : {
                "ts" : Timestamp(1584083465, 1),
                "t" : NumberLong(1)
            },
            "optimeDate" : ISODate("2020-03-13T07:11:05Z"),
            "optimeDurableDate" : ISODate("2020-03-13T07:11:05Z"),
            "lastHeartbeat" : ISODate("2020-03-13T07:11:08.712Z"),
            "lastHeartbeatRecv" : ISODate("2020-03-13T07:11:08.711Z"),
            "pingMs" : NumberLong(0),
            "lastHeartbeatMessage" : "",
            "syncingTo" : "10.1.1.159:27020",
            "syncSourceHost" : "10.1.1.159:27020",
            "syncSourceId" : 0,
            "infoMessage" : "",
            "configVersion" : 1
        },
        {
            "_id" : 2,
            "name" : "10.1.1.178:27020",
            "health" : 1,
            "state" : 7,
            "stateStr" : "ARBITER",     #仲裁节点
            "uptime" : 175540,
            "lastHeartbeat" : ISODate("2020-03-13T07:11:08.712Z"),
            "lastHeartbeatRecv" : ISODate("2020-03-13T07:11:08.711Z"),
            "pingMs" : NumberLong(0),
            "lastHeartbeatMessage" : "",
            "syncingTo" : "",
            "syncSourceHost" : "",
            "syncSourceId" : -1,
            "infoMessage" : "",
            "configVersion" : 1
        }
    ],
    "ok" : 1,
    "operationTime" : Timestamp(1584083465, 1),
    "$clusterTime" : {
        "clusterTime" : Timestamp(1584083465, 1),
        "signature" : {
            "hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
            "keyId" : NumberLong(0)
        }
    }
}
rs02:PRIMARY>

7, maintenant l'état de l'ensemble de réplique:

10.1.1.178:27020 noeud d'arbitrage ARBITER
10.1.1.77:27020 secondaire à partir noeud
10.1.1.159:27020 noeud maître PRIMAIRE

Nous insérons des données pour vérifier, puis éteindre le nœud maître,

nœud d'arbitrage journal ,
nous pouvons voir que quand après le nœud 10.1.1.159 vers le bas, réélu: Membre 10.1.1.77:27010 est maintenant en état primaire

2020-03-18T14:34:53.636+0800 I NETWORK  [conn9] end connection 10.1.1.159:49160 (1 connection now open)
2020-03-18T14:34:54.465+0800 I CONNPOOL [Replication] dropping unhealthy pooled connection to 10.1.1.159:27010
2020-03-18T14:34:54.465+0800 I CONNPOOL [Replication] after drop, pool was empty, going to spawn some connections
2020-03-18T14:34:54.465+0800 I ASIO     [Replication] Connecting to 10.1.1.159:27010
......
2020-03-18T14:35:02.473+0800 I ASIO     [Replication] Failed to connect to 10.1.1.159:27010 - HostUnreachable: Error connecting to 10.1.1.159:27010 :: caused by :: Connection refused
2020-03-18T14:35:02.473+0800 I CONNPOOL [Replication] Dropping all pooled connections to 10.1.1.159:27010 due to HostUnreachable: Error connecting to 10.1.1.159:27010 :: caused by :: Connection refused
2020-03-18T14:35:02.473+0800 I REPL_HB  [replexec-8] Error in heartbeat (requestId: 662) to 10.1.1.159:27010, response status: HostUnreachable: Error connecting to 10.1.1.159:27010 :: caused by :: Connection refused
2020-03-18T14:35:04.463+0800 I REPL     [replexec-5] Member 10.1.1.77:27010 is now in state PRIMARY
2020-03-18T14:35:04.473+0800 I ASIO     [Replication] Connecting to 10.1.1.159:27010
2020-03-18T14:35:04.473+0800 I ASIO     [Replication] Failed to connect to 10.1.1.159:27010 - HostUnreachable: Error connecting to 10.1.1.159:27010 :: caused by :: Connection refused
2020-03-18T14:35:04.473+0800 I CONNPOOL [Replication] Dropping all pooled connections to 10.1.1.159:27010 due to HostUnreachable: Error connecting to 10.1.1.159:27010 :: caused by :: Connection refused

Architecture deviendra une figure ci-dessous:

Mongodb version 4.2 configuration de jeu de réplicas

À l' heure actuelle pour construire une mis en copie complète, également testé Lorsque (au moins trois noeuds) problème avec un nœud, et ne sera pas affecter la lecture du service et de l' écriture correctement.
Le chapitre suivant , nous commençons à ajouter des utilisateurs:

Je suppose que tu aimes

Origine blog.51cto.com/jiachen/2485887
conseillé
Classement