Ruoyi AI 部署指南:从环境搭建到项目运行

在当今数字化时代,人工智能技术正逐步融入各类应用开发中。Ruoyi AI 作为一个开源项目,为开发者提供了一个便捷的平台,用于快速搭建具备人工智能功能的系统。本文将详细介绍如何从头开始部署 Ruoyi AI 项目,涵盖环境搭建、后端与前端项目安装、配置以及运行的全过程。

一、项目概述

Ruoyi AI 是一个基于 Spring Boot 的后端项目,结合了前端管理端和用户端,支持多种人工智能功能。它通过集成外部 AI 服务(如 PandaRobot)来实现智能交互。其架构清晰,易于扩展,适合用于快速开发具备 AI 功能的管理系统或用户交互平台。

二、环境准备

在开始部署 Ruoyi AI 之前,需要确保你的开发环境满足以下要求:

1. Java 开发环境

2. 数据库

  • MySQL:支持 MySQL 5.7 或 8.0。我使用的是 MySQL 8.0。你可以从 MySQL 官网 下载安装。

  • mysqld --console

3. 缓存系统

  • Redis:版本必须 >= 5.X。你可以从 Redis 官方 GitHub 下载适合你操作系统的版本。

4. 构建工具

  • Maven:版本需为 3.8+。我使用的是 Maven 3.9.4。你可以从 Maven 官网 下载安装。

5. 前端工具

  • Node.js:版本需为 20+。同时需要安装 pnpm 作为包管理工具。你可以从 Node.js 官网 下载安装。

三、后端项目部署

后端项目是 Ruoyi AI 的核心,它提供了与数据库交互、业务逻辑处理以及与前端通信的功能。

1. 下载项目

你可以从以下地址下载 Ruoyi AI 后端项目:

2. 导入项目

使用 IntelliJ IDEA 打开项目。在导入过程中,确保正确配置了 Maven 的安装路径:

  • 打开 IDEA,选择 File -> Open,选择下载的项目文件夹。

  • 在 IDEA 的左上角搜索框中输入 maven,选择 Maven 配置项,设置 Maven 安装目录。

  • 配置maven 文件 - 设置 - 左上角搜索框输入maven - 选择maven安装目录

  • xml配置

  • <?xml version="1.0" encoding="UTF-8"?>
    <settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
      <localRepository>D:/dev/apache-maven-3.9.9/repository</localRepository>
      <mirrors>
     <mirror>
       <id>aliyunmaven</id>
       <mirrorOf>*</mirrorOf>
       <name>阿里云公共仓库</name>
       <url>https://maven.aliyun.com/repository/public</url>
     </mirror>
      </mirrors>
      <profiles>
     <profile>
      <id>jdk-17</id>
      <activation>
       <activeByDefault>true</activeByDefault>
       <jdk>17</jdk>
      </activation>
      <properties>
       <maven.compiler.source>17</maven.compiler.source>
       <maven.compiler.target>17</maven.compiler.target>
       <maven.compiler.compilerVersion>17</maven.compiler.compilerVersion>
      </properties>
         </profile>
      </profiles>
    </settings>

