问题现象
部署 Hexo 博客时遇到各种错误,无法正常运行。
常见问题 1: Hexo init 失败
症状
1 2 3
| FATAL { err: Error: Command failed: git clone ... }
|
原因
- 网络连接问题
- Git 配置错误
- GitHub 访问受限
解决方案
1 2 3 4 5 6 7 8 9 10 11
| cat > ~/.gitconfig << 'EOF' EOF
cd /root/tech-blog rm -rf themes/next git clone https://github.com/next-theme/hexo-theme-next themes/next
git clone https://gitee.com/next-theme/hexo-theme-next themes/next
|
常见问题 2: npm install 失败
症状
1 2
| npm ERR! network timeout npm ERR! code ETIMEDOUT
|
原因
解决方案
1 2 3 4 5 6 7 8
| npm config set registry https://registry.npmmirror.com
npm install
npm config get registry
|
常见问题 3: 博客无法访问
症状
原因分析
| 原因 |
检查方法 |
解决 |
| 服务未启动 |
ps aux | grep http.server |
启动服务 |
| 端口未开放 |
firewall-cmd --list-ports |
开放端口 |
| 阿里云安全组 |
控制台检查 |
添加规则 |
解决方案
1 2 3 4 5 6 7 8 9 10 11
| cd /root/tech-blog/public nohup python3 -m http.server 8080 &
firewall-cmd --zone=public --add-port=8080/tcp --permanent firewall-cmd --reload
netstat -tlnp | grep 8080 curl http://localhost:8080
|
常见问题 4: hexo generate 失败
症状
1
| ERROR Asset render failed: ...
|
原因
解决方案
1 2 3 4 5 6 7 8 9
| cat _config.yml | grep theme
ls -la themes/next
hexo clean hexo generate
|
常见问题 5: 文章不显示
症状
原因
解决方案
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| cat source/_posts/*.md | head -10
hexo clean hexo generate
|
完整排查流程
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| node --version npm --version
hexo version
ls -la themes/
ls -la source/_posts/
hexo clean hexo generate
ps aux | grep http.server netstat -tlnp | grep 8080
curl http://localhost:8080
|
日志查看
1 2 3 4 5 6 7 8
| hexo generate --debug
tail -f /tmp/blog-server.log
journalctl -u hexo-blog -f
|
预防措施
1. 使用 systemd 服务
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| [Unit] Description=Hexo Blog Server After=network.target
[Service] Type=simple User=root WorkingDirectory=/root/tech-blog/public ExecStart=/usr/bin/python3 -m http.server 8080 Restart=always RestartSec=10
[Install] WantedBy=multi-user.target
|
2. 配置日志轮转
1 2 3 4 5 6 7 8 9
| /tmp/blog-server.log { daily rotate 7 compress delaycompress missingok notifempty }
|
3. 定期备份
1 2
| tar -czf /backup/hexo-blog-$(date +%Y%m%d).tar.gz /root/tech-blog
|
总结
博客部署问题通常是配置或网络问题,按照上述流程排查即可解决。
建议:
- 使用 systemd 服务管理博客
- 配置防火墙规则
- 定期备份博客内容
遇到问题?在评论区留言!