首页 > 数据库 >centos7环境用docker-compose部署mysql5.7集群,redis7.2.4,springboot项目

centos7环境用docker-compose部署mysql5.7集群,redis7.2.4,springboot项目

时间:2024-02-28 12:44:25浏览次数:31  
标签:compose redis7.2 springboot redis db miouo master mysql slave

文件目录结构

image

关于每个配置项及docker-compose的安装,大家可以自己查

mysql配置文件

master --- my.cnf

[mysqld]
server_id =  1

gtid-mode  =  ON
enforce-gtid-consistency    =   1

binlog-ignore-db    =   mysql
log-bin             =   mysql-bin
binlog_cache_size   =   1M
binlog_format       =   mixed
expire_logs_days    =   7
slave_skip_errors   =   1062
log_slave_updates   =   ON

slave1 --- my.cnf

[mysqld]
server_id   = 2

gtid-mode                =  ON
enforce-gtid-consistency =  1

binlog-ignore-db    =   mysql
log-bin             =   mysql-slave1-bin
binlog_cache_size   =   1M
binlog_format       =   mixed
expire_logs_days    =   7
slave_skip_errors   =   1062
relay_log           =   mysql-relay-bin
log_slave_updates   =   ON
read_only           =   1

slave1 --- my.cnf

[mysqld]
server_id   = 3

gtid-mode                =  ON
enforce-gtid-consistency =  1

binlog-ignore-db    =   mysql
log-bin             =   mysql-slave1-bin
binlog_cache_size   =   1M
binlog_format       =   mixed
expire_logs_days    =   7
slave_skip_errors   =   1062
relay_log           =   mysql-relay-bin
log_slave_updates   =   ON
read_only           =   1

redis配置文件

master --- redis.conf

port 6379
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000

docker

Dockerfile

Dockerfiles --- Dockerfile-Spring-boot

FROM openjdk:8
WORKDIR /app
COPY ./jars/fmovies-0.0.1-SNAPSHOT.jar app.jar
ENTRYPOINT ["java","-jar","app.jar"]

docker-compose.yaml

docker-compose.yaml

version: '3'

networks:
  miouo-fmovies-network:
    driver: bridge

services:
  springboot-app:
    networks:
      - miouo-fmovies-network
    build:
      context: .
      dockerfile: ./Dockerfiles/Dockerfile-Spring-Boot
    image: miouo-fmovies:0.0.1
    container_name: miouo-fmovies-0.0.1
    ports:
      - "8080:8080"
    depends_on:
      - mysql-master
      - mysql-slave-1
      - mysql-slave-2
      - redis-master-1
 
  mysql-master:
   container_name: miouo-mysql5.7-master
   hostname: mysql-master
   image: "mysql:5.7"
   ports:
     - "33070:3306"
   networks:
     - miouo-fmovies-network
   volumes:
     - ./db/mysql/master/etc:/etc/mysql
     - ./db/mysql/master/var/lib:/var/lib/mysql
     - ./db/mysql/master/my.cnf:/etc/my.cnf
     - ./db/mysql/master/init_db:/docker-entrypoint-initdb.d/
   environment:
     MYSQL_ROOT_PASSWORD: 123456
     MYSQL_DATABASE: fmovies
   command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
   restart: always

  mysql-slave-1:
    container_name: miouo-mysql5.7-slave-1
    hostname: mysql-slave-1
    image: "mysql:5.7"
    ports:
      - "33071:3306"
    networks: 
      - miouo-fmovies-network
    volumes:
      - ./db/mysql/slave1/etc:/etc/mysql
      - ./db/mysql/slave1/var/lib:/var/lib/mysql
      - ./db/mysql/slave1/my.cnf:/etc/my.cnf
      - ./db/mysql/slave1/init_db:/docker-entrypoint-initdb.d/
    environment:
      - TZ=Asia/Shanghai
      - MYSQL_ROOT_PASSWORD=123456
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    restart: always

  mysql-slave-2:
    container_name: miouo-mysql5.7-slave-2
    hostname: mysql-slave-2
    image: "mysql:5.7"
    ports:
      - "33072:3306"
    networks:
      - miouo-fmovies-network    
    volumes:
      - ./db/mysql/slave2/etc:/etc/mysql
      - ./db/mysql/slave2/var/lib:/var/lib/mysql
      - ./db/mysql/slave2/my.cnf:/etc/my.cnf
      - ./db/mysql/slave2/init_db:/docker-entrypoint-initdb.d/
    environment:
      - TZ=Asia/Shanghai
      - MYSQL_ROOT_PASSWORD=123456
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    restart: always

  redis-master-1:
    image: redis:7.2.4
    container_name: miouo-redis7.2.4-master-1
    restart: always
    command: ["redis-server", "/usr/local/etc/redis/redis.conf"]
    ports:
      - 6379:6379
    volumes:
      - ./db/redis/master/data:/data
      - ./db/redis/master/redis.conf:/usr/local/etc/redis/redis.conf
    networks:
      - miouo-fmovies-network

