2025-01-07 14:16:42 +08:00
|
|
|
|
<!-- Space: qifu -->
|
|
|
|
|
<!-- Parent: 后端技术&知识&规范 -->
|
|
|
|
|
<!-- Parent: 技术方案 -->
|
|
|
|
|
<!-- Parent: 基建 -->
|
|
|
|
|
<!-- Title: 20250107-Yearning安装及SSO接入指南 -->
|
|
|
|
|
|
|
|
|
|
<!-- Macro: :anchor\((.*)\):
|
|
|
|
|
Template: ac:anchor
|
|
|
|
|
Anchor: ${1} -->
|
|
|
|
|
<!-- Macro: \!\[.*\]\((.+)\)\<\!\-\- width=(.*) \-\-\>
|
|
|
|
|
Template: ac:image
|
|
|
|
|
Url: ${1}
|
|
|
|
|
Width: ${2} -->
|
|
|
|
|
<!-- Macro: \<\!\-\- :toc: \-\-\>
|
|
|
|
|
Template: ac:toc
|
|
|
|
|
Printable: 'false'
|
|
|
|
|
MinLevel: 2
|
|
|
|
|
MaxLevel: 4 -->
|
|
|
|
|
<!-- Include: 杂项/声明文件.md -->
|
|
|
|
|
|
|
|
|
|
<!-- :toc: -->
|
|
|
|
|
|
|
|
|
|
# Yearning 安装及 SSO 接入指南
|
|
|
|
|
|
|
|
|
|
## Yearning 安装启动
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
|
|
|
|
- 可以参考:https://next.yearning.io/zh/usage/ixah25xr/
|
2025-01-07 14:16:42 +08:00
|
|
|
|
|
|
|
|
|
### Docker Compose
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
#### `docker-compose.yml` 文件
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
```yaml
|
|
|
|
|
version: '3'
|
|
|
|
|
|
|
|
|
|
services:
|
2025-01-07 14:24:17 +08:00
|
|
|
|
yearning:
|
|
|
|
|
image: yeelabs/yearning:v3.1.5
|
|
|
|
|
environment:
|
|
|
|
|
MYSQL_USER: yearning
|
|
|
|
|
MYSQL_PASSWORD: ukC2ZkcG_ZTeb
|
|
|
|
|
MYSQL_ADDR: mysql
|
|
|
|
|
MYSQL_DB: yearning
|
|
|
|
|
SECRET_KEY: dbcjqheupqjsuwsm
|
|
|
|
|
IS_DOCKER: is_docker
|
|
|
|
|
ports:
|
|
|
|
|
- 8000:8000
|
|
|
|
|
volumes:
|
|
|
|
|
- ./opt/conf.toml:/opt/conf.toml
|
|
|
|
|
#- 首次使用请先初始化
|
|
|
|
|
#- command: /bin/bash -c "./Yearning install && ./Yearning run"
|
|
|
|
|
depends_on:
|
|
|
|
|
- mysql
|
|
|
|
|
restart: always
|
|
|
|
|
|
|
|
|
|
mysql:
|
|
|
|
|
image: mysql:5.7
|
|
|
|
|
environment:
|
|
|
|
|
MYSQL_ROOT_PASSWORD: ukC2ZkcG_ZTeb
|
|
|
|
|
MYSQL_DATABASE: yearning
|
|
|
|
|
MYSQL_USER: yearning
|
|
|
|
|
MYSQL_PASSWORD: ukC2ZkcG_ZTeb
|
|
|
|
|
command:
|
|
|
|
|
- --character-set-server=utf8mb4
|
|
|
|
|
- --collation-server=utf8mb4_general_ci
|
|
|
|
|
volumes:
|
|
|
|
|
- ./data/mysql:/var/lib/mysql
|
|
|
|
|
|
|
|
|
|
#- 默认账号:admin,默认密码:Yearning_admin
|
2025-01-07 14:16:42 +08:00
|
|
|
|
```
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
#### `conf.toml` 文件
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:33:24 +08:00
|
|
|
|
```toml
|
2025-01-07 14:16:42 +08:00
|
|
|
|
[Mysql]
|
2025-01-07 14:33:24 +08:00
|
|
|
|
Db = "Yearning"
|
|
|
|
|
Host = "127.0.0.1"
|
|
|
|
|
Port = "3306"
|
|
|
|
|
Password = ""
|
|
|
|
|
User = "root"
|
|
|
|
|
|
|
|
|
|
[General]
|
|
|
|
|
SecretKey = "dbcjqheupqjsuwsm"
|
|
|
|
|
Hours = 4
|
|
|
|
|
Lang = "zh_CN"
|
|
|
|
|
|
|
|
|
|
[Oidc]
|
|
|
|
|
Enable = false
|
|
|
|
|
ClientId = "${keycloak的客户端ID}"
|
|
|
|
|
ClientSecret = "${keycloak的客户端Secret}"
|
|
|
|
|
Scope = "openid profile"
|
|
|
|
|
AuthUrl = "${issuer链接}/protocol/openid-connect/auth"
|
|
|
|
|
TokenUrl = "${issuer链接}/protocol/openid-connect/token"
|
|
|
|
|
UserUrl = "${issuer链接}/protocol/openid-connect/userinfo"
|
|
|
|
|
RedirectUrL = "${yearning的地址}/oidc/_token-login"
|
|
|
|
|
UserNameKey = "preferred_username"
|
|
|
|
|
RealNameKey = "name"
|
|
|
|
|
EmailKey = "email"
|
|
|
|
|
SessionKey = "session_state"
|
2025-01-07 14:16:42 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Yearning OIDC 配置
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
|
|
|
|
- 可以参考:https://next.yearning.io/zh/usage/boccobus/
|
2025-01-07 14:16:42 +08:00
|
|
|
|
|
|
|
|
|
#### 修改 `conf.toml`(Keycloak示例)
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:33:24 +08:00
|
|
|
|
```toml
|
2025-01-07 14:16:42 +08:00
|
|
|
|
[Oidc]
|
2025-01-07 14:33:24 +08:00
|
|
|
|
Enable = true
|
|
|
|
|
ClientId = "${keycloak的客户端ID}"
|
|
|
|
|
ClientSecret = "${keycloak的客户端Secret}"
|
|
|
|
|
Scope = "openid profile"
|
|
|
|
|
AuthUrl = "${issuer链接}/protocol/openid-connect/auth"
|
|
|
|
|
TokenUrl = "${issuer链接}/protocol/openid-connect/token"
|
|
|
|
|
UserUrl = "${issuer链接}/protocol/openid-connect/userinfo"
|
|
|
|
|
RedirectUrL = "${yearning的地址}/oidc/_token-login"
|
|
|
|
|
UserNameKey = "preferred_username"
|
|
|
|
|
RealNameKey = "name"
|
|
|
|
|
EmailKey = "email"
|
|
|
|
|
SessionKey = "session_state"
|
2025-01-07 14:16:42 +08:00
|
|
|
|
```
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
- ${keycloak的客户端ID}:例如 `yearning`
|
|
|
|
|
- ${keycloak的客户端Secret}: Keycloak中获取
|
|
|
|
|
- ${issuer链接}: Keycloak 中获取
|
|
|
|
|
- ${yearning的地址}:yearning 请求地址
|
|
|
|
|
|
|
|
|
|
### 异常处理
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
- 如果出现异常,可以排查 `Yearning` 服务和 `Keycloak` 服务是否可以访问通畅。
|
|
|
|
|
- 或者说 `Yearning` SSO 配置中的链接在 `Yearning` 所在服务中是否可以正常访问
|
|
|
|
|
|
|
|
|
|
## 本地构建启动(参考)
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
- Yearning `3.1.9.1`
|
|
|
|
|
- 系统 `Ubuntu24.04`
|
|
|
|
|
- nodejs `v18.20.5`
|
|
|
|
|
- npm `10.8.2`
|
|
|
|
|
- go `go version go1.22.10 linux/amd64`
|
|
|
|
|
|
|
|
|
|
### 安装 GO
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
#### 下载安装
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
- 下载 go:https://go.dev/dl/
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
```shell
|
2025-01-07 14:24:17 +08:00
|
|
|
|
#- 解压
|
2025-01-07 14:16:42 +08:00
|
|
|
|
tar -zxf go1.22.10.linux-amd64.tar.gz
|
|
|
|
|
|
2025-01-07 14:24:17 +08:00
|
|
|
|
#- 移动
|
2025-01-07 14:16:42 +08:00
|
|
|
|
mv go /usr/local/go
|
|
|
|
|
|
2025-01-07 14:24:17 +08:00
|
|
|
|
#- 配置环境变量
|
2025-01-07 14:16:42 +08:00
|
|
|
|
vi /etc/profile
|
2025-01-07 14:24:17 +08:00
|
|
|
|
####- /etc/profile start
|
2025-01-07 14:16:42 +08:00
|
|
|
|
export GOROOT=/usr/local/go
|
|
|
|
|
export PATH=$PATH:$GOROOT/bin
|
2025-01-07 14:24:17 +08:00
|
|
|
|
####- /etc/profile end
|
2025-01-07 14:16:42 +08:00
|
|
|
|
|
2025-01-07 14:24:17 +08:00
|
|
|
|
#- 使配置生效
|
2025-01-07 14:16:42 +08:00
|
|
|
|
source /etc/profile
|
|
|
|
|
|
2025-01-07 14:24:17 +08:00
|
|
|
|
#- 查看是否成功
|
2025-01-07 14:16:42 +08:00
|
|
|
|
go version
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 配置 go proxy
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
|
|
|
|
- 参考:https://goproxy.cn/
|
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
```shell
|
|
|
|
|
go env -w GO111MODULE=on
|
|
|
|
|
|
|
|
|
|
go env -w GOPROXY=https://goproxy.cn,direct
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### 安装 Node
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
#### 下载安装
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
- 下载 nodejs:https://nodejs.org/en/download/
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
```shell
|
2025-01-07 14:24:17 +08:00
|
|
|
|
#- 解压
|
2025-01-07 14:16:42 +08:00
|
|
|
|
xz -d node-v18.20.5-linux-x64.tar.xz
|
|
|
|
|
tar tar -xf node-v18.20.5-linux-x64.tar
|
|
|
|
|
|
2025-01-07 14:24:17 +08:00
|
|
|
|
#- 移动
|
2025-01-07 14:16:42 +08:00
|
|
|
|
mv node-v18.20.5-linux-x64 /usr/local/nodejs
|
|
|
|
|
|
2025-01-07 14:24:17 +08:00
|
|
|
|
#- 配置环境变量
|
2025-01-07 14:16:42 +08:00
|
|
|
|
vi /etc/profile
|
|
|
|
|
####-/etc/profile start
|
|
|
|
|
export GOROOT=/usr/local/go
|
|
|
|
|
export NODE_HOME=/usr/local/nodejs
|
|
|
|
|
export PATH=$PATH:$GOROOT/bin:$NODE_HOME/bin
|
|
|
|
|
####-/etc/profile end
|
|
|
|
|
|
2025-01-07 14:24:17 +08:00
|
|
|
|
#- 验证安装
|
2025-01-07 14:16:42 +08:00
|
|
|
|
node -v
|
|
|
|
|
|
|
|
|
|
npm -v
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Yearning 源码安装
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:33:24 +08:00
|
|
|
|
- 工作目录 `/usr/local/workspace`
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
#### 获取 Yearning
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
```shell
|
|
|
|
|
git clone https://github.com/cookieY/Yearning.git
|
|
|
|
|
```
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
#### 获取 Yearning 前端
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
```shell
|
|
|
|
|
git clone https://github.com/cookieY/gemini-next.git
|
|
|
|
|
```
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
#### 编译前端代码
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
```shell
|
2025-01-07 14:24:17 +08:00
|
|
|
|
#- 进入目录
|
2025-01-07 14:16:42 +08:00
|
|
|
|
cd /usr/local/workspace/gemini-next
|
2025-01-07 14:24:17 +08:00
|
|
|
|
#- 安装
|
2025-01-07 14:16:42 +08:00
|
|
|
|
npm install --registry https://registry.npmmirror.com
|
2025-01-07 14:24:17 +08:00
|
|
|
|
#- 构建
|
2025-01-07 14:16:42 +08:00
|
|
|
|
npm run build --registry https://registry.npmmirror.com
|
|
|
|
|
|
|
|
|
|
#- 将目标文件移动到源文件目录
|
|
|
|
|
mv dist /usr/local/workspace/Yearning/src/service/
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
#### 编译后端代码
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:16:42 +08:00
|
|
|
|
```shell
|
|
|
|
|
cd /usr/local/workspace/Yearning
|
|
|
|
|
|
|
|
|
|
go mod tidy
|
|
|
|
|
|
|
|
|
|
cp conf.toml.template conf.toml
|
|
|
|
|
|
2025-01-07 14:33:24 +08:00
|
|
|
|
#- 修改 配置文件
|
2025-01-07 14:16:42 +08:00
|
|
|
|
vi conf.toml
|
|
|
|
|
|
2025-01-07 14:33:24 +08:00
|
|
|
|
#- 初始化(第一次需要)
|
|
|
|
|
#- go run main.go install
|
2025-01-07 14:16:42 +08:00
|
|
|
|
|
2025-01-07 14:33:24 +08:00
|
|
|
|
#- 启动
|
2025-01-07 14:16:42 +08:00
|
|
|
|
go run main.go run
|
|
|
|
|
```
|
2025-01-07 14:24:17 +08:00
|
|
|
|
|
2025-01-07 14:33:24 +08:00
|
|
|
|
- 启动报错 `chat/* xxx`
|
|
|
|
|
- 编辑文件 `vi src/service/yearning.go`
|
2025-01-07 14:24:17 +08:00
|
|
|
|
- 删除报错提示的行相关的代码
|
2025-01-07 14:16:42 +08:00
|
|
|
|
|
|
|
|
|
## 参考
|
|
|
|
|
|
|
|
|
|
- [Yearning安装教程](https://next.yearning.io/zh/usage/ptbzchak/)
|
|
|
|
|
- [使用go语言编译部署最新版Yearning【v3.0.1】](https://blog.csdn.net/qq_44930876/article/details/125679454)
|