我的maven的settings.xml

  • <?xml version="1.0" encoding="UTF-8"?>
    
    <!--
    Licensed to the Apache Software Foundation (ASF) under one
    or more contributor license agreements.  See the NOTICE file
    distributed with this work for additional information
    regarding copyright ownership.  The ASF licenses this file
    to you under the Apache License, Version 2.0 (the
    "License"); you may not use this file except in compliance
    with the License.  You may obtain a copy of the License at
    
        http://www.apache.org/licenses/LICENSE-2.0
    
    Unless required by applicable law or agreed to in writing,
    software distributed under the License is distributed on an
    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    KIND, either express or implied.  See the License for the
    specific language governing permissions and limitations
    under the License.
    -->
    
    <!--
     | This is the configuration file for Maven. It can be specified at two levels:
     |
     |  1. User Level. This settings.xml file provides configuration for a single user,
     |                 and is normally provided in ${user.home}/.m2/settings.xml.
     |
     |                 NOTE: This location can be overridden with the CLI option:
     |
     |                 -s /path/to/user/settings.xml
     |
     |  2. Global Level. This settings.xml file provides configuration for all Maven
     |                 users on a machine (assuming they're all using the same Maven
     |                 installation). It's normally provided in
     |                 ${maven.conf}/settings.xml.
     |
     |                 NOTE: This location can be overridden with the CLI option:
     |
     |                 -gs /path/to/global/settings.xml
     |
     | The sections in this sample file are intended to give you a running start at
     | getting the most out of your Maven installation. Where appropriate, the default
     | values (values used when the setting is not specified) are provided.
     |
     |-->
    <settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 https://maven.apache.org/xsd/settings-1.2.0.xsd">
      <!-- localRepository
       | The path to the local repository maven will use to store artifacts.
       |
       | Default: ${user.home}/.m2/repository
      <localRepository>/path/to/local/repo</localRepository>
      -->
    
      <!-- interactiveMode
       | This will determine whether maven prompts you when it needs input. If set to false,
       | maven will use a sensible default value, perhaps based on some other setting, for
       | the parameter in question.
       |
       | Default: true
      <interactiveMode>true</interactiveMode>
      -->
    
      <!-- offline
       | Determines whether maven should attempt to connect to the network when executing a build.
       | This will have an effect on artifact downloads, artifact deployment, and others.
       |
       | Default: false
      <offline>false</offline>
      -->
    
      <!-- pluginGroups
       | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
       | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
       | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
       |-->
      <pluginGroups>
        <!-- pluginGroup
         | Specifies a further group identifier to use for plugin lookup.
        <pluginGroup>com.your.plugins</pluginGroup>
        -->
      </pluginGroups>
    
      <!-- TODO Since when can proxies be selected as depicted? -->
      <!-- proxies
       | This is a list of proxies which can be used on this machine to connect to the network.
       | Unless otherwise specified (by system property or command-line switch), the first proxy
       | specification in this list marked as active will be used.
       |-->
      <proxies>
        <!-- proxy
         | Specification for one proxy, to be used in connecting to the network.
         |
        <proxy>
          <id>optional</id>
          <active>true</active>
          <protocol>http</protocol>
          <username>proxyuser</username>
          <password>proxypass</password>
          <host>proxy.host.net</host>
          <port>80</port>
          <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
        </proxy>
        -->
      </proxies>
    
      <!-- servers
       | This is a list of authentication profiles, keyed by the server-id used within the system.
       | Authentication profiles can be used whenever maven must make a connection to a remote server.
       |-->
      <servers>
        <!-- server
         | Specifies the authentication information to use when connecting to a particular server, identified by
         | a unique name within the system (referred to by the 'id' attribute below).
         |
         | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
         |       used together.
         |
        <server>
          <id>deploymentRepo</id>
          <username>repouser</username>
          <password>repopwd</password>
        </server>
        -->
    
        <!-- Another sample, using keys to authenticate.
        <server>
          <id>siteServer</id>
          <privateKey>/path/to/private/key</privateKey>
          <passphrase>optional; leave empty if not used.</passphrase>
        </server>
        -->
      </servers>
    
      <!-- mirrors
       | This is a list of mirrors to be used in downloading artifacts from remote repositories.
       |
       | It works like this: a POM may declare a repository to use in resolving certain artifacts.
       | However, this repository may have problems with heavy traffic at times, so people have mirrored
       | it to several places.
       |
       | That repository definition will have a unique id, so we can create a mirror reference for that
       | repository, to be used as an alternate download site. The mirror site will be the preferred
       | server for that repository.
       |-->
      <mirrors>
        <!-- mirror
         | Specifies a repository mirror site to use instead of a given repository. The repository that
         | this mirror serves has an ID that matches the mirrorOf element of this mirror. IDs are used
         | for inheritance and direct lookup purposes, and must be unique across the set of mirrors.
         |
        <mirror>
          <id>mirrorId</id>
          <mirrorOf>repositoryId</mirrorOf>
          <name>Human Readable Name for this Mirror.</name>
          <url>http://my.repository.com/repo/path</url>
        </mirror>
     
        <mirror>
          <id>maven-default-http-blocker</id>
          <mirrorOf>external:http:*</mirrorOf>
          <name>Pseudo repository to mirror external repositories initially using HTTP.</name>
          <url>http://0.0.0.0/</url>
          <blocked>true</blocked>
        </mirror>
    <mirror>
    <id>nexus-aliyun</id>
    <mirrorOf>*,!jeecg,!jeecg-snapshots,!getui-nexus</mirrorOf>
    <name>Nexus aliyun</name>
    <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
        -->
        <mirror>
          <id>maven-default-http-blocker</id>
          <mirrorOf>external:http:*</mirrorOf>
          <name>Pseudo repository to mirror external repositories initially using HTTP.</name>
          <url>http://0.0.0.0/</url>
          <blocked>true</blocked>
        </mirror>
     <mirror>
       <id>aliyunmaven</id>
       <mirrorOf>*</mirrorOf>
       <name>阿里云公共仓库</name>
       <url>https://maven.aliyun.com/repository/public</url>
     </mirror>
      </mirrors>
    
      <!-- profiles
       | This is a list of profiles which can be activated in a variety of ways, and which can modify
       | the build process. Profiles provided in the settings.xml are intended to provide local machine-
       | specific paths and repository locations which allow the build to work in the local environment.
       |
       | For example, if you have an integration testing plugin - like cactus - that needs to know where
       | your Tomcat instance is installed, you can provide a variable here such that the variable is
       | dereferenced during the build process to configure the cactus plugin.
       |
       | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
       | section of this document (settings.xml) - will be discussed later. Another way essentially
       | relies on the detection of a property, either matching a particular value for the property,
       | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
       | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
       | Finally, the list of active profiles can be specified directly from the command line.
       |
       | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
       |       repositories, plugin repositories, and free-form properties to be used as configuration
       |       variables for plugins in the POM.
       |
       |-->
      <profiles>
        <profile>
      <id>jdk-17</id>
      <activation>
       <activeByDefault>true</activeByDefault>
       <jdk>17</jdk>
      </activation>
     <properties>
       <maven.compiler.source>17</maven.compiler.source>
       <maven.compiler.target>17</maven.compiler.target>
       <maven.compiler.compilerVersion>17</maven.compiler.compilerVersion>
      </properties>
         </profile>
      </profiles>
        <!-- profile
         | Specifies a set of introductions to the build process, to be activated using one or more of the
         | mechanisms described above. For inheritance purposes, and to activate profiles via <activatedProfiles/>
         | or the command line, profiles have to have an ID that is unique.
         |
         | An encouraged best practice for profile identification is to use a consistent naming convention
         | for profiles, such as 'env-dev', 'env-test', 'env-production', 'user-jdcasey', 'user-brett', etc.
         | This will make it more intuitive to understand what the set of introduced profiles is attempting
         | to accomplish, particularly when you only have a list of profile id's for debug.
         |
         | This profile example uses the JDK version to trigger activation, and provides a JDK-specific repo.
        <profile>
          <id>jdk-1.4</id>
    
          <activation>
            <jdk>1.4</jdk>
          </activation>
    
          <repositories>
            <repository>
              <id>jdk14</id>
              <name>Repository for JDK 1.4 builds</name>
              <url>http://www.myhost.com/maven/jdk14</url>
              <layout>default</layout>
              <snapshotPolicy>always</snapshotPolicy>
            </repository>
          </repositories>
        </profile>
        -->
    
        <!--
         | Here is another profile, activated by the property 'target-env' with a value of 'dev', which
         | provides a specific path to the Tomcat instance. To use this, your plugin configuration might
         | hypothetically look like:
         |
         | ...
         | <plugin>
         |   <groupId>org.myco.myplugins</groupId>
         |   <artifactId>myplugin</artifactId>
         |
         |   <configuration>
         |     <tomcatLocation>${tomcatPath}</tomcatLocation>
         |   </configuration>
         | </plugin>
         | ...
         |
         | NOTE: If you just wanted to inject this configuration whenever someone set 'target-env' to
         |       anything, you could just leave off the <value/> inside the activation-property.
         |
        <profile>
          <id>env-dev</id>
    
          <activation>
            <property>
              <name>target-env</name>
              <value>dev</value>
            </property>
          </activation>
    
          <properties>
            <tomcatPath>/path/to/tomcat/instance</tomcatPath>
          </properties>
        </profile>
        -->
      </profiles>
    
      <!-- activeProfiles
       | List of profiles that are active for all builds.
       |
      <activeProfiles>
        <activeProfile>alwaysActiveProfile</activeProfile>
        <activeProfile>anotherAlwaysActiveProfile</activeProfile>
      </activeProfiles>
      -->
    </settings>
    
  • 多个jdk版本的话,需要把jdk17放最前面,否则可能无法识别

  • 初始化数据库

