From 548f2a960c8a4a484ff420ce2216d0702e0e954b Mon Sep 17 00:00:00 2001 From: xiaojunnuo Date: Sat, 8 Feb 2025 22:16:27 +0800 Subject: [PATCH] =?UTF-8?q?chore:=20=E5=A2=9E=E5=8A=A0=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E5=BA=93=E6=96=87=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/.vitepress/config.ts | 3 +- docs/guide/install/1panel/index.md | 3 +- docs/guide/install/baota/index.md | 4 ++ docs/guide/install/database.md | 73 ++++++++++++++++++++++++++++++ docs/guide/install/docker/index.md | 2 + 5 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 docs/guide/install/database.md diff --git a/docs/.vitepress/config.ts b/docs/.vitepress/config.ts index 88159dfc..b5854290 100644 --- a/docs/.vitepress/config.ts +++ b/docs/.vitepress/config.ts @@ -78,7 +78,8 @@ export default defineConfig({ ] }, { text: "演示教程", link: "/guide/tutorial.md" }, - { text: "版本升级", link: "/guide/install/upgrade.md" } + { text: "版本升级", link: "/guide/install/upgrade.md" }, + { text: "切换数据库", link: "/guide/install/database.md" } ] }, { diff --git a/docs/guide/install/1panel/index.md b/docs/guide/install/1panel/index.md index 75ad94f9..1cb9b8c6 100644 --- a/docs/guide/install/1panel/index.md +++ b/docs/guide/install/1panel/index.md @@ -19,7 +19,8 @@ https://1panel.cn/docs/installation/online_installation/ 3. 点击确定,启动容器 ![](./images/2.png) -> 默认数据保存在`/data/certd`目录下,可以手动备份 +> 默认使用sqlite数据库,数据保存在`/data/certd`目录下,您可以手动备份该目录 +> certd还支持`mysql`和`postgresql`数据库,[点我了解如何切换其他数据库](../../database/) 3. 访问测试 diff --git a/docs/guide/install/baota/index.md b/docs/guide/install/baota/index.md index ae0d6097..8bec6b04 100644 --- a/docs/guide/install/baota/index.md +++ b/docs/guide/install/baota/index.md @@ -29,6 +29,9 @@ 点击确定,等待启动完成 ![](./images/2.png) +> certd默认使用sqlite数据库,另外支持`mysql`和`postgresql`数据库,[点我了解如何切换其他数据库](../../database/) + + ## 二、访问应用 http://ip:7001 @@ -59,6 +62,7 @@ admin/123456 数据默认保存在`/data/certd`目录下,可以手动备份 + ### 4.3 自动备份 > 建议配置一条 [数据库备份流水线](../../use/backup/),自动备份 diff --git a/docs/guide/install/database.md b/docs/guide/install/database.md new file mode 100644 index 00000000..c6226508 --- /dev/null +++ b/docs/guide/install/database.md @@ -0,0 +1,73 @@ +# 切换数据库 + +certd支持如下几种数据库: +1. sqlite3 (默认) +2. mysql +3. postgresql + +您可以按如下两种方式切换数据库 + + +## 一、全新安装 +::: tip +以下按照`docker-compose`安装方式介绍如何使用mysql或postgresql数据库 +如果您使用其他方式部署,请自行修改对应的环境变量即可。 +::: + +### 1.1、使用mysql数据库 + +1. 安装mysql,创建数据库 `(注意:charset=utf8mb4, collation=utf8mb4_bin)` +2. 下载最新的docker-compose.yaml +3. 修改环境变量配置 +```yaml +services: + certd: + environment: + # 使用mysql数据库,需要提前创建数据库 charset=utf8mb4, collation=utf8mb4_bin + - certd_flyway_scriptDir=./db/migration-mysql # 升级脚本目录 【照抄】 + - certd_typeorm_dataSource_default_type=mysql # 数据库类型, 或者 mariadb + - certd_typeorm_dataSource_default_host=localhost # 数据库地址 + - certd_typeorm_dataSource_default_port=3306 # 数据库端口 + - certd_typeorm_dataSource_default_username=root # 用户名 + - certd_typeorm_dataSource_default_password=yourpasswd # 密码 + - certd_typeorm_dataSource_default_database=certd # 数据库名 + +``` +4. 启动certd +```shell +docker-compose up -d +``` + + +### 1.2、使用Postgresql数据库 + +1. 安装postgresql,创建数据库 +2. 下载最新的docker-compose.yaml +3. 修改环境变量配置 +```yaml +services: + certd: + environment: + # 使用postgresql数据库,需要提前创建数据库 + - certd_flyway_scriptDir=./db/migration-pg # 升级脚本目录 【照抄】 + - certd_typeorm_dataSource_default_type=postgres # 数据库类型 【照抄】 + - certd_typeorm_dataSource_default_host=localhost # 数据库地址 + - certd_typeorm_dataSource_default_port=5433 # 数据库端口 + - certd_typeorm_dataSource_default_username=postgres # 用户名 + - certd_typeorm_dataSource_default_password=yourpasswd # 密码 + - certd_typeorm_dataSource_default_database=certd # 数据库名 + +``` +4. 启动certd +```shell +docker-compose up -d +``` + +## 二、从旧版的sqlite切换数据库 + +1. 先将`旧certd`升级到最新版 (`建议:备份sqlite数据库` ) +2. 按照上面全新安装方式部署一套`新的certd` (`注意:新旧版本的certd要一致`) +3. 使用数据库工具将数据从sqlite导入到mysql或postgresql (`注意:flyway_history数据表不要导入`) +4. 重启新certd +5. 确认没有问题之后,删除旧版certd + diff --git a/docs/guide/install/docker/index.md b/docs/guide/install/docker/index.md index 6dd5ca5c..2465f469 100644 --- a/docs/guide/install/docker/index.md +++ b/docs/guide/install/docker/index.md @@ -42,6 +42,8 @@ docker compose up -d > 如果提示 没有docker compose命令,请安装docker-compose > https://docs.docker.com/compose/install/linux/ +> certd默认使用sqlite数据库,另外还支持`mysql`和`postgresql`数据库,[点我了解如何切换其他数据库](../../database/) + ### 3. 访问测试