ruoyi框架学习-1-环境准备

ruoyi框架学习

虚拟机内安装必要组件

安装mysql

1
2
3
4
5
6
7
8
9
docker run   --name test-mysql  -p 13306:3306  -e MYSQL_ROOT_PASSWORD=123456  -d mysql:5.7
docker cp test-mysql:/etc/mysql /data/app/mysql5.7/cnf
docker cp test-mysql:/etc/mysql /data/app/mysql5.7/cnf
docker cp test-mysql:/var/lib/mysql /data/app/mysql5.7/data
docker cp test-mysql:/var/log /data/app/mysql5.7/log
docker cp test-mysql:/var/lib/mysql-files /data/app/mysql5.7/mysql-files

docker rm -f test-mysql
docker run --restart=always --name test-mysql -v /data/app/mysql5.7/cnf:/etc/mysql -v /data/app/mysql5.7/data:/var/lib/mysql -v /data/app/mysql5.7/log:/var/log -v /data/app/mysql5.7/mysql-files:/var/lib/mysql-files -p 13306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7

安装 zk / kafka /redis

docker-compose up -d

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
30
31
32
version: '3.8'
services:
zookeeper:
image: wurstmeister/zookeeper
ports:
- "2181:2181"
mem_limit: 256m
kafka:
image: wurstmeister/kafka
depends_on: [ zookeeper ]
ports:
- "9092:9092"
environment:
#KAFKA_ADVERTISED_HOST_NAME: kafka
KAFKA_ADVERTISED_HOST_NAME: 192.168.16.130
KAFKA_CREATE_TOPICS: "test:1:1"
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
mem_limit: 1024m
redis-master:
image: redis:3.2.3-alpine
container_name: redis_n
restart: always
ports:
- 16379:6379
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- /data/app/redis/redis.conf:/usr/local/etc/redis/redis.conf:rw
- /data/app/redis/data:/data:rw
mem_limit: 512m


wnindows环境准备

组件版本不对可能会有异常报错.可以自行尝试

java

使用的版本是 1.8

maven

使用版本是 3.9.2

node

使用的版本是 v10.24.1
记得修改为国内源

下载项目(以2.2vue版本为例)

1
git clone -v v2.2 https://gitee.com/y_project/RuoYi-Vue.git

idea打开项目

后端项目修改配置

创建数据库
并执行RuoYi-Vue\ruoyi\sql 中的脚本初始化数据库
修改文件RuoYi-Vue\ruoyi\src\main\resources\application-druid.yml.包括数据库连接redis连接
就可以启动了
img.png

前端下载依赖组件

1
2
3
4
5
cd RuoYi-Vue\ruoyi-ui
npm install
npm run dev
# 前端打包静态资源命令
npm run build:prod

img_1.png
img_2.png

启动成功

img_5.png

遇到的问题及bug

登录后发现若依 vue 版菜单点不开,报错:Error: Cannot find module ‘@/views/system/user/index’

F12 一看控制台一顿输出:

1
2
3
4
Error: Cannot find module '@/views/system/user/index'
at webpackEmptyContext (index.js:39)
at permission.js:73

找到代码里,对应的是 src/store/modules/permission.js
img_3.png

1
return () => import(`@/views/${view}`)

了解到是 webpack 版本问题,webpack4 不支持变量方式的动态 import ,新版本的使用 require() 来解决此问题。
解决方法
打开 src/store/modules/permission.js 文件,将加载方式修改成:

1
return (resolve) => require([`@/views/${view}`], resolve)

img_4.png

linux部署

idea打包

前端打包

1
npm run build:prod

后端打包

直接使用idea继承的maven工具点击打包
如下图例标记了打包输出的路径
img_6.png

idea直接部署到linux主机

使用idea自带的配置sftp部署上传
img_7.png
配置好sftp本地路径与目的路径
img_8.png
点击上传(记得点击一下项目文件路径)
img_9.png

nginx配置

