当前位置:网站首页>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
边栏推荐
- 643. Maximum average number of subarrays I
- Don't want to knock the code? Here comes the chance
- Reorganize the trivial knowledge points at the end of the term
- Use the npoi package of net core 6 C to read excel Pictures in xlsx cells and stored to the specified server
- C 语言进阶
- 【14. 区间和(离散化)】
- Word2vec yyds dry goods inventory
- 百度上找的期货公司安全吗?期货公司怎么确定正规
- 2022-2-15 learning the imitation Niuke project - Section 3 post details
- Research Report on the development trend and competitive strategy of the global powder filling machine industry
猜你喜欢

C learning notes (5) class and inheritance

One of the data Lake series | you must love to read the history of minimalist data platforms, from data warehouse, data lake to Lake warehouse

JVM performance tuning and practical basic theory part II

Details of appium key knowledge

对于编程思想和能力有重大提升的书有哪些?
![[Verilog quick start of Niuke question series] ~ use functions to realize data size conversion](/img/e1/d35e1d382e0e945849010941b219d3.png)
[Verilog quick start of Niuke question series] ~ use functions to realize data size conversion

Guess lantern riddles, not programmers still can't understand?
![After twists and turns, I finally found the method of SRC vulnerability mining [recommended collection]](/img/ac/ab6053e6ea449beedf434d4cf07dbb.png)
After twists and turns, I finally found the method of SRC vulnerability mining [recommended collection]

C 语言基础
![[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](/img/30/aea4ae24f418eb971bca77a1d46bef.png)
[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
随机推荐
Effet halo - qui dit qu'il y a de la lumière sur la tête est un héros
【R语言数据科学】:机器学习常见评估指标
One of the first steps to redis
问题随记 —— Oracle 11g 卸载
tensorflow2-savedmodel convert to pb(frozen_graph)
Fundamentals of C language
微服务大行其道的今天,Service Mesh是怎样一种存在?
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?
Build your own website (14)
JVM performance tuning and practical basic theory part II
Reorganize the trivial knowledge points at the end of the term
SQLAchemy 常用操作
关于软件测试的一些思考
Cannot link redis when redis is enabled
Opencv mat class
生成随机数(4位、6位)
Research Report on the development trend and competitive strategy of the global facial wrinkle removal and beauty instrument industry
QT capture interface is displayed as picture or label
Music player development example (can be set up)
数据湖系列之一 | 你一定爱读的极简数据平台史,从数据仓库、数据湖到湖仓一体