一、环境准备:
1.下载源码并解压:
https://gitee.com/y_project/RuoYi-Vue
2.前端工程配置修改及打包:
进入ruoyi-ui项目下的vue.config.js文件里的服务端口和后端地址:
在ruoyi-ui目录下打开PowerShell窗口并打包项目生成dist静态资源目录:
npm install
npm run build:prod
3.将dist目录拷贝至nginx的html目录,修改nginx配置文件nginx.conf,注意对应修改后端地址
server {
listen 80;
server_name localhost;
location / {
root /usr/share/nginx/html/dist;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /prod-api/{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://10.0.0.13:8080/;
}
}
4.后端工程打包
修改数据库连接:ruoyi-admin项目下src-main-resources的application-druid.yml
修改服务器配置:ruoyi-admin项目下src-main-resources的application.yml
在RuoYi-Vue的bin目录下执行package.bat利用maven打包项目,会在ruoyi-admin下生成文件夹target包含ruoyi-admin.jar
二、传统方式部署:
1.创建MySQL数据库ry-vue
将sql文件夹下的quartz.sql和ry_20220822.sql导入
create database ry-vue character set utf8 collate utf8_bin;
use ry-vue;
source quartz.sql;
source ry_20220822.sql;
2.安装并启动redis,配置文件设置密码123456
3.安装并启动nginx,将dist目录拷贝至nginx的html目录,注意修改配置文件
4.启动若依主程序
nohup java -jar ruoyi-admin.jar > ruoyi_log.out 2>&1 &
浏览器登录http://IP admin ruoyi
三、docker方式部署
1.先看看目录情况
conf目录里面是nginx和redis配置文件
nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /home/ruoyi/projects/ruoyi-ui;
try_files $uri $uri/ /index.html;
index index.html index.htm;
}
location /prod-api/{
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header REMOTE-HOST $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://ruoyi-server:8080/;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
redis.conf
requirepass 123456
db目录里面是数据库初始化脚本
html目录里面是前端包
jar目录里面是打包的jar文件
另外需要创建mysql、nginx、redis和ruoyi四个目录作为docker容器的本地目录映射
2.编写用到得4个组件mysql、redis、nginx和ruoyi的dockerfile制作镜像
mysql-dockerfile
# 基础镜像
FROM mysql:5.7.33
# author
MAINTAINER zaker
# 执行sql脚本
ADD ./db/*.sql /docker-entrypoint-initdb.d/
redis-dockerfile
# 基础镜像
FROM redis:6.2-alpine
# author
MAINTAINER zaker
# 挂载目录
VOLUME /home/ruoyi/redis
# 创建目录
RUN mkdir -p /home/ruoyi/redis
# 指定路径
WORKDIR /home/ruoyi/redis
# 复制conf文件到路径
COPY ./conf/redis.conf /home/ruoyi/redis/redis.conf
nginx-dockerfile
# 基础镜像
FROM nginx:1.21.1
# author
MAINTAINER zaker
# 挂载目录
VOLUME /home/ruoyi/projects/ruoyi-ui
# 创建目录
RUN mkdir -p /home/ruoyi/projects/ruoyi-ui
# 指定路径
WORKDIR /home/ruoyi/projects/ruoyi-ui
# 复制conf文件到路径
COPY ./conf/nginx.conf /etc/nginx/nginx.conf
# 复制html文件到路径
COPY ./html/dist /home/ruoyi/projects/ruoyi-ui
ruoyi-dockerfile
# 基础镜像
FROM java:8
# author
MAINTAINER zaker
# 挂载目录
VOLUME /home/ruoyi
# 创建目录
RUN mkdir -p /home/ruoyi
# 指定路径
WORKDIR /home/ruoyi
# 复制jar文件到路径
COPY ./jar/*.jar /home/ruoyi/ruoyi.jar
# 启动应用
ENTRYPOINT ["java","-jar","ruoyi.jar"]
3.编写docker-compose.yml
version : '3'
services:
ruoyi-mysql:
container_name: ruoyi-mysql
image: mysql-ruoyi:1.0
build:
context: .
dockerfile: mysql-dockerfile
ports:
- "3306:3306"
volumes:
- ./mysql/conf:/etc/mysql/conf.d
- ./mysql/logs:/logs
- ./mysql/data:/var/lib/mysql
command: [
'mysqld',
'--innodb-buffer-pool-size=80M',
'--character-set-server=utf8mb4',
'--collation-server=utf8mb4_unicode_ci',
'--default-time-znotallow=+8:00',
'--lower-case-table-names=1'
]
environment:
MYSQL_DATABASE: 'ry-vue'
MYSQL_ROOT_PASSWORD: password
ruoyi-redis:
container_name: ruoyi-redis
image: redis-ruoyi:1.0
build:
context: .
dockerfile: redis-dockerfile
ports:
- "6379:6379"
volumes:
- ./conf/redis.conf:/home/ruoyi/redis/redis.conf
- ./redis/data:/data
command: redis-server /home/ruoyi/redis/redis.conf
ruoyi-nginx:
container_name: ruoyi-nginx
image: nginx-ruoyi:1.0
build:
context: .
dockerfile: nginx-dockerfile
ports:
- "80:80"
volumes:
- ./html/dist:/home/ruoyi/projects/ruoyi-ui
- ./conf/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/logs:/var/log/nginx
- ./nginx/conf.d:/etc/nginx/conf.d
depends_on:
- ruoyi-server
links:
- ruoyi-server
ruoyi-server:
container_name: ruoyi-server
image: server-ruoyi:1.0
build:
context: .
dockerfile: ruoyi-dockerfile
ports:
- "8080:8080"
volumes:
- ./ruoyi/logs:/home/ruoyi/logs
- ./ruoyi/uploadPath:/home/ruoyi/uploadPath
depends_on:
- ruoyi-mysql
- ruoyi-redis
links:
- ruoyi-mysql
- ruoyi-redis
4.启动容器
docker-compose up -d
登录页面
四、k8s方式部署(使用kuboard图形化)
1.创建名称空间
2.创建mysql的statefulset
首先需要创建pvc
创建my.cnf的configmap
创建工作负载容器
3.创建redis的deployment
创建redis配置configmap
4.创建nginx的deployment
5.创建ruoyi-server
标签:部署,redis,ruoyi,若依,nginx,三种,conf,mysql,home From: https://blog.51cto.com/u_15233520/5833873