编排

命令行

docker-compose up -d

结果

image

此时mysql仍未集群,需要进入miouo-mysql5.7-master,miouo-mysql5.7-slave-1,miouo-mysql5.7-slave-2中进行联通

miouo-mysql5.7-master --- 连接主节点创建复制账号

image

miouo-mysql5.7-slave-1 --- 连接从节点重置主

image

miouo-mysql5.7-slave-2 --- 连接从节点重置主

image

集群结果

image

项目测试

image

标签:compose,redis7.2,springboot,redis,db,miouo,master,mysql,slave
From: https://www.cnblogs.com/fcloud/p/18039876

相关文章

  • springboot两种配置文件的使用(举例:端口号、虚拟路径配置)
    1、properties配置文件使用   2、yml配置文件、yaml配置文件 在项目中更常用 在项目中一般yml配置文件更为常用,因为yml层级更加明确、清晰,更为关注数据。 ......
  • 如何在SpringBoot中优雅地重试调用第三方API?
    1引言在实际的应用中,我们经常需要调用第三方API来获取数据或执行某些操作。然而,由于网络不稳定、第三方服务异常等原因,API调用可能会失败。为了提高系统的稳定性和可靠性,我们通常会考虑实现重试机制。本文将深入探讨如何在SpringBoot项目中优雅地重试调用第三方API,并结合代码......
  • SpringBoot 2x 系列之(七)web场景
    web场景1.SpringMVC自动配置概览SpringBootprovidesauto-configurationforSpringMVCthatworkswellwithmostapplications.(大多场景我们都无需自定义配置)Theauto-configurationaddsthefollowingfeaturesontopofSpring’sdefaults:InclusionofCont......
  • SpringBoot 2x 系列之(五)开发技巧
    开发技巧1.Lombok1.应用场景简化JavaBean的开发帮我们在编译时生成get、set、toString方法2.安装及使用引入依赖【SpringBoot已经做了版本仲裁】<dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId></depende......
  • SpringBoot 2x 系列之(四)自动配置
    自动配置1.引导加载自动配置类见SpringBoot1.md一、SpringBoot入门4.2主程序类,主入口类【自动配置原理】1.1@SpringBootConfiguration见SpringBoot1.md一、SpringBoot入门4.2主程序类,主入口类【自动配置原理】[email protected]@AutoConfi......
  • SpringBoot 2x 系列之(三)容器功能
    容器功能1.组件添加1.1@Configuration结合@Bean注册组件@Configuration见[email protected]@Component、@Controller、@Service、@Repository见Spring.md相关内容1.3@ComponentScan见[email protected]@Import见Spring.md8.......
  • SpringBoot 2x 系列之(二)SpringBoot特点
    SpringBoot特点1.依赖管理特性SpringBoot已经为我们做了版本仲裁,那么如果我们要修改已经做了版本仲裁的依赖,比如mysql驱动的依赖,该怎么做呢?查看spring-boot-dependencies里面规定的当前依赖版本用的properties属性在当前项目里面重新配置<properties><mysql.versi......
  • SpringBoot 2x 系列之(一)基础入门
    基础入门课程规划1.时代背景响应式编程解决的问题:如何使用少量资源编写一个极高吞吐量、能承担大并发的应用响应式应用:占用少量的资源(线程)处理大量的并发springboot:整合spring整个生态圈的一站式框架​ 高层框架,底层是SpringFrameworkSpring:1)从微观角度说Spring指Spri......
  • SpringBoot 1x 系列之(十一)Spring Boot与任务
    SpringBoot与任务异步任务、定时任务、邮件任务1.异步任务1.1应用场景执行一些操作(如:邮件任务等)不想阻塞当前线程的情况下,可以通过多线程的方式进行异步处理。1.2快速使用主配置类//开启@Async异步注解功能@EnableAsync@EnableRabbit@EnableCaching@MapperScan("co......
  • SpringBoot 1x 系列之(十)Spring Boot与检索
    SpringBoot与检索ElasticSearch1.ElasticSearch简介1)Java语言编写的开源全文搜索引擎。2)用于快速的存储、搜索和分析海量数据。3)是一个分布式搜索服务。4)提供RestfulAPI,通过发送请求的方式就可以将ElasticSearch用起来。5)底层基于Lucene(开源的搜索引擎软件工具包)2.Doc......