本文主要是介绍ruo-yi项目部署 前后端分离,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
- nginx服务器部署
- java服务器部署
- db服务器部署
- 配置打包环境
- 配置前端打包环境(java服务器)
- 配置后端打包环境
- 获取代码
- 前端代码打包
- 后端代码打包
- 项目上线
- 前端项目上线
- 后端项目上线
- 将jar包传送到后端服务器
- 导入初始化数据
ip | 主机名 | 服务名称 |
---|---|---|
192.168.20.138 | nginx | nginx |
192.168.20.141 | java | java、maven、nodejs |
192.168.20.135 | db | mysql、redis |
nginx服务器部署
[root@nginx ~]# yum -y install wget vim
#配置nginx的yum源
[root@nginx ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true[nginx-mainline]
name=nginx mainline repo
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true#下载nginx
[root@nginx ~]# yum -y install nginx
java服务器部署
#上传java包
#安装java环境
[root@java ~]# tar -xf jdk-8u211-linux-x64.tar.gz -C /usr/local/
[root@java ~]# mv /usr/local/jdk1.8.0_211/ /usr/local/java#配置环境变量
vim /etc/profile.d/java.sh
JAVA_HOME=/usr/local/java
PATH=$PATH:$JAVA_HOME/bin
#重新加载环境变量
[root@java ~]# source /etc/profile.d/java.sh
#查看java是否配置成功
[root@java ~]# java -version
java version "1.8.0_211"
Java(TM) SE Runtime Environment (build 1.8.0_211-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.211-b12, mixed mode)
db服务器部署
#配置mysqlyum源
[root@db ~]# yum install -y https://dev.mysql.com/get/mysql80-community-release-el7-7.noarch.rpm
#把安装5.7的源打开, 关闭安装8.0的源
[root@db ~]# vim /etc/yum.repos.d/mysql-community.repo
#启动mysql
[root@db ~]# systemctl start mysqld
#修改MySQL密码
[root@db ~]# grep pass /var/log/mysqld.log
2023-11-04T02:22:37.670939Z 1 [Note] A temporary password is generated for root@localhost: ?FoEgX.ue3Od
mysqladmin -uroot -p'?FoEgX.ue3Od' password 'Qianfeng@123'#登录mysql
[root@db ~]# mysql -pQianfeng@123
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 3
Server version: 5.7.44 MySQL Community Server (GPL)Copyright (c) 2000, 2023, 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>
#创建数据库
mysql> create database ruoyi character set utf8 collate utf8_general_ci;
#开启远程登录
mysql> update mysql.user set host = '%' where user = 'root';
#刷新授权
mysql> flush privileges;
mysql> \q
Bye
安装redis
[root@db ~]# wget http://download.redis.io/releases/redis-4.0.9.tar.gz
[root@db ~]# tar -xf redis-4.0.9.tar.gz -C /usr/local/
[root@db ~]# yum install -y gcc make
[root@db ~]# mv /usr/local/redis-4.0.9/ /usr/local/redis
[root@db ~]# yum install -y gcc make
[root@db ~]# cd /usr/local/redis/
[root@db redis]# make[root@db redis]# vim redis.conf
bind 192.168.20.135
port 6379
daemonize yes[root@db redis]# ./src/redis-server redis.conf &
[root@db redis]# ss -tlanp |grep redis
LISTEN 0 128 10.36.192.253:6379 *:* users:(("redis-server",pid=4938,fd=6))
配置打包环境
配置前端打包环境(java服务器)
[root@java ~]# wget https://nodejs.org/dist/v12.18.4/node-v12.18.4-linux-x64.tar.xz
[root@java ~]# tar -xf node-v12.18.4-linux-x64.tar.xz -C /usr/local/
[root@java ~]# mv /usr/local/node-v12.18.4-linux-x64/ /usr/local/node
[root@java ~]# vim /etc/profile.d/node.sh
NODE_HOME=/usr/local/node
PATH=$PATH:$NODE_HOME/bin
[root@java ~]# source /etc/profile.d/node.sh
[root@java ~]# node -v
v12.18.4
配置后端打包环境
[root@java ~]# wget https://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.9.5/binaries/apache-maven-3.9.5-bin.tar.gz --no-check-certificate
[root@java ~]# tar -xf apache-maven-3.9.5-bin.tar.gz -C /usr/local/
[root@java ~]# mv /usr/local/apache-maven-3.9.5/ /usr/local/maven
[root@java ~]# vim /etc/profile.d/mvn.sh
MAVEN_HOME=/usr/local/maven
PATH=$PATH:$MAVEN_HOME/bin
[root@java ~]# source /etc/profile.d/mvn.sh
[root@java ~]# mvn -version
Apache Maven 3.9.5 (57804ffe001d7215b5e7bcb531cf83df38f93546)
Maven home: /usr/local/maven
Java version: 1.8.0_211, vendor: Oracle Corporation, runtime: /usr/local/java/jre
Default locale: zh_CN, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-1160.el7.x86_64", arch: "amd64", family: "unix"
获取代码
[root@java ~]# yum install -y git
[root@java ~]# git clone https://gitee.com/y_project/RuoYi-Vue.git
[root@java ~]# ls
anaconda-ks.cfg node-v12.18.4-linux-x64.tar.xz
apache-maven-3.9.5-bin.tar.gz RuoYi-Vue
jdk-8u211-linux-x64.tar.gz
前端代码打包
[root@java ~]# cd RuoYi-Vue/ruoyi-ui
#替换为国内的taobaoyuan
[root@java ruoyi-ui]# npm install --unsafe-perm --registry=https://registry.npm.taobao.org
[root@java ruoyi-ui]# npm run build:prod构建打包成功之后,会在根目录生成 dist 文件夹,里面就是构建打包好的文件,通常是 xxx.js 、xxx.css、index.html 等静态文件。通常情况下 dist 文件夹的静态文件发布到你的 nginx 或者静态服务器即可,其中的 index.html 是后台服务的入口页面。
[root@java ruoyi-ui]# ls
babel.config.js dist package-lock.json src
bin node_modules public vue.config.js
build package.json README.md
[root@java ruoyi-ui]# cd dist/
[root@java dist]# ls
favicon.ico html index.html index.html.gz robots.txt static
#将静态资源移动到其他位置,然后进行后端代码打包
[root@java dist]# cd /root/RuoYi-Vue
[root@java RuoYi-Vue]# mv ruoyi-ui/ /opt/
后端代码打包
[root@java ~]# cd RuoYi-Vue/
[root@java RuoYi-Vue]# vim ruoyi-admin/src/main/resources/application.yml
# 修改redis配置信息redis:# 地址host: 192.168.20.141# 端口,默认为6379port: 6379# 数据库索引database: 0# 密码password:# 连接超时时间timeout: 10slettuce:[root@java RuoYi-Vue]# vim ruoyi-admin/src/main/resources/application-druid.yml
### 修改数据库url,修改数据库密码
# 数据源配置
spring:datasource:type: com.alibaba.druid.pool.DruidDataSourcedriverClassName: com.mysql.cj.jdbc.Driverdruid:# 主库数据源master:url: jdbc:mysql://192.168.20.141:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8username: rootpassword: Qianfeng@123# 开始进行后端打包
[root@java RuoYi-Vue]# mvn package
…………
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 04:35 min
[INFO] Finished at: 2023-11-03T20:18:20+08:00
[INFO] ------------------------------------------------------------------------
[root@java RuoYi-Vue]# ls ruoyi-admin/target/
classes maven-archiver ruoyi-admin.jar
generated-sources maven-status ruoyi-admin.jar.original#把ruoyi-admin.jar 放在后端服务器运行
项目上线
前端项目上线
# 拷贝前端资源到前端服务器
[root@java ~]# cd /opt
[root@java opt]# scp -r ruoyi-ui/ 10.36.192.251:/opt/#前端项目上线
[root@nginx ~]# rm -rf /usr/share/nginx/html/*
[root@nginx ~]# cp -r /opt/ruoyi-ui/dist/* /usr/share/nginx/html/
[root@nginx ~]# ls /usr/share/nginx/html/
favicon.ico html index.html index.html.gz robots.txt static[root@nginx ~]# vim /etc/nginx/conf.d/default.conf
server {listen 80;server_name localhost;access_log /var/log/nginx/host.access.log main;location / {root /usr/share/nginx/html;try_files $uri $uri/ /index.html;index index.html index.htm;}location /prod-api/ {proxy_pass http://rs/;proxy_set_header Host $http_host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;}}[root@nginx ~]# systemctl restart nginx#前端上线完成,但是由于后端还未上线,所以有报错,并且验证码无法显示
后端项目上线
将jar包传送到后端服务器
[root@java opt]# cp ~/RuoYi-Vue/ruoyi-admin/target/ruoyi-admin.jar /java/#导入初始化数据,首先将初始化数据传到数据库服务器
[root@java ~]# cd /root/RuoYi-Vue/sql
[root@java sql]# ls
quartz.sql ry_20230706.sql
[root@java sql]# scp * 10.36.192.253:/opt/
导入初始化数据
[root@db redis]# mysql -uroot -p'QianFeng@123!' ruoyi < /opt/quartz.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@db redis]# mysql -uroot -p'QianFeng@123!' ruoyi < /opt/ry_20230706.sql
mysql: [Warning] Using a password on the command line interface can be insecure.#开始测试上线后端服务
[root@java target]# java -jar -server -Xmx1024m -Xms1024m ruoyi-admin.jar(♥◠‿◠)ノ゙ 若依启动成功 ლ(´ڡ`ლ)゙.-------. ____ __| _ _ \ \ \ / /| ( ' ) | \ _. / '|(_ o _) / _( )_ .'| (_,_).' __ ___(_ o _)'| |\ \ | || |(_,_)'| | \ `' /| `-' /| | \ / \ /''-' `'-' `-..-'## 开始正式上线
[root@java target]# nohup java -jar -server -Xmx1024m -Xms1024m ruoyi-admin.jar &
这篇关于ruo-yi项目部署 前后端分离的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!