修改数据库配置为你自己的本地环境,包括redis

安装jdk17后没有jre

bin\jlink.exe --module-path jmods --add-modules java.desktop --output jre

3. 配置 Maven

在项目根目录下找到 pom.xml 文件,确保其中的依赖版本与你的环境一致。如果需要修改版本,可以直接在文件中进行编辑。

4. 初始化数据库

在项目中找到数据库初始化脚本,运行该脚本以创建必要的数据库表结构。通常,这些脚本位于 src/main/resources/sql 目录下。

5. 启动 Redis

确保 Redis 已正确安装并启动。你可以通过以下命令启动 Redis:

redis下载地址:Releases · tporadowski/redis · GitHub

bash复制

redis-server.exe redis.windows.conf

6. 启动项目

在 IDEA 中运行项目主类(通常是 Application 类)。如果一切配置正确,后端项目将成功启动,并监听默认端口(通常是 8080)。

四、前端项目部署

前端项目分为管理端和用户端,分别用于后台管理和用户交互。

1. 管理端部署

2. 用户端部署

  • 其他配置:/apps/web-antd/.env.development

五、申请 API KEY

为了使用 Ruoyi AI 的智能功能,你需要申请一个 API KEY。访问 PandaRobot 官方网站 注册账号并申请 API KEY。注册成功后,点击添加令牌,参数可以全部默认,点击复制按钮获取 API KEY。

