当前位置:网站首页>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
边栏推荐
- WebSocket(简单体验版)
- Details of appium key knowledge
- Halo effect - who says that those with light on their heads are heroes
- 手把手带你入门 API 开发
- tensorflow2-savedmodel convert to tflite
- [repair version] imitating the template of I love watching movies website / template of ocean CMS film and television system
- sqlilabs less-8
- Research Report on the development trend and competitive strategy of the global navigation simulator industry
- 问题随记 —— Oracle 11g 卸载
- 适合没口才的人做,加入中视频伙伴计划收益是真香,一个视频拿3份收益
猜你喜欢

2022-2-15 learning xiangniuke project - Section 4 business management

Using CMD to repair and recover virus infected files

Yyds dry goods inventory hcie security day13: firewall dual machine hot standby experiment (I) firewall direct deployment, uplink and downlink connection switches

241. 为运算表达式设计优先级

Leetcode(69)——x 的平方根

Salesforce, Johns Hopkins, Columbia | progen2: exploring the boundaries of protein language models

Salesforce、约翰霍普金斯、哥大 | ProGen2: 探索蛋白语言模型的边界

sqlilabs less-8
![[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

互联网医院系统源码 医院小程序源码 智慧医院源码 在线问诊系统源码
随机推荐
微服务大行其道的今天,Service Mesh是怎样一种存在?
tensorflow2-savedmodel convert to tflite
En utilisant le paquet npoi de net Core 6 c #, lisez Excel.. Image dans la cellule xlsx et stockée sur le serveur spécifié
关于重载运算符的再整理
2022-2-15 learning the imitation Niuke project - post in Section 2
官宣:Apache Doris 顺利毕业,成为 ASF 顶级项目!
Pat 1121 damn single (25 points) set
Research Report on the development trend and competitive strategy of the global diamond suspension industry
Research Report on the development trend and competitive strategy of the global chemical glassware industry
Leetcode(69)——x 的平方根
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
How to view the state-owned enterprises have unloaded Microsoft office and switched to Kingsoft WPS?
Tdengine connector goes online Google Data Studio app store
Research Report on the development trend and competitive strategy of the global commercial glassware industry
【牛客网刷题系列 之 Verilog快速入门】~ 使用函数实现数据大小端转换
Vnctf2022 open web gocalc0
What problems should be considered for outdoor LED display?
[Verilog quick start of Niuke question series] ~ use functions to realize data size conversion
Guess lantern riddles, not programmers still can't understand?
Sqlachemy common operations