博客升级 Ghost 1.x 小记
距离 Ghost
博客发布 1.0 版本已经有小半年时间了,到博主今天升级博客 Ghost
已经版本迭代到了 v1.18.4
,Ghost 团队这迭代够快的了。感觉不久就会发布2.x版本😂,其实我9月份就尝试过去升级博客。记得上次是生产环境使用 ghost-cli
时出现数据库迁移问题,让我暂时放弃了直接升级博客。不过那时候根据v1.x主题升级攻略, Kaldorei 从 v0.8.0
升级到了 v1.0.0
,完美适配了 Ghost v1.x
。
花了一下午时间,来研究如何升级 Ghost 到生产环境。别于旧版的 Ghost 环境部署流程,v1.0.0 开始,Ghost 团队提供了 ghost-cli
用来搭建部署,具体参考Install & Setup (production) 其中在我的vps中遇到了一些坑,下面是我的部署流程。
# 安装 Ghost-Cli 工具
~ npm i -g ghost-cli
2
安装成功后,运行 ghost -v
~ ghost -v
Ghost-CLI version: 1.4.0
2
3
# 通过 Ghost-Cli 安装 Ghost
# 选择/创建博客工程目录
~ mkdir -p /home/wwwroot/ghost_latest
2
# 安装 Ghost
~ ghost install --no-setup
2
这里为什么没有采用官方推荐的命令 ghost install
,是因为,安装是有设置流程的,设置的流程还是如之前一样,数据库迁移那一步会报错。报错原因可能因为系统是 CentOS 7,有些命令行工具的功能不能用,官方提示如下:
✔ Checking system Node.js version
✔ Checking current folder permissions
System checks failed with message: 'Linux version is not Ubuntu 16'
Some features of Ghost-CLI may not work without additional configuration.
For local installs we recommend using `ghost install local` instead.
2
3
4
5
6
查看 ghost-cli
帮助文档,找到 ghost-cli 安装是可以分步骤的。
All CLI command are composed of stages. Each stage self registers itself for a command. So for example ghost install contains the stage "setup", whereas ghost setup contains "ssl" and "nginx". That means you can disable "setup" using ghost install --no-stetup, as well as disabling "ssl" for the setup command with ghost setup --no-setup-ssl - very flexible.
所以采用 --no-setup
参数项,暂时跳过安装流程的设置,之后再继续配置。
# 配置 Ghost
~ ghost setup
2
这一步骤会设置博客的链接、数据库的信息(默认为mysql数据库)
# 初始化数据库
~ ghost setup migrate
2
# 创建一个 ghost 用户运行博客
~ ghost setup linux-user
2
# 修改博客实例名称
~ vi .ghost-cli
2
{
"cli-version": "1.4.0",
"active-version": "1.18.4"
}
2
3
4
5
加入 "name": "xlbd-me",
, 这是避免下一步生成系统服务名称为 ghost_undefined.service,看着 undefined 就别扭😂。
{
"cli-version": "1.4.0",
"active-version": "1.18.4",
"name": "xlbd-me"
}
2
3
4
5
6
# 创建跟随系统启动
~ ghost setup systemd
2
这一步依赖 ghost setup linux-user
,必需先有 ghost 用户。
Running sudo command: ln -sf /home/wwwroot/ghost_latest/system/files/ghost_xlbd-me.service /lib/systemd/system/ghost_xlbd-me.service
Running sudo command: systemctl daemon-reload
✔ Setting up Systemd
2
3
4
# 启动博客
~ ghost start
2
# 导入旧版本博客数据
尝试用导出旧版本数据库,再导入新数据库的办法来迁移数据库。失败,原因是新版Ghost删改了一些字段。导入会报错。幸好 Ghost
提供了导入导出数据的功能。
Ghost 后台 > Labs > Export
导出旧版本的数据为json文件,再导入到新Ghost后台,完美迁移数据。
# 兼容旧版本博客
旧版本的博客还是有点纪念意义的,毕竟陪伴了我将近两年。换个端口号,映射到二级域名上。
创建一个 nginx 的 vhost 文件
server {
listen 80;
server_name blog.xlbd.me;
location / {
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:3368;
}
}
2
3
4
5
6
7
8
9
10