### Install Frontend Dependencies and Start Development Server Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/README.md Navigate to the frontend directory, install npm dependencies, and start the development server. The frontend will be accessible at http://localhost:5173. ```bash cd AyeezBlog-Frontend npm install npm run dev ``` -------------------------------- ### Install Admin Panel Dependencies and Start Development Server Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/README.md Navigate to the admin panel directory, install npm dependencies, and start the development server. The admin panel will be accessible at http://localhost:5173/admin/. ```bash cd AyeezBlog-AdminPanel npm install npm run dev ``` -------------------------------- ### Runtime Configuration Example Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/Docker-Compose线上部署指南.md Example configuration file for runtime settings, such as post page size and strict mode. ```yaml postPageSize: 10 strictModeEnabled: false ``` -------------------------------- ### Configure Local Database Settings (Example) Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/README.md Copy the example local configuration file and edit it with your database credentials. This file is automatically imported and is suitable for local private configurations. ```powershell cd AyeezBlog-Backend/blog-server/src/main/resources Copy-Item application-local.example.yml application-local.yml ``` -------------------------------- ### Check Container Start Time and Status Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/Docker-Compose线上部署指南.md Inspect the backend container to confirm its start time and status, ensuring it has not been restarted after configuration updates. ```bash docker inspect ayeezblog-backend --format='StartedAt={{.State.StartedAt}} Status={{.State.Status}} RestartCount={{.RestartCount}}' ``` -------------------------------- ### Start Services with Docker Compose Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/Docker-Compose线上部署指南.md Build and start the services defined in the docker-compose.yml file using the specified environment file. The '-d' flag runs containers in detached mode. ```bash docker compose -f deploy/prod/docker-compose.yml --env-file deploy/prod/.env up -d --build ``` -------------------------------- ### Rebuild and Start Backend Service Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/Docker-Compose线上部署指南.md Rebuild and start only the backend service, useful for applying code changes. ```bash docker compose -f deploy/prod/docker-compose.yml --env-file deploy/prod/.env up -d --build backend ``` -------------------------------- ### Check Docker, Docker Compose, and Git Versions Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/Docker-Compose线上部署指南.md Verify that Docker, Docker Compose, and Git are installed and check their versions. ```bash docker --version docker compose version git --version ``` -------------------------------- ### Production Environment Configuration (.env) Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/Docker-Compose线上部署指南.md Example configuration for the production environment, including timezone, database credentials, and JWT secret. ```dotenv # Timezone TZ=Asia/Shanghai # MySQL data volume name (can be customized for new deployments) MYSQL_VOLUME_NAME=ayeezblog_mysql_data # Database MYSQL_ROOT_PASSWORD=Please change to a strong password HM_DB_USER=blog_user HM_DB_PASSWORD=Please change to business account password # JWT (Please use a sufficiently random and long key) HM_JWT_SECRET_KEY=Please change to a strong random string # Optional: Third-party capabilities (leave empty if not used) QINIU_ACCESS_KEY= QINIU_SECRET_KEY= QINIU_BUCKET= QINIU_DOMAIN= DEEPSEEK_API_KEY= VOLCENGINE_ACCESS_KEY= VOLCENGINE_SECRET_KEY= ``` -------------------------------- ### Build and Run Backend Service Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/README.md Navigate to the backend directory, clean and install the project, then run the Spring Boot application. The default API address is http://localhost:8080. ```bash cd AyeezBlog-Backend mvn clean install cd blog-server mvn spring-boot:run ``` -------------------------------- ### Initialize Database and Import Schema Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/Docker-Compose线上部署指南.md Create the AyeezBlog database and import the table schema using the root MySQL password from the environment. ```bash docker exec mysql sh -c 'mysql -uroot -p"$MYSQL_ROOT_PASSWORD" -e "CREATE DATABASE IF NOT EXISTS ayeezblog CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"' docker exec -i mysql sh -c 'mysql -uroot -p"$MYSQL_ROOT_PASSWORD" ayeezblog' < "AyeezBlog建表.sql" ``` -------------------------------- ### 构建 Docker 镜像 Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/切换与回滚手册.md 在服务器仓库根目录执行,提前拉取或构建服务所需的 Docker 镜像。 ```shell docker compose -f deploy/prod/docker-compose.yml --env-file deploy/prod/.env build backend ``` -------------------------------- ### Clone AyeezBlog Project Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/Docker-Compose线上部署指南.md Create a directory, navigate into it, and clone the AyeezBlog repository. ```bash mkdir -p /opt/ayeezblog cd /opt/ayeezblog git clone https://github.com/Ayeez757/AyeezBlog.git . ``` -------------------------------- ### 重建 Docker 服务 Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/切换与回滚手册.md 在低峰期执行,停止并移除旧服务,然后使用 Docker Compose 启动新服务。 ```shell docker rm -f mysql ayeezblog-backend nginx || true ``` ```shell docker compose -f deploy/prod/docker-compose.yml --env-file deploy/prod/.env up -d mysql ``` ```shell docker compose -f deploy/prod/docker-compose.yml --env-file deploy/prod/.env up -d backend ``` ```shell docker compose -f deploy/prod/docker-compose.yml --env-file deploy/prod/.env up -d nginx ``` -------------------------------- ### Clone AyeezBlog Repository Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/README.md Clone the project repository and navigate into the project directory. ```bash git clone https://github.com/Ayeez757/AyeezBlog.git cd AyeezBlog ``` -------------------------------- ### Set Database Connection Environment Variables (Windows) Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/README.md Configure database connection details using environment variables on Windows. This is the default startup method for the backend service. ```powershell $env:HM_DB_HOST="localhost" $env:HM_DB_USERNAME="root" $env:HM_DB_PASSWORD="你的数据库密码" ``` -------------------------------- ### Backup All Databases Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/Docker-Compose线上部署指南.md Create a SQL dump of all databases, including transactions, routines, and triggers, and save it with a timestamped filename. ```bash mkdir -p /root/db-backup docker exec mysql sh -c 'mysqldump -uroot -p"$MYSQL_ROOT_PASSWORD" --all-databases --single-transaction --routines --events --triggers --set-gtid-purged=OFF' > /root/db-backup/all-databases-$(date +%F-%H%M%S).sql ls -lh /root/db-backup ``` -------------------------------- ### 检查 Docker 依赖资源 Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/切换与回滚手册.md 检查 Docker 卷和网络是否存在,确保切换所需资源可用。 ```shell docker volume ls | rg "html|config|00bf7a5c3317bc4d650e5815dbfd74b4866867e2d46cba4e75958b8434e28e08" ``` ```shell docker network ls | rg ".*ayeez\b" ``` -------------------------------- ### View MySQL Container Logs Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/Docker-Compose线上部署指南.md Check the logs of the MySQL container to diagnose startup failures. ```bash docker logs --tail=200 mysql ``` -------------------------------- ### 停止 Compose 管理服务 Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/切换与回滚手册.md 在回滚操作开始前,停止由 Docker Compose 管理的所有服务。 ```shell docker compose -f deploy/prod/docker-compose.yml --env-file deploy/prod/.env stop nginx backend mysql ``` -------------------------------- ### Create External Network and Volumes Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/Docker-Compose线上部署指南.md Initialize external Docker network and volumes required by docker-compose.yml. The '|| true' ensures the commands do not fail if the network/volume already exists. ```bash docker network create ayeez || true docker volume create html || true docker volume create config || true docker volume create "$(awk -F= '/^MYSQL_VOLUME_NAME=/{print $2}' deploy/prod/.env)" || true ``` -------------------------------- ### 处理容器名称冲突 Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/切换与回滚手册.md 当出现 'container name ... is already in use' 错误时,先删除旧容器再重试 Compose 命令。 ```shell docker rm -f mysql ayeezblog-backend nginx ``` -------------------------------- ### Verify Runtime Configuration Reload Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/Docker-Compose线上部署指南.md Fetch the runtime configuration from the backend API to verify that changes to runtime-config.yml are reflected without restarting the container. ```bash curl http://127.0.0.1:8080/post/runtime/config ``` -------------------------------- ### List Running Containers Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/Docker-Compose线上部署指南.md Display a table of running containers with their names, status, and exposed ports. ```bash docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" ``` -------------------------------- ### Run Frontend with Custom Port Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/README.md If the admin panel and frontend conflict on port 5173, run the frontend development server on a different port, such as 5174. ```bash npm run dev -- --port 5174 ``` -------------------------------- ### View Service Logs Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/Docker-Compose线上部署指南.md View the last 200 lines of logs for MySQL, backend, and Nginx services. ```bash docker compose -f deploy/prod/docker-compose.yml --env-file deploy/prod/.env logs --tail=200 mysql docker compose -f deploy/prod/docker-compose.yml --env-file deploy/prod/.env logs --tail=200 backend docker compose -f deploy/prod/docker-compose.yml --env-file deploy/prod/.env logs --tail=200 nginx ``` -------------------------------- ### Upgrade Project Version Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/Docker-Compose线上部署指南.md Pull the latest code changes and rebuild/restart services using Docker Compose. ```bash cd /opt/ayeezblog git pull docker compose -f deploy/prod/docker-compose.yml --env-file deploy/prod/.env up -d --build ``` -------------------------------- ### 为博客文章表添加分类ID和外键约束 Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/数据库设计.md 在博客文章表中添加了分类ID字段,并设置了与分类表的外键约束,支持在删除分类时将文章的分类ID设为NULL。 ```sql ALTER TABLE blog_post ADD COLUMN category_id BIGINT UNSIGNED NULL COMMENT '分类ID(可为空表示未分类)' AFTER description, ADD KEY idx_category_id (category_id), ADD CONSTRAINT fk_blog_post_category FOREIGN KEY (category_id) REFERENCES blog_category(id) ON DELETE SET NULL ON UPDATE CASCADE; ``` -------------------------------- ### 准备环境变量文件 Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/切换与回滚手册.md 复制示例环境变量文件并填入真实密钥和密码,用于服务配置。 ```shell cp deploy/prod/.env.example deploy/prod/.env ``` -------------------------------- ### 验证回滚后服务状态 Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/切换与回滚手册.md 回滚操作完成后,验证容器状态和外部访问的连通性。 ```shell docker ps --format "table {{.Names}}\t{{.Status}}\t{{.Ports}}" ``` ```shell curl -I https://blog.ayeez.cn ``` -------------------------------- ### Create Blog Category Table Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/数据库设计.md SQL statement to create the `blog_category` table. This table supports hierarchical categories with fields for ID, parent ID, name, slug, description, sorting, and timestamps. It includes unique constraints for category name within a parent and for the slug, as well as a foreign key constraint for the parent ID. ```sql CREATE TABLE blog_category ( id BIGINT UNSIGNED AUTO_INCREMENT COMMENT '分类ID' PRIMARY KEY, parent_id BIGINT UNSIGNED NULL COMMENT '父分类ID,NULL表示顶级', name VARCHAR(64) NOT NULL COMMENT '分类名称', slug VARCHAR(64) NULL COMMENT '可选:URL友好标识,唯一', description VARCHAR(255) NULL COMMENT '分类描述', sort INT DEFAULT 0 NOT NULL COMMENT '同级排序', created_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL, updated_at DATETIME DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP, CONSTRAINT uk_category_name_parent UNIQUE (parent_id, name), CONSTRAINT uk_category_slug UNIQUE (slug), CONSTRAINT fk_blog_category_parent FOREIGN KEY (parent_id) REFERENCES blog_category (id) ON UPDATE CASCADE ) COMMENT '博客文章分类表(树)' COLLATE = utf8mb4_unicode_ci; ``` -------------------------------- ### Create Blog Tag Table Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/数据库设计.md SQL statement to create the 'blog_tag' table. This table stores information about individual tags, including their name, slug, and description. It includes unique constraints on name and slug. ```sql CREATE TABLE IF NOT EXISTS blog_tag ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT COMMENT '标签ID', name VARCHAR(64) NOT NULL COMMENT '标签名', slug VARCHAR(64) NULL COMMENT '可选:URL友好标识,唯一', description VARCHAR(255) NULL COMMENT '标签描述', created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id), UNIQUE KEY uk_tag_name (name), UNIQUE KEY uk_tag_slug (slug) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='博客标签表'; ``` -------------------------------- ### 立即验证服务状态 Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/切换与回滚手册.md 服务重建后立即执行,检查容器状态并进行 HTTP 连通性测试。 ```shell docker compose -f deploy/prod/docker-compose.yml --env-file deploy/prod/.env ps ``` ```shell curl -I http://127.0.0.1 ``` ```shell curl -I https://blog.ayeez.cn ``` ```shell curl -sS http://127.0.0.1:8080/api/logs/current ``` -------------------------------- ### Verify HTTP Access Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/Docker-Compose线上部署指南.md Check if the application is accessible via HTTP on the default port 80 and an alternative port 8080. ```bash curl -I http://127.0.0.1 curl -I http://127.0.0.1:8080 ``` -------------------------------- ### Create Friend Link Table Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/数据库设计.md SQL statement to create the `friend_link` table. This table stores individual blog links, referencing their category via `class_id` and including details like name, URL, avatar, and description. ```sql CREATE TABLE IF NOT EXISTS friend_link ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, class_id BIGINT UNSIGNED NOT NULL, name VARCHAR(128) NOT NULL, link VARCHAR(512) NOT NULL, avatar VARCHAR(512) NULL, descr VARCHAR(512) NULL, rss VARCHAR(512) NULL, sort INT NOT NULL DEFAULT 0, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id), KEY idx_class_id (class_id), CONSTRAINT fk_friend_link_class FOREIGN KEY (class_id) REFERENCES friend_link_class(id) ON DELETE RESTRICT ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ``` -------------------------------- ### 数据库逻辑备份 Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/切换与回滚手册.md 在进行切换前,执行此命令进行数据库的逻辑备份,以确保数据安全。 ```shell docker exec mysql sh -c 'mysqldump -uroot -p"$MYSQL_ROOT_PASSWORD" --all-databases --single-transaction --set-gtid-purged=OFF' > /root/mysql-backup-pre-compose.sql ``` -------------------------------- ### Restart All Services Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/Docker-Compose线上部署指南.md Restart all services managed by Docker Compose. ```bash docker compose -f deploy/prod/docker-compose.yml --env-file deploy/prod/.env restart ``` -------------------------------- ### Create Friend Link Category Table Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/数据库设计.md SQL statement to create the `friend_link_class` table. This table stores information about categories for blog links, including name, description, and sorting. ```sql CREATE TABLE IF NOT EXISTS friend_link_class ( id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, class_name VARCHAR(64) NOT NULL, class_desc VARCHAR(255) NULL, sort INT NOT NULL DEFAULT 0, created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, updated_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY (id), UNIQUE KEY uk_class_name (class_name) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; ``` -------------------------------- ### 创建用户表 Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/数据库设计.md 定义了用户表的结构,包括ID、用户名、密码、角色和状态等字段。 ```sql CREATE TABLE `user` ( `id` BIGINT NOT NULL AUTO_INCREMENT COMMENT '用户ID', `username` VARCHAR(50) NOT NULL COMMENT '用户名', `nickname` VARCHAR(50) DEFAULT NULL COMMENT '昵称', `password` VARCHAR(255) NOT NULL COMMENT '密码(加密存储)', `role` TINYINT NOT NULL DEFAULT 0 COMMENT '角色:0-普通用户,1-管理员', `status` TINYINT NOT NULL DEFAULT 1 COMMENT '账户状态:0-禁用,1-启用', PRIMARY KEY (`id`) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COMMENT ='用户表'; ``` -------------------------------- ### Create Blog Post-Tag Association Table Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/数据库设计.md SQL statement to create the 'blog_post_tag' table, which manages the many-to-many relationship between blog posts and tags. It uses foreign keys to link to the 'blog_post' and 'blog_tag' tables, with cascading delete and update actions. ```sql CREATE TABLE IF NOT EXISTS blog_post_tag ( post_id VARCHAR(64) NOT NULL COMMENT '文章ID(对应blog_post.id)', tag_id BIGINT UNSIGNED NOT NULL COMMENT '标签ID(对应blog_tag.id)', created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (post_id, tag_id), KEY idx_tag_id (tag_id), CONSTRAINT fk_blog_post_tag_post FOREIGN KEY (post_id) REFERENCES blog_post(id) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT fk_blog_post_tag_tag FOREIGN KEY (tag_id) REFERENCES blog_tag(id) ON DELETE CASCADE ON UPDATE CASCADE ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='博客文章-标签关联表'; ``` -------------------------------- ### 创建博客文章表 Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/数据库设计.md 定义了博客文章表的结构,包括ID、标题、内容、封面、创建和更新时间等字段。 ```sql CREATE TABLE blog_post ( id VARCHAR(64) NOT NULL COMMENT '文章ID(字符串,如UUID)', title VARCHAR(255) NOT NULL COMMENT '文章标题', content LONGTEXT NOT NULL COMMENT '文章正文(Markdown)', cover VARCHAR(512) NULL COMMENT '封面图片URL,可为空', create_time DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) COMMENT '创建时间(毫秒精度)', update_time DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3) COMMENT '最后更新时间', description VARCHAR(255) DEFAULT NULL COMMENT '描述', PRIMARY KEY (id), INDEX idx_create_time (create_time DESC) ) ENGINE = InnoDB DEFAULT CHARSET = utf8mb4 COLLATE = utf8mb4_unicode_ci COMMENT ='博客文章表'; ``` -------------------------------- ### Create Index for Parent ID Source: https://github.com/zhdhnsfdx/hans-blog/blob/master/docs/数据库设计.md SQL statement to create an index on the `parent_id` column of the `blog_category` table. This index can improve the performance of queries that filter or sort by parent ID, particularly for retrieving subcategories. ```sql CREATE INDEX idx_parent_id ON blog_category (parent_id); ```