当前位置:网站首页>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#学习笔记(5)类和继承
- Microservice development steps (Nacos)
- 使用net core 6 c# 的 NPOI 包,读取excel..xlsx单元格内的图片,并存储到指定服务器
- When the main process architecture game, to prevent calls everywhere to reduce coupling, how to open the interface to others to call?
- Don't want to knock the code? Here comes the chance
- Research Report on development trend and competitive strategy of global vibration polishing machine industry
- Research Report on the development trend and competitive strategy of the global ultrasonic scalpel system industry
- Research Report on the development trend and competitive strategy of the global facial wrinkle removal and beauty instrument industry
- NPDP能给产品经理带来什么价值?你都知道了吗?
- 音乐播放器开发实例(可毕设)
猜你喜欢

The State Administration of Chia Tai market supervision, the national development and Reform Commission and the China Securities Regulatory Commission jointly reminded and warned some iron ores

Tdengine connector goes online Google Data Studio app store

Microservice development steps (Nacos)

【牛客网刷题系列 之 Verilog快速入门】~ 多功能数据处理器、求两个数的差值、使用generate…for语句简化代码、使用子模块实现三输入数的大小比较

C learning notes (5) class and inheritance
![[commercial terminal simulation solution] Shanghai daoning brings you Georgia introduction, trial and tutorial](/img/44/b65aaf11b1e632f2dab55b6fc699f6.jpg)
[commercial terminal simulation solution] Shanghai daoning brings you Georgia introduction, trial and tutorial

sqlilabs less10

Use the right scene, get twice the result with half the effort! Full introduction to the window query function and usage scenarios of tdengine

sqlilabs less-8

Fundamentals of C language
随机推荐
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é
C 语言进阶
It's suitable for people who don't have eloquence. The benefits of joining the China Video partner program are really delicious. One video gets 3 benefits
官宣:Apache Doris 顺利毕业,成为 ASF 顶级项目!
深度合作 | 涛思数据携手长虹佳华为中国区客户提供 TDengine 强大企业级产品与完善服务保障
Force deduction solution summary 241- design priority for operation expression
In depth cooperation | Taosi data cooperates with changhongjia Huawei customers in China to provide tdengine with powerful enterprise level products and perfect service guarantee
sqlilabs less13
Research Report on the development trend and competitive strategy of the global commercial glassware industry
使用net core 6 c# 的 NPOI 包,读取excel..xlsx单元格内的图片,并存储到指定服务器
sqlilabs less9
生成随机数(4位、6位)
Research Report on the development trend and competitive strategy of the global powder filling machine industry
NPDP能给产品经理带来什么价值?你都知道了吗?
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
2022-2-15 learning xiangniuke project - Section 4 business management
手把手带你入门 API 开发
SWT / anr problem - how to capture performance trace
[15. Interval consolidation]
JVM performance tuning and practical basic theory part II