当前位置:   article > 正文

使用docker-compose部署rouyi-cloud_ruoyi-cloud的docker部署

ruoyi-cloud的docker部署

前言

仅供学习实践。
若依系统docker-compose部署
以下命令适用于CentOS7.x版本,我的实验环境为虚拟机

一、安装docker

不赘述

二、安装docker-compose

不赘述

三、Ruoyi部署

  1. 获取Ruoyi部署文件

    获取地址:https://gitee.com/y_project/RuoYi-Cloud/tree/master/docker

    目录结构如下:

    ├── docker
    │   ├── copy.sh
    │   ├── deploy.sh
    │   ├── docker-compose.yml
    │   ├── mysql
    │   │   ├── conf
    │   │   ├── data
    │   │   ├── db
    │   │   ├── dockerfile
    │   │   └── logs
    │   ├── nacos
    │   │   ├── conf
    │   │   ├── dockerfile
    │   │   └── logs
    │   ├── nginx
    │   │   ├── conf
    │   │   ├── conf.d
    │   │   ├── dockerfile
    │   │   ├── html
    │   │   └── logs
    │   ├── redis
    │   │   ├── conf
    │   │   ├── data
    │   │   └── dockerfile
    │   └── ruoyi
    │       ├── auth
    │       ├── gateway
    │       ├── modules
    │       └── visual
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
  2. 下载依赖镜像

    依赖镜像名称可以从docker/docker-compose.yaml文件中获取:

    [root@localhost docker]# cat docker-compose.yml | grep image:
        image: nacos/nacos-server
        image: mysql:5.7
        image: redis
        image: nginx
    
    • 1
    • 2
    • 3
    • 4
    • 5

    下载镜像,执行命令:

    docker pull nacos/nacos-server
    docker pull mysql:5.7
    docker pull redis
    docker pull nginx
    
    • 1
    • 2
    • 3
    • 4
  3. 启动Ruoyi基础服务

    脚本授权:

    cd docker
    chmod +x deploy.sh
    
    • 1
    • 2

    启动基础服务:

    ./deploy.sh base
    
    • 1

    检查启动情况:

    # docker ps
    CONTAINER ID   IMAGE                         COMMAND                  CREATED       STATUS       PORTS                                                                                                      NAMES
    f3e908b5989d   mysql:5.7                     "docker-entrypoint.s…"   6 hours ago   Up 6 hours   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp                                                       ruoyi-mysql
    090a066f03f8   redis                         "docker-entrypoint.s…"   6 hours ago   Up 6 hours   0.0.0.0:6379->6379/tcp, :::6379->6379/tcp                                                                  ruoyi-redis
    
    
    • 1
    • 2
    • 3
    • 4
    • 5

    正常情况redismysql服务是正常的,nacos启动失败,暂时不用管。

  4. 导入Ruoyi SQL脚本

    nacos脚本复制到mysql容器:

    cd mysql/db/
    docker cp ry_20230706.sql f3e908b5989d:/
    docker cp ry_config_20220929.sql f3e908b5989d:/
    
    • 1
    • 2
    • 3

    进入mysql容器,连接mysql服务

    # docker exec -it f3e908b5989d bash
    
    root@f3e908b5989d:/# mysql -uroot -ppassword
    mysql: [Warning] Using a password on the command line interface can be insecure.
    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 41
    Server version: 5.7.36 MySQL Community Server (GPL)
    
    Copyright (c) 2000, 2021, Oracle and/or its affiliates.
    
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    
    Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
    
    mysql> 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    创建nacos库,导入SQL脚本:

    create database `ry-config` character set utf8 collate utf8_general_ci;
    
    use ry-cloud;
    source /ry_20230706.sql;
    
    use ry-config;
    source /ry_config_20220929.sql;
    
    exit
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    使用exit退出mysql客户端,再次使用exit退出容器。

  5. 重启nacos

    执行命令查询启动失败的nacos容器ID:

    docker ps -a
    # 返回
    CONTAINER ID   IMAGE
    e0e44800a523   nacos/nacos-server 
    
    • 1
    • 2
    • 3
    • 4

    重启nacos

    docker restart e0e44800a523
    
    • 1

    观察nacos日志,正常nacos可以启动成功:

    docker logs e0e44800a523
    
    • 1
  6. 登录nacos修改Ruoyi微服务配置

    通过http://虚机IP:8848/nacos访问nacos页面(nacos/nacos):

    修改ruoyi-gateway-dev.yml配置:

    spring:
      redis:
        host: localhost #改为虚机IP
        port: 6379
        password:
    
    • 1
    • 2
    • 3
    • 4
    • 5

    修改ruoyi-auth-dev.yml配置:

    spring:
      redis:
        host: localhost #改为虚机IP
        port: 6379
        password:
    
    • 1
    • 2
    • 3
    • 4
    • 5

    修改ruoyi-system-dev.yml配置:

    spring:
      redis:
        host: localhost #改为虚机IP
        port: 6379
        password:
        
        ...
        
          datasource:
              master:
                driver-class-name: com.mysql.cj.jdbc.Driver
                #改为虚机IP
                url: jdbc:mysql://localhost:3306/ry-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
                username: root
                password: password
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    修改ruoyi-gen-dev.yml配置:

    spring:
      redis:
        host: localhost #改为虚机IP
        port: 6379
        password:
      datasource:
        driver-class-name: com.mysql.cj.jdbc.Driver
        # #改为虚机IP
        url: jdbc:mysql://localhost:3306/ry-cloud?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
        username: root
        password: password
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    修改ruoyi-job-dev.yml配置:

    spring:
      redis:
        host: localhost  #改为虚机IP
        port: 6379
        password: 
      datasource:
        driver-class-name: com.mysql.cj.jdbc.Driver
        #改为虚机IP
        url: jdbc:mysql://localhost:3306/ry-cloud? useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
        username: root
        password: password
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
  7. 修改Ruoyi jar包配置文件

    查找jar包:

    [root@localhost docker]# find ./ -name *.jar
    ./ruoyi/auth/jar/ruoyi-auth.jar
    ./ruoyi/gateway/jar/ruoyi-gateway.jar
    ./ruoyi/modules/file/jar/ruoyi-modules-file.jar
    ./ruoyi/modules/gen/jar/ruoyi-modules-gen.jar
    ./ruoyi/modules/job/jar/ruoyi-modules-job.jar
    ./ruoyi/modules/system/jar/ruoyi-modules-system.jar
    ./ruoyi/visual/monitor/jar/ruoyi-visual-monitor.jar
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    安装vim、zip命令:

    yum install zip vim -y
    
    • 1

    以第一个jar包为例./ruoyi/auth/jar/ruoyi-auth.jar,编辑jar包:

    vim ./ruoyi/auth/jar/ruoyi-auth.jar
    # 找到bootstrap.yml,将所有的localhost改为虚机IP地址
    ...
      cloud:
        nacos:
          discovery:
            # 服务注册地址
            server-addr: 192.168.22.134:8848
          config:
            # 配置中心地址
            server-addr: 192.168.22.134:8848
            # 配置文件格式
            file-extension: yml
            # 共享配置
            shared-configs:
              - application-${spring.profiles.active}.${spring.cloud.nacos.config.file-extension}
    ...
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    其它jar包修改过程同理,不在赘述。

  8. 启动Ruoyi微服务

    [root@localhost docker]# ./deploy.sh modules
    
    • 1

    正常情况,会启动:nginx,docker_ruoyi-modules-system,docker_ruoyi-auth,docker_ruoyi-gateway4个容器进程:

    [root@localhost docker]# docker ps 
    CONTAINER ID   IMAGE                         COMMAND                  CREATED       STATUS       PORTS                                                                                                      NAMES
    fcdbd6c56ab4   keking/kkfileview             "java -Dfile.encodin…"   4 hours ago   Up 4 hours   0.0.0.0:8012->8012/tcp, :::8012->8012/tcp                                                                  ecstatic_jones
    127ea30c521d   nginx                         "/docker-entrypoint.…"   6 hours ago   Up 6 hours   0.0.0.0:80->80/tcp, :::80->80/tcp                                                                          ruoyi-nginx
    fb72aea1d703   docker_ruoyi-modules-system   "java -jar ruoyi-mod…"   6 hours ago   Up 6 hours   0.0.0.0:9201->9201/tcp, :::9201->9201/tcp                                                                  ruoyi-modules-system
    75ebd2c9118a   docker_ruoyi-auth             "java -jar ruoyi-aut…"   6 hours ago   Up 6 hours   0.0.0.0:9200->9200/tcp, :::9200->9200/tcp                                                                  ruoyi-auth
    4bc210701adb   docker_ruoyi-gateway          "java -jar ruoyi-gat…"   6 hours ago   Up 6 hours   0.0.0.0:8080->8080/tcp, :::8080->8080/tcp                                                                  ruoyi-gateway
    e0e44800a523   nacos/nacos-server            "bin/docker-startup.…"   7 hours ago   Up 6 hours   0.0.0.0:8848->8848/tcp, :::8848->8848/tcp, 0.0.0.0:9848-9849->9848-9849/tcp, :::9848-9849->9848-9849/tcp   ruoyi-nacos
    f3e908b5989d   mysql:5.7                     "docker-entrypoint.s…"   7 hours ago   Up 6 hours   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp                                                       ruoyi-mysql
    090a066f03f8   redis                         "docker-entrypoint.s…"   7 hours ago   Up 6 hours   0.0.0.0:6379->6379/tcp, :::6379->6379/tcp                                                                  ruoyi-redis
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
  9. 修改Nginx前端文件位置

    官方镜像中提供的Ruoyi 前端页面位置有问题,访问Ruoyi前端会返回403,需要进入容器内部修改前端文件位置:

    docker exec -it 127ea30c521d bash
    cd /home/ruoyi/projects/ruoyi-ui/dist/
    mv ./* ../
    
    • 1
    • 2
    • 3

    将前端页面上移一层目录。也可以通过改nginx配置解决该问题(未尝试)。

  10. 访问Ruoyi地址

    关闭防火墙等

    systemctl stop firewalld
    setenforce 0
    
    • 1
    • 2

    浏览器访问前端地址:

    http://虚机IP

    admin/admin123

四、参考资料

  1. http://doc.ruoyi.vip/ruoyi-cloud/cloud/dokcer.html#%E9%A1%B9%E7%9B%AE%E9%83%A8%E7%BD%B2
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:【wpsshop博客】
推荐阅读
相关标签
  

闽ICP备14008679号