Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

搭建mongodb副本集数据库 #21

Open
apersonw opened this issue Jun 30, 2020 · 0 comments
Open

搭建mongodb副本集数据库 #21

apersonw opened this issue Jun 30, 2020 · 0 comments

Comments

@apersonw
Copy link
Owner

apersonw commented Jun 30, 2020

一、创建docker-compose.yml文件

version: '3.7'
services:
  master-mongo:
    image: mongo
    container_name: master-mongo
    ports:
    - "27017:27017"
    volumes:
    - ./data/master:/data/db
    command: mongod --dbpath /data/db --replSet testSet --oplogSize 128
  secondary-mongo:
    image: mongo
    container_name: secondary-mongo
    ports:
    - "27018:27017"
    volumes:
    - ./data/secondary:/data/db
    command: mongod --dbpath /data/db --replSet testSet --oplogSize 128
  arbiter-mongo:
    image: mongo
    container_name: arbiter-mongo
    ports:
    - "27019:27017"
    volumes:
    - ./data/arbiter:/data/db
    command: mongod --dbpath /data/db --replSet testSet --oplogSize 128

二、进入master节点终端bash

#1、输入mongo命令,进入mongo命令行
#2、输入以下副本集加入配置(10.22.33.44是宿主机的ip地址)
config={
  _id:"testSet",
  members:[
    {_id:0,host:"10.22.33.44:27017","priority": 2},
    {_id:1,host:"10.22.33.44:27018","priority": 1},
    {_id:2,host:"10.22.33.44:27019","priority": 1}
  ]
}
#3、根据config初始化,初始化成功会返回ok
rs.initiate(config)
#4、查看状态命令
rs.status()

三、在@configuration注解下添加响应式事务管理器

@Bean
ReactiveMongoTransactionManager reactiveTransactionManager(ReactiveMongoDatabaseFactory reactiveMongoDatabaseFactory) {
    return new ReactiveMongoTransactionManager(reactiveMongoDatabaseFactory);
}

四、在需要使用事务的地方添加注解即可

@Transactional
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant