CentOS7 安装配置 Ghost

准备工作

环境依赖

  • 至少 1 GB 物理内存(可设置 1GB 以上的 Swap 代替)

  • Systemd (CentOS 7 自带)

  • 一个非 root 且拥有 sudo 权限的用户(用户名不能为 ghost )

  • NGINX(如需使用 HTTPS 则需要 NGINX >= 1.9.5)

  • Node.js( 支持的 Node.js 版本 ,推荐 node@10)

  • Yarn(替代 npm 管理 Node.js 软件包)

检查系统内存

查看当前系统内存:

free

​ total used free shared nbuff/cache available

Mem: 1016168 100360 293520 356 622288 746024

Swap: 0 0 0

可见当前系统物理内存为 1GB,虚拟内存为 0,可以不设置。

如果物理内存不足 1GB,可设置 1GB 交换分区作为虚拟内存使用:

再次查看系统内存信息:

​ total used free shared buff/cache available Mem: 1016168 100360 293520 356 622288 746024 Swap: 1048572 0 1048572

检查当前用户

安装运行 Ghost 需要使用一个非 root ,用户名不为 ghost 且拥有 sudo 权限的用户。如果没有,需要新建一个用户进行后续操作。

检查 NGINX

检查 NGINX 版本:

nginx version: nginx/1.10.2

如果需要使用 HTTPS,则需要 NGINX >= 1.9.5。

检查 Node.js

检查 Node.js 版本:

v10.16.3

检查 Yarn

查看当前安装的 Yarn 版本:

1.19.0

查看 Yarn 全局 bin 路径:

/usr/local/bin

如果 yarn global bin 路径不是公共路径,需要设置成公共路径。

Tips: Ghost 服务启动时,是以 ghost 这个用户的身份启动的,这个用户没有访问其他用户个人目录文件的权限。Yarn 全局安装的 Ghost-CLI 命令在 yarn global bin 路径,如果该路径不是公共路径,会导致 Ghost-CLI 命令执行失败。

查看当前用户的环境变量中的 $PATH

/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin

如果 Yarn 全局 bin 路径不在其中,需要手动添加到环境变量中。

安装 Ghost

安装 Ghost-CLI

使用 Yarn 全局安装 Ghost-CLI :

查看安装的 Ghost-CLI 版本:

Ghost-CLI version: 1.11.0

新建 Ghost 安装目录

新建 Ghost 安装目录:

修改安装目录所有者为安装运行 Ghost 的用户:

修改安装目录权限:

进入安装目录:

使用 Ghost-CLI 安装 Ghost

使用 Ghost-CLI 在当前目录安装 Ghost ,并使用 SQLite 3 数据库,安装完不启动 :

...... ? Enter your blog URL: (http://localhost:2368)

输入博客访问地址:

? Enter your blog URL: http://blog.avincheng.com ...... ? Do you wish to set up Systemd? (Y/n)

输入 Y 或者直接回车,自动创建 Systemd 服务 :

..... Ghost was installed successfully! To complete setup of your publication, visit:

https://blog.avincheng.com/ghost/

此时完成安装。

配置 NGINX

新建配置文件:

写入配置:

修改 server_name 字段为自己解析的域名,多个域名空格隔开。

保存退出,重启 NGINX 服务:

启动 Ghost

搜索 Ghost-CLI 创建的 Systemd 服务文件:

/lib/systemd/system/ghost_blog-avincheng-com.service

使用 Systemd 服务启动 Ghost:

设置 Ghost 开机启动:

通过浏览器访问管理后台地址并注册管理员账号:

管理 Ghost

在 CentOS 7 上,Ghost-CLI 相关命令在检查 Ghost 的 Systemd 服务状态时返回值为 unknown ,会导致命令执行失败。所以相关命令如 ghost start/stop/restart/ls 等均无法执行,需要直接使用 Systemd 启动或停止 Ghost 服务。

启动 Ghost:

停止 Ghost:

重启 Ghost:

设置 Ghost 开机启动:

停止 Ghost 开机启动:

参考文献

Last updated

Was this helpful?