所有环境皆关闭防火墙与selinux
| 服务器功能 | 主机IP | 主机名 | 服务名称 | 配置 |
|---|---|---|---|---|
| 前端服务器 | 192.168.231.177 | nginx | nginx | 1C2G |
| 后端服务器+代码打包 | 192.168.231.178 | java | java、maven、nodejs | 4C8G |
| 数据库/缓存 | 192.168.231.179 | db | mysql、redis | 2C4G |
- #配置Nginxyum源
- [root@nginx ~]# cat /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 install -y nginx
- # 上传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
- [root@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)
- # 配置mysql yum源
- # 安装mysql
- [root@db ~]# yum install -y mysql-server
- [root@db ~]# systemctl start mysqld
- [root@db ~]# systemctl enable mysqld
-
- 过滤MySQL初始密码,必须启动MySQL,才能过滤出来
- [root@db ~]# grep "password" /var/log/mysqld.log
- 2023-11-03T19:44:26.450149Z 1 [Note] A temporary password is generated for root@localhost: rb894yRh(NUG
-
- 修改mysql密码
- [root@db ~]# mysqladmin -uroot -p'rb894yRh(NUG' password 'QianFeng@123!'
- [root@db ~]# mysql -uroot -p'QianFeng@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.42 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> create database ruoyi character set utf8 collate utf8_general_ci;
- Query OK, 1 row affected (0.00 sec)
-
- #授权root用户远程登录
- mysql> grant all on *.* to 'root'@'%' identified by 'QianFeng@123!';
- Query OK, 0 rows affected, 1 warning (0.00 sec)
-
- #刷新权限
- mysql> flush privileges;
- Query OK, 0 rows affected (0.00 sec)
-
- mysql> \q
- Bye
- [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 ~]# mv /usr/local/redis-4.0.9/ /usr/local/redis
-
- 安装编译工具gcc make
- [root@db ~]# yum install -y gcc make
- [root@db ~]# cd /usr/local/redis/
- [root@db redis]# make
-
- 修改redis的配置文件,
- [root@db redis]# cat redis.conf
- bind 192.168.231.179
- port 6379
- daemonize yes
- [root@db redis]# ./src/redis-server redis.conf &
- [root@db redis]# ss -tlanp |grep redis
- LISTEN 0 128 192.168.231.179:6379 *:* users:(("redis-server",pid=4938,fd=6))
- [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
-
- 获得RuoYi-Vue
- [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.231.179
- # 端口,默认为6379
- port: 6379
- # 数据库索引
- database: 0
- # 密码
- password:
- # 连接超时时间
- timeout: 10s
- lettuce:
-
- [root@java RuoYi-Vue]# vim ruoyi-admin/src/main/resources/application-druid.yml
- ### 修改数据库url,修改数据库密码
- # 数据源配置
- spring:
- datasource:
- type: com.alibaba.druid.pool.DruidDataSource
- driverClassName: com.mysql.cj.jdbc.Driver
- druid:
- # 主库数据源
- master:
- url: jdbc:mysql://192.168.231.179:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
- username: root
- password: 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/ 192.168.231.177:/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
- upstream rs {
- server 192.168.231.178:8080;
- }
- 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 * 192.168.231.179:/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
- Application Version: 3.8.6
- Spring Boot Version: 2.5.15
-
- // _ooOoo_ //
- // o8888888o //
- // 88" . "88 //
- // (| ^_^ |) //
- // O\ = /O //
- // ____/`---'\____ //
- // .' \\| |// `. //
- // / \\||| : |||// \ //
- // / _||||| -:- |||||- \ //
- // | | \\\ - /// | | //
- // | \_| ''\---/'' | | //
- // \ .-\__ `-` ___/-. / //
- // ___`. .' /--.--\ `. . ___ //
- // ."" '< `.___\_<|>_/___.' >'"". //
- // | | : `- \`.;`\ _ /`;.`/ - ` : | | //
- // \ \ `-. \_ __\ /__ _/ .-` / / //
- // ========`-.____`-.___\_____/___.-`____.-'======== //
- // `=---=' //
- // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
- // 佛祖保佑 永不宕机 永无BUG //
-
- 05:15:09.581 [background-preinit] INFO o.h.v.i.util.Version - [<clinit>,21] - HV000001: Hibernate Validator 6.2.5.Final
- 05:15:09.633 [main] INFO c.r.RuoYiApplication - [logStarting,55] - Starting RuoYiApplication using Java 1.8.0_211 on db with PID 15389 (/opt/RuoYi-Vue/ruoyi-admin/target/ruoyi-admin.jar started by root in /opt/RuoYi-Vue/ruoyi-admin/target)
- 05:15:09.634 [main] DEBUG c.r.RuoYiApplication - [logStarting,56] - Running with Spring Boot v2.5.15, Spring v5.3.27
- 05:15:09.634 [main] INFO c.r.RuoYiApplication - [logStartupProfileInfo,686] - The following 1 profile is active: "druid"
- 05:15:11.945 [main] INFO o.a.c.h.Http11NioProtocol - [log,173] - Initializing ProtocolHandler ["http-nio-8080"]
- 05:15:11.945 [main] INFO o.a.c.c.StandardService - [log,173] - Starting service [Tomcat]
- 05:15:11.946 [main] INFO o.a.c.c.StandardEngine - [log,173] - Starting Servlet engine: [Apache Tomcat/9.0.75]
- 05:15:12.035 [main] INFO o.a.c.c.C.[.[.[/] - [log,173] - Initializing Spring embedded WebApplicationContext
- 05:15:12.514 [main] DEBUG c.r.f.s.f.JwtAuthenticationTokenFilter - [init,242] - Filter 'jwtAuthenticationTokenFilter' configured for use
- 05:15:13.856 [main] INFO c.a.d.p.DruidDataSource - [init,996] - {dataSource-1} inited
- 05:15:13.862 [main] DEBUG c.r.s.m.S.selectDictDataList - [debug,137] - ==> Preparing: select dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, create_time, remark from sys_dict_data WHERE status = ? order by dict_sort asc
- 05:15:13.880 [main] DEBUG c.r.s.m.S.selectDictDataList - [debug,137] - ==> Parameters: 0(String)
- 05:15:13.903 [main] DEBUG c.r.s.m.S.selectDictDataList - [debug,137] - <== Total: 29
- 05:15:14.462 [main] DEBUG c.r.s.m.S.selectConfigList - [debug,137] - ==> Preparing: select config_id, config_name, config_key, config_value, config_type, create_by, create_time, update_by, update_time, remark from sys_config
- 05:15:14.463 [main] DEBUG c.r.s.m.S.selectConfigList - [debug,137] - ==> Parameters:
- 05:15:14.465 [main] DEBUG c.r.s.m.S.selectConfigList - [debug,137] - <== Total: 6
- 05:15:14.873 [main] INFO o.q.i.StdSchedulerFactory - [instantiate,1220] - Using default implementation for ThreadExecutor
- 05:15:14.885 [main] INFO o.q.c.SchedulerSignalerImpl - [<init>,61] - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
- 05:15:14.885 [main] INFO o.q.c.QuartzScheduler - [<init>,229] - Quartz Scheduler v.2.3.2 created.
- 05:15:14.886 [main] INFO o.q.s.RAMJobStore - [initialize,155] - RAMJobStore initialized.
- 05:15:14.887 [main] INFO o.q.c.QuartzScheduler - [initialize,294] - Scheduler meta-data: Quartz Scheduler (v2.3.2) 'quartzScheduler' with instanceId 'NON_CLUSTERED'
- Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.
- NOT STARTED.
- Currently in standby mode.
- Number of jobs executed: 0
- Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.
- Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.
-
- 05:15:14.887 [main] INFO o.q.i.StdSchedulerFactory - [instantiate,1374] - Quartz scheduler 'quartzScheduler' initialized from an externally provided properties instance.
- 05:15:14.887 [main] INFO o.q.i.StdSchedulerFactory - [instantiate,1378] - Quartz scheduler version: 2.3.2
- 05:15:14.887 [main] INFO o.q.c.QuartzScheduler - [setJobFactory,2293] - JobFactory set to: org.springframework.scheduling.quartz.SpringBeanJobFactory@649725e3
- 05:15:14.906 [main] DEBUG c.r.q.m.S.selectJobAll - [debug,137] - ==> Preparing: select job_id, job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, remark from sys_job
- 05:15:14.906 [main] DEBUG c.r.q.m.S.selectJobAll - [debug,137] - ==> Parameters:
- 05:15:14.908 [main] DEBUG c.r.q.m.S.selectJobAll - [debug,137] - <== Total: 3
- 05:15:16.124 [main] INFO o.a.c.h.Http11NioProtocol - [log,173] - Starting ProtocolHandler ["http-nio-8080"]
- 05:15:16.511 [main] INFO o.q.c.QuartzScheduler - [start,547] - Scheduler quartzScheduler_$_NON_CLUSTERED started.
- 05:15:16.521 [main] INFO c.r.RuoYiApplication - [logStarted,61] - Started RuoYiApplication in 7.487 seconds (JVM running for 7.935)
- (♥◠‿◠)ノ゙ 若依启动成功 ლ(´ڡ`ლ)゙
- .-------. ____ __
- | _ _ \ \ \ / /
- | ( ' ) | \ _. / '
- |(_ o _) / _( )_ .'
- | (_,_).' __ ___(_ o _)'
- | |\ \ | || |(_,_)'
- | | \ `' /| `-' /
- | | \ / \ /
- ''-' `'-' `-..-'
结尾出现若依启动成功,则证明后端服务成功上线
[root@java target]# nohup java -jar -server -Xmx1024m -Xms1024m ruoyi-admin.jar &

## 如果报错链接不上数据库,且数据库配置无问题,将RuoYi-Vue/ruoyi-admin/src/main/resources/application-druid.yml文件中,
master:
url: jdbc:mysql://192.168.231.179:3306/ruoyi?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8
将url中useSSL=yes改成useSSL=false,然后重新打包上线在JDBC连接MySQL数据库时,useSSL参数用于指定是否使用SSL(安全套接层)加密连接。SSL是一种用于在计算机网络上提供安全通信的协议,它可以确保在客户端和服务器之间传输的数据在传输过程中是加密的,从而提供了一定程度的安全性。
当useSSL参数设置为false时,表示不使用SSL加密连接。这通常在开发和测试环境中比较常见,因为在这些环境下,对数据传输的安全性要求可能较低,而且SSL加密会增加一些额外的性能开销。在这种情况下,如果数据库服务器不要求强制的SSL连接,你可以将useSSL参数设置为false来简化连接配置。
但是,在生产环境中,特别是涉及到敏感数据的应用,强烈建议使用SSL加密来保护数据的传输安全性。在生产环境中,通常会将useSSL参数设置为true,以确保数据库连接是安全的。
在你的连接字符串中,useSSL=false表示不使用SSL加密连接。如果你的数据库服务器要求SSL连接,那么你需要将useSSL参数设置为true,以便建立加密连接。
nohup命令:nohup 是 no hang up 的缩写,就是不挂断的意思,但没有后台运行,终端不能标准输入。
nohup :不挂断的运行,注意并没有后台运行的功能,就是指,用nohup运行命令可以使命令永久的执行下去,和用户终端没有关系,例如我们断开SSH连接都不会影响他的运行,注意了nohup没有后台运行的意思;&才是后台运行在缺省情况下该作业的所有输出都被重定向到一个名为nohup.out的文件中。
nohup和&的区别
&:指在后台运行
&是指在后台运行,但当用户推出(挂起)的时候,命令自动也跟着退出&的意思是在后台运行, 什么意思呢? 意思是说, 当你在执行 ./start.sh & 的时候, 即使你用ctrl+C, 那么start.sh照样运行(因为对SIGINT(程序终止信号,一般有ctrl+C发出)信号免疫)。 但是要注意, 如果你直接关掉shell后, 那么,start.sh进程同样消失。 可见, &的后台并不硬(因为对SIGHUP(用户终端连接(正常或非正常)结束时发出)信号不免疫)。
nohup的意思是忽略SIGHUP信号, 所以当运行nohup ./start.sh的时候, 关闭shell, 那么start.sh进程还是存在的(对SIGHUP信号免疫)。 但是, 要注意, 如果你直接在shell中用Ctrl+C, 那么start.sh进程也是会消失的(因为对SIGINT信号不免疫)
所以, &和nohup没有半毛钱的关系, 要让进程真正不受shell中Ctrl+C和shell关闭的影响, 那该怎么办呢? 那么,我们可以巧妙的将他们结合起来用就是
nohup COMMAND > /dev/null &
这样就能使命令永久的在后台执行两全其美。