当前位置:网站首页>Mongodb second talk - - mongodb High available Cluster Implementation
Mongodb second talk - - mongodb High available Cluster Implementation
2022-07-01 14:44:00 【Singe programmé avec des cheveux!】
Les principaux documents de cet articleMongoDBConstruction de Clusters
Préparation à l'environnement:liunx centos7,docker-compose,Miroirmongo:4.2.21.
Arbitrage d'un chef à l'autre,Sur une machine
Projets | Value |
---|---|
0.221:27017 | Noeud1 |
0.221:27018 | Noeud2 |
0.221:27019 | Noeud d'arbitrage |
1. docker-compose.yaml
version: '3.7'
services:
mongo01:
image: mongo:4.2.21
container_name: mongo01
ports:
- "27017:27017"
environment:
- TZ=Asia/Shanghai
volumes:
- ./rs1:/data/db
#--replSet newset Définir le nom de l'ensemble de répliques Peut être utilisé après le chemin?replicaSet=newset
command: mongod --dbpath /data/db --replSet newset --oplogSize 128
networks:
- my-net
mongo02:
image: mongo:4.2.21
container_name: mongo02
ports:
- "27018:27017"
environment:
- TZ=Asia/Shanghai
volumes:
- ./rs2:/data/db
command: mongod --dbpath /data/db --replSet newset --oplogSize 128
networks:
- my-net
myarbiter:
image: mongo:4.2.21
container_name: myarbiter
ports:
- "27019:27017"
environment:
- TZ=Asia/Shanghai
volumes:
- ./rs3:/data/db
command: mongod --dbpath /data/db --replSet newset --oplogSize 128
networks:
- my-net
mongo-console:
image: mongo-express
container_name: mongo-console
ports:
- "8081:8081"
environment:
#Console Le Cluster doit entrer en vigueur avant que la connexion puisse réussir Connexion seulementmaster Peut être retiré seul
- ME_CONFIG_MONGODB_SERVER=mongo01
# - ME_CONFIG_BASICAUTH_USERNAME=admin
# - ME_CONFIG_BASICAUTH_PASSWORD=admin
- TZ=Asia/Shanghai
networks:
- my-net
networks:
#Nouveaux réseaux Appel interne au nom de service
my-net:
external: true
2.Conteneur de démarrage
[[email protected] mongo-cluster]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7588aac35621 mongo:4.2.21 "docker-entrypoint.s…" 15 minutes ago Up 8 minutes 0.0.0.0:27017->27017/tcp mongo01
5adca1bbfa3d mongo:4.2.21 "docker-entrypoint.s…" 15 minutes ago Up 15 minutes 0.0.0.0:27019->27017/tcp myarbiter
5384dac6d37a mongo:4.2.21 "docker-entrypoint.s…" 15 minutes ago Up 15 minutes 0.0.0.0:27018->27017/tcp mongo02
5df1b5d9af4f mongo-express "tini -- /docker-ent…" 15 minutes ago Up 8 minutes 0.0.0.0:8081->8081/tcp mongo-console
3.Initialisation du cluster
# Dans n'importe quel conteneur Mise en œuvremongoLes ordres
[[email protected] mongo-cluster]# docker exec -it mongo02 mongo
MongoDB shell version v4.2.21
# Effectuer la configuration initiale du cluster , Si une connexion au programme est nécessaire , Besoin de remplir l'hôte IP
>rs.initiate({
_id:"newset",members:[{
_id:0,host:"192.168.0.221:27017"},{
_id:1,host:"192.168.0.221:27018"},{
_id:2,host:"192.168.0.221:27019",arbiterOnly:true}]})
{
"operationTime" : Timestamp(1656417751, 1),
"ok" : 0,
"errmsg" : "already initialized",
"code" : 23,
"codeName" : "AlreadyInitialized",
"$clusterTime" : {
"clusterTime" : Timestamp(1656417751, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId" : NumberLong(0)
}
}
}
newset:SECONDARY>
_id:CorrespondantreplSet Nom
host: Si une connexion au programme est nécessaire , Besoin de remplir l'hôte IP
arbiterOnly:true Indique que le noeud est un noeud quorum
4.Voir l'état du cluster
newset:SECONDARY> rs.status()
#TrouvermembersInformations sur les noeuds
"members" : [
{
"_id" : 0,
"name" : "192.168.0.221:27017",
"health" : 1,
"state" : 1,
#Clustermaster
"stateStr" : "PRIMARY",
"uptime" : 202,
"optime" : {
"ts" : Timestamp(1656417761, 6),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2022-06-28T12:02:41Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "could not find member to sync from",
"electionTime" : Timestamp(1656417761, 1),
"electionDate" : ISODate("2022-06-28T12:02:41Z"),
"configVersion" : 1,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 1,
"name" : "192.168.0.221:27018",
"health" : 1,
"state" : 2,
#Clusterslave
"stateStr" : "SECONDARY",
"uptime" : 10,
"optime" : {
"ts" : Timestamp(1656417751, 1),
"t" : NumberLong(-1)
},
"optimeDurable" : {
"ts" : Timestamp(1656417751, 1),
"t" : NumberLong(-1)
},
"optimeDate" : ISODate("2022-06-28T12:02:31Z"),
"optimeDurableDate" : ISODate("2022-06-28T12:02:31Z"),
"lastHeartbeat" : ISODate("2022-06-28T12:02:41.778Z"),
"lastHeartbeatRecv" : ISODate("2022-06-28T12:02:41.434Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"configVersion" : 1
},
{
"_id" : 2,
"name" : "192.168.0.221:27019",
"health" : 1,
"state" : 7,
# Arbitrage groupé
"stateStr" : "ARBITER",
"uptime" : 10,
"lastHeartbeat" : ISODate("2022-06-28T12:02:41.778Z"),
"lastHeartbeatRecv" : ISODate("2022-06-28T12:02:41.704Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"configVersion" : 1
}
],
5.SimulationmasterNoeud suspendu
ArrêtemasterNoeud,Entréeslave Afficher l'état dans le conteneur du noeud
"members" : [
{
"_id" : 0,
"name" : "192.168.0.221:27017",
"health" : 0,
"state" : 8,
"stateStr" : "(not reachable/healthy)",
"uptime" : 0,
"optime" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"optimeDurable" : {
"ts" : Timestamp(0, 0),
"t" : NumberLong(-1)
},
"optimeDate" : ISODate("1970-01-01T00:00:00Z"),
"optimeDurableDate" : ISODate("1970-01-01T00:00:00Z"),
"lastHeartbeat" : ISODate("2022-06-28T12:05:49.005Z"),
"lastHeartbeatRecv" : ISODate("2022-06-28T12:05:30.416Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "Error connecting to 192.168.0.221:27017 :: caused by :: Connection refused",
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"configVersion" : -1
},
{
"_id" : 1,
"name" : "192.168.0.221:27018",
"health" : 1,
"state" : 1,
#L'originalslave Le noeud a été changé en masterC'est
"stateStr" : "PRIMARY",
"uptime" : 390,
"optime" : {
"ts" : Timestamp(1656417940, 2),
"t" : NumberLong(3)
},
"optimeDate" : ISODate("2022-06-28T12:05:40Z"),
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "could not find member to sync from",
"electionTime" : Timestamp(1656417940, 1),
"electionDate" : ISODate("2022-06-28T12:05:40Z"),
"configVersion" : 1,
"self" : true,
"lastHeartbeatMessage" : ""
},
{
"_id" : 2,
"name" : "192.168.0.221:27019",
"health" : 1,
"state" : 7,
"stateStr" : "ARBITER",
"uptime" : 197,
"lastHeartbeat" : ISODate("2022-06-28T12:05:49.006Z"),
"lastHeartbeatRecv" : ISODate("2022-06-28T12:05:48.204Z"),
"pingMs" : NumberLong(0),
"lastHeartbeatMessage" : "",
"syncingTo" : "",
"syncSourceHost" : "",
"syncSourceId" : -1,
"infoMessage" : "",
"configVersion" : 1
}
],
Vous pouvez voir l'originalslaveLe noeud est devenuPRIMARYNoeud maître
6.mongo-expressConsole
- Points nécessitant une attention particulière pour la connexion
environment:
# Sans port Nom du conteneur de marche directe
- ME_CONFIG_MONGODB_SERVER=mongo01
- Cluster non initialisé ou Cluster masterModifié, La console signale l'erreur suivante
(node:6) UnhandledPromiseRejectionWarning: MongoError: not master and slaveOk=false
À déterminermaster Après le noeud, redémarrez la console
7.springbootConfiguration du cluster moyen
spring:
data:
mongodb:
# Connexion par mot de passe Le mot de passe du compte contient des caractères spéciaux pour URLEncoderCodage Nom de la Bibliothèque requis
#uri: mongodb://admin:[email protected]:27017/imgdb
#Approche groupée Jeu de répliquesreplicaSetAvec ou sans
uri: mongodb://192.168.0.221:27017,192.168.0.221:27018/imgdb?replicaSet=newset
# uri: mongodb://192.168.0.221:27017/imgdb
C'est tout ce qu'il y a dans ce chapitre.
Page précédente:MongoDBLe premier mot – DockerInstallationMongoDBEtSpringbootIntégrationMongoDB
Suivant:JVMLe premier mot – JVM Détails de démarrage et analyse de la zone de données d'exécution
Il y a une route pour la montagne du livre,Apprendre à naviguer sans limite
边栏推荐
- C learning notes (5) class and inheritance
- Pat 1121 damn single (25 points) set
- 2022-2-15 learning the imitation Niuke project - Section 3 post details
- After twists and turns, I finally found the method of SRC vulnerability mining [recommended collection]
- 建立自己的网站(14)
- Why did you win the first Taosi culture award of 20000 RMB if you are neither a top R & D expert nor a sales Daniel?
- 音乐播放器开发实例(可毕设)
- sqlilabs less13
- Research Report on the development trend and competitive strategy of the global display filter industry
- [leetcode 324] swing sorting II thinking + sorting
猜你喜欢
Word2vec yyds dry goods inventory
Microservice development steps (Nacos)
[Verilog quick start of Niuke series] ~ multi function data processor, calculate the difference between two numbers, use generate... For statement to simplify the code, and use sub modules to realize
2022-2-15 learning xiangniuke project - Section 1 filtering sensitive words
Blog recommendation | in depth study of message segmentation in pulsar
[15. Interval consolidation]
用对场景,事半功倍!TDengine 的窗口查询功能及使用场景全介绍
[14. Interval sum (discretization)]
241. Design priorities for operational expressions
[零基础学IoT Pwn] 复现Netgear WNAP320 RCE
随机推荐
写在Doris毕业后的第一天
用对场景,事半功倍!TDengine 的窗口查询功能及使用场景全介绍
Music player development example (can be set up)
tensorflow2-savedmodel convert to pb(frozen_graph)
Basis of target detection (NMS)
Problem note - Oracle 11g uninstall
tensorflow2-savedmodel convert to tflite
Use of Oracle database objects
Pat 1121 damn single (25 points) set
Research Report on the development trend and competitive strategy of the global electromagnetic flowmeter industry
tensorflow2-savedmodel convert to pb(frozen_graph)
Rearrangement of overloaded operators
Today, with the popularity of micro services, how does service mesh exist?
Is the futures company found on Baidu safe? How do futures companies determine the regularity
Summary of leetcode's dynamic programming 5
643. Maximum average number of subarrays I
Research Report on development trend and competitive strategy of global consumer glassware industry
Research Report on the development trend and competitive strategy of the global high temperature label industry
Advanced C language
WebSocket(简单体验版)