Hexo 博客Docker部署前期准备与安装指南(Debian 示例)
前期准备工作
准备一台 Linux 操作系统的服务器(本文以 Debian 为例)
更新软件包并安装基本工具
1
| apt-get update && apt install curl nano
|
开启 SSH 登录并启用 root 用户
手动开启 root 登录
1
| nano /etc/ssh/sshd_config
|
修改以下配置:
PermitRootLogin prohibit-password
→ 修改为:PermitRootLogin yes
#PasswordAuthentication no
→ 修改为:PasswordAuthentication yes
(去掉前面的 #
号)
如 root 用户尚未设置密码:
重启 SSH 服务使配置生效:
一键开启 root 登录 SSH
1
| wget -q root.sh https://raw.githubusercontent.com/passeway/root/main/root.sh && chmod +x root.sh && ./root.sh
|
安装 Docker
一键安装 Docker 脚本
1
| curl -fsSL https://get.docker.com | bash -s docker
|
如需设置国内镜像源(如阿里云):
1
| curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun
|
Docker 官方已内置 docker compose
命令,无需单独安装 docker-compose
。
若你习惯使用 docker-compose
,也可额外安装。注意区分命令写法(有无 -
)。
部署 Hexo 博客
安装 Hexo
- 创建本地 Hexo 容器目录:
1
| mkdir -p /root/data/docker/hexo && cd /root/data/docker/hexo
|
- 创建
docker-compose.yml
配置文件:
- 添加以下内容:
1 2 3 4 5 6 7 8 9 10 11 12 13
| version: '3.0' services: hexo: container_name: hexo restart: always environment: - HEXO_SERVER_PORT=4000 - TZ=Asia/Shanghai volumes: - './blog:/app' ports: - '8889:4000' image: spurin/hexo
|
按 Ctrl + X
保存,回车确认退出。
- 启动容器(后台运行):
访问博客:
安装 Keep 主题
GitHub 仓库地址:
XPoet/hexo-theme-keep
执行以下命令:
1 2 3 4 5 6 7 8 9 10
| cd blog
git clone https://github.com/tanwanme/keep.git themes/keep
rm _config.yml cp themes/keep/blog/_config.yml _config.yml cp themes/keep/blog/_config.keep.yml _config.keep.yml
|
启用主题并安装插件
- 进入容器内部:
1
| docker exec -it hexo bash
|
- 安装 Hexo 插件:
1 2 3 4 5
| npm install npm install hexo-admin --save npm install hexo-deployer-git --save hexo clean && hexo g exit
|
- 重启容器:
1
| docker-compose restart hexo
|
浏览器访问:
配置说明
你可以修改以下文件来自定义博客:
- 主题配置文件:
_config.keep.yml
- Hexo 主配置文件:
_config.yml