使用docker启动nginx,并配置好相关配置.
(我多预留了几个端口,自己按照自己实际使用配置)
docker-compose配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
nginx:
container_name: nginx_n
image: nginx:1.23.2-alpine
restart: always
ports:
- 10080:10080
- 10081:10081
- 10082:10082
- 80:20080
environment:
- NGINX_PORT=10080
volumes:
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
- /data/app/nginx:/etc/nginx:rw
- /data/app:/data/app:rw
mem_limit: 256m

nginx的http中server结构体,参考配置如下

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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
[root@lqz-test-demo conf.d]# pwd
/data/app/nginx/conf.d
[root@lqz-test-demo conf.d]# cat http-ruoyi-20080.conf
server {
listen 20080;
listen [::]:20080;
server_name 192.168.16.130;

#access_log /var/log/nginx/host.access.log main;

#location / {
# root /etc/data/Myblog/test/;
# index index.html index.htm;
#}


location / {
root /data/app/ruoyi/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://172.18.0.1:8080/;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy the PHP scripts to Apache listening on 127.0.0.1:80
#
#location ~ \.php$ {
# proxy_pass http://127.0.0.1;
#}

# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
#
#location ~ \.php$ {
# root html;
# fastcgi_pass 127.0.0.1:9000;
# fastcgi_index index.php;
# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
# include fastcgi_params;
#}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
#location ~ /\.ht {
# deny all;
#}
}

docker 网段确认

容器内的IP可以通过如下命令查询

1
2
3
4
5
6
7
[root@lqz-test-demo conf.d]# docker network ls
NETWORK ID NAME DRIVER SCOPE
0142eb3a509d bridge bridge local
d79008557e79 host host local
76fd6de54ac1 kafka_default bridge local
ea58da0d6efa none null local
[root@lqz-test-demo conf.d]#
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
[root@lqz-test-demo conf.d]# docker network inspect kafka_default
[
{
"Name": "kafka_default",
"Id": "76fd6de54ac185847797d3cc3c3ce86b4673827f12d3f3a443f9f793749991c7",
"Created": "2023-12-24T14:30:36.340971645+08:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.18.0.0/16",
"Gateway": "172.18.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"2bb1f6bac1dea12c35d811aab979a252a4dcb6fccca8fb02b211f88c8718aab1": {
"Name": "kafka-kafka-1",
"EndpointID": "642bd94768ce86dd0bd8c53f5a176aa7dd2ad6932aca415057f7756653ef64b5",
"MacAddress": "02:42:ac:12:00:04",
"IPv4Address": "172.18.0.4/16",
"IPv6Address": ""
},
"312b63ec939d32f532cc9dc055f5c13a2b1d6abbefceee68ccde19f736fce3af": {
"Name": "kafka-zookeeper-1",
"EndpointID": "56865fb3fb7b2ddae17836fe4ce1504c412845f29337692cb1df01b17878ef95",
"MacAddress": "02:42:ac:12:00:02",
"IPv4Address": "172.18.0.2/16",
"IPv6Address": ""
},
"6afc6c97c4f4c50afd15775ef79b3c6ad1f695ab78906f915becbfbed8b61994": {
"Name": "nginx_n",
"EndpointID": "f917a944cd0dbceadb10bf5d8c2fc20f32a9c71434c59b508cb3321b68075bdc",
"MacAddress": "02:42:ac:12:00:05",
"IPv4Address": "172.18.0.5/16",
"IPv6Address": ""
},
"8799eca0931022a350f18d2b9be58b36d4e971d37e3357aeb857efb262f39549": {
"Name": "redis_n",
"EndpointID": "2f25831a62112fc225ceaa9f65fd72be48e427490bcfebbe43883c45e0723300",
"MacAddress": "02:42:ac:12:00:03",
"IPv4Address": "172.18.0.3/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "default",
"com.docker.compose.project": "kafka",
"com.docker.compose.version": "2.17.2"
}
}
]

前端部署后测试

除了验证码不显示外网页可以正常显示
img_10.png

后端启动

1
java -jar ruoyi.jar

img_13.png

此时再查看页面,验证码已经正常显示
img_14.png

启动时有报错

img_11.png
需要修改log目录再重新打包上传即可
img_12.png

登录测试成功

至此部署已经完成