六、后台管理配置

使用默认账号 admin/admin123 登录后台管理系统。进入运营管理 -> 系统模型 -> 新增模型,在请求密钥处填写上一步申请到的 API KEY。

七、应用场景

Ruoyi AI 可以应用于多种场景,例如:

  • 智能客服系统:通过集成 AI 模型,为用户提供自动化的客服服务。

  • 内容管理系统:管理文章、图片等资源,并通过 AI 实现智能推荐。

  • 企业内部管理:用于员工考勤、任务分配等。

八、注意事项

现在,你就可以同时在VSCode的两个窗口中编辑两个不同的项目了。你可以使用标签页在两个窗口之间切换,或者使用快捷键Ctrl+`来切换窗口。

  1. 环境兼容性:确保所有工具和库的版本与项目要求一致,避免因版本不兼容导致的问题。

  2. 数据库备份:在进行数据库初始化或修改时,建议提前备份现有数据。

  3. API KEY 安全:不要将 API KEY 暴露在公共代码库中,确保其安全性。

  4. 前端性能优化:在生产环境中,建议对前端项目进行性能优化,例如压缩资源文件、使用 CDN 等。

  5. 如何在VSCode中同时打开两个项目?

  6. 在VSCode中同时打开两个项目非常简单。下面是一些步骤:

  7. 步骤一: 打开VSCode编辑器,并确保你已经成功安装了VSCode。

  8. 步骤二: 在VSCode的顶部菜单栏中,选择“文件” -> “打开文件夹”(或者使用快捷键Ctrl+K Ctrl+O)。

  9. 步骤三: 在弹出的对话框中,选择要打开的第一个项目所在的文件夹,并单击“选择文件夹”。VSCode将会打开该项目。

  10. 步骤四: 重复步骤三,选择要打开的第二个项目所在的文件夹,并单击“选择文件夹”。VSCode将会以新的窗口打开该项目。

  11. 推荐使用nvm管理node版本

  12.  nvm list available 查询可插入版本号,LST表示可插入稳定版本

    使用 nvm 管理 Node.js

    1. 安装 Node.js

    使用 nvm 安装指定版本的 Node.js:

    bash复制

    nvm install 18.17.0  # 安装 Node.js v18.17.0
    nvm install 20.5.0   # 安装 Node.js v20.5.0

    2. 列出已安装版本

    查看已安装的 Node.js 版本:

    nvm list或者nvm ls 查看当前已安装的node.js版本,带*号的是正在使用的

    nvm list

    3. 切换 Node.js 版本

    切换到指定版本的 Node.js:

    bash复制

    nvm use 18.17.0  # 切换到 Node.js v18.17.0
    nvm use 20.5.0   # 切换到 Node.js v20.5.0

    4. 设置默认版本

    设置默认使用的 Node.js 版本:

    bash复制

    nvm alias default 18.17.0  # 设置默认版本为 Node.js v18.17.0

     5. 删除某node.js版本

    nvm uninstall 22.13.1

九、总结

通过本文的介绍,你应该已经能够顺利部署 Ruoyi AI 项目。从环境搭建到后端与前端的部署,每一步都至关重要。希望 Ruoyi AI 能够为你的项目带来便捷和高效。如果你在部署过程中遇到任何问题,欢迎在评论区留言,我会尽力为你解答。


希望这篇文章对你有所帮助!如果需要进一步调整或补充,需要对应安装包的也可以请随时告诉我。