赞
踩
仅供学习实践。
若依系统docker-compose部署
以下命令适用于CentOS7.x版本,我的实验环境为虚拟机。
不赘述
不赘述
获取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
下载依赖镜像
依赖镜像名称可以从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
下载镜像,执行命令:
docker pull nacos/nacos-server
docker pull mysql:5.7
docker pull redis
docker pull nginx
启动Ruoyi基础服务
脚本授权:
cd docker
chmod +x deploy.sh
启动基础服务:
./deploy.sh base
检查启动情况:
# 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
正常情况redis
和mysql
服务是正常的,nacos
启动失败,暂时不用管。
导入Ruoyi SQL脚本
将nacos
脚本复制到mysql
容器:
cd mysql/db/
docker cp ry_20230706.sql f3e908b5989d:/
docker cp ry_config_20220929.sql f3e908b5989d:/
进入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>
创建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
使用exit
退出mysql
客户端,再次使用exit
退出容器。
重启nacos
执行命令查询启动失败的nacos
容器ID:
docker ps -a
# 返回
CONTAINER ID IMAGE
e0e44800a523 nacos/nacos-server
重启nacos
:
docker restart e0e44800a523
观察nacos日志,正常nacos可以启动成功:
docker logs e0e44800a523
登录nacos修改Ruoyi微服务配置
通过http://虚机IP:8848/nacos
访问nacos页面(nacos/nacos
):
修改ruoyi-gateway-dev.yml
配置:
spring:
redis:
host: localhost #改为虚机IP
port: 6379
password:
修改ruoyi-auth-dev.yml
配置:
spring:
redis:
host: localhost #改为虚机IP
port: 6379
password:
修改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
修改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
修改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
修改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
安装vim、zip命令:
yum install zip vim -y
以第一个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} ...
其它jar包修改过程同理,不在赘述。
启动Ruoyi微服务
[root@localhost docker]# ./deploy.sh modules
正常情况,会启动:nginx,docker_ruoyi-modules-system,docker_ruoyi-auth,docker_ruoyi-gateway
4个容器进程:
[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
修改Nginx前端文件位置
官方镜像中提供的Ruoyi 前端页面位置有问题,访问Ruoyi前端会返回403,需要进入容器内部修改前端文件位置:
docker exec -it 127ea30c521d bash
cd /home/ruoyi/projects/ruoyi-ui/dist/
mv ./* ../
将前端页面上移一层目录。也可以通过改nginx配置解决该问题(未尝试)。
访问Ruoyi地址
关闭防火墙等
systemctl stop firewalld
setenforce 0
浏览器访问前端地址:
http://虚机IP
admin/admin123
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。