从零搭建生产环境的ghost2.0博客

当前安装过程是在ghost cli 1.9.2上的,由于ghost更新特别快,我安装我个人博客cmlanche.com的时候还是1.9.1,当时没碰到啥问题,到1.9.2就有一点点不一样了,所以要注意当时你的安装版本。

针对安装过程我会针对ghost的更新不断更新文档

环境要求

安装设置官方文档:https://docs.ghost.org/docs/getting-started-guide

  1. 操作系统:Ubuntu 16.04 or Ubuntu 18.04 见主机购买文章:Vultr主机购买流程
  2. MySQL
  3. Nginx(最低1.9.5,目的是为了安装SSL)
  4. Systemd
  5. NodeJS(推荐使用>=8.9 (Node v8 carbon LTS),不支持9+,10+)
  6. 至少1GB内存
  7. 在非root用户下执行ghost命令

环境安装

# 登录你的Ubuntu系统
ssh root@<yourip>
# 添加系统新用户
adduser <yourusername>
# 提高该用户权限
usermod -aG sudo <yourusername>
# 登录到这个用户
su <yourusername>
# 更新Ubuntu的包管理工具apt-get
sudo apt-get update
sudo apt-get upgrade
# 安装Nginx
sudo apt-get install nginx
# 为http和https打开防火墙
sudo ufw allow 'Nginx Full'
# 安装MySql
sudo apt-get install mysql-server
# 登录到mysql,更新root密码
sudo mysql
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '<you-mysql-password>';
# 创建mysql数据库
create database <yourdatabasename>
# 退出mysql
exit
# 以后你登录mysql,就需要这样了:
mysql -uroot -p
# 安装NodeJS
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash
sudo apt-get install -y nodejs
# 安装Ghost CLI
sudo npm i -g ghost-cli
# 创建ghost安装目录,并赋予权限
sudo mkdir -p /var/www/ghost
sudo chown <yourusername>:<yourusername> /var/www/ghost # 比如我的用户名是test,那就用test:test
sudo chmod 775 /var/www/ghost # 赋予该目录读写权限
# 将工作环境切换到ghost安装目录
cd /var/www/ghost
# 安装ghost
ghost install # 安装会默认使用mysql数据库,另外可以选择使用sqlite,生产环境当然用mysql了

环境排错

在使用ghost install安装的时候,报错:

✔ Checking system Node.js version
✔ Checking logged in user
✔ Checking current folder permissions
✔ Checking operating system compatibility
✔ Checking for a MySQL installation
✔ Checking memory availability
✖ Checking for latest Ghost version
A ProcessError occurred.

Message: Command failed: yarn info ghost versions --json
{"type":"error","data":"An unexpected error occurred: \"EACCES: permission denied, scandir '/home/cmlanche/.config/yarn/link'\"."}

错误说/home/cmlanche/.config没权限,那么我们授予当前用户这个目录的权限:

sudo chown cmlanche:cmlanche /home/cmlanche/.config

注意这里的cmlanche是我系统里面的用户名,你应该替换成你的用户名。

ghost安装必须在一个空目录,而刚刚出错,产生了一个叫yarn-error.log的文件,我们需要删掉它:

rm yarn-error.log

然后再次安装

ghost install

输出:

cmlanche@vultrhosting:/var/www/ghost$ ghost install
✔ Checking system Node.js version
✔ Checking logged in user
✔ Checking current folder permissions
✔ Checking operating system compatibility
✔ Checking for a MySQL installation
✔ Checking memory availability
✔ Checking for latest Ghost version
✔ Setting up install directory
✔ Downloading and installing Ghost v2.1.0
✔ Finishing install process
? Enter your blog URL: (http://localhost:2368) https://www.vultrhosting.com

这样就表示ghost安装环境一切正常了!

演示安装VultrHosting.com

我们当然会要求安装ssl证书了,ghost利用国人编写的acme.sh提供了一整套非常便捷的安装Let’s Encrypt ssl数字证书的流程,官方配置看config

Enter Your Blog URL: 设置你的博客站点地址

我们输入: https://www.vultrhosting.com,这里我们需要注意的是要设置为https,对这个域名vultrhosting.com要提前设置好域名解析,例如下图:

image-20180902161713477

上图是阿里云后台的截图,你需要再你的域名注册商设置@和www这两个主机记录,指向你的主机IP地址。注意一定要提前设置好,后续安装ssl证书的时候会去检测解析状态的

Enter your MySQL hostname: 设置你的mysql主机地址

默认用localhost就好

Enter your MySQL username: 设置你的mysql用户名

我们用root就好,或者你自己登录到mysql去建一个新用户,注意要赋予必要的权限,比较麻烦,我们就用root就好了。用户名输入了,再输入你的mysql数据库密码,密码就是环境安装中你重设的root密码

Do you wish to set up "ghost" mysql user? 是否希望建立一个ghost的mysql用户

n,否

Do you wish to set up Nginx?

Y,当然安装了

Do you wish to set up SSL?

Y,等待ssl安装完成

Do you wish to set up Systemd?

Y,必要选择,文章开头的环境要求就说了,必须要Systemd

✔ Creating systemd service file at /var/www/ghost/system/files/ghost_www-vultrhosting-com.service
Running sudo command: ln -sf /var/www/ghost/system/files/ghost_www-vultrhosting-com.service /lib/systemd/system/ghost_www-vultrhosting-com.service
Running sudo command: systemctl daemon-reload
✔ Setting up Systemd
? Do you want to start Ghost? Yes
Running sudo command: systemctl is-active ghost_www-vultrhosting-com
✔ Ensuring user is not logged in as ghost user
✔ Checking if logged in user is directory owner
✔ Checking current folder permissions
Running sudo command: systemctl is-active ghost_www-vultrhosting-com
✔ Validating config
✔ Checking folder permissions
✔ Checking file permissions
✔ Checking content folder ownership
✔ Checking memory availability
Running sudo command: systemctl start ghost_www-vultrhosting-com
✔ Starting Ghost
Running sudo command: systemctl is-enabled ghost_www-vultrhosting-com
Running sudo command: systemctl enable ghost_www-vultrhosting-com --quiet
✔ Enabling Ghost instance startup on server boot
You can access your publication at https://www.vultrhosting.com
Next, go to to your admin interface at https://www.vultrhosting.com/ghost/ to complete the setup of your publication

Ghost uses direct mail by default
To set up an alternative email method read our docs at https://docs.ghost.org/docs/mail-config

好了,ghost已经安装并启动了,访问https://www.vultrhosting.com试试吧()

image-20180902162937050

ghost安装失败怎么办?

比如操作失误,你可以ghost uninstall来删除刚刚安装的ghost,注意需要再ghost工作目录下执行,所有的ghost命令都要求制定工作目录,上面我使用的工作目录是/var/www/ghost

删除ghost之后,你可以重试,如果还是出问题,那么你可以:

  1. 在官方论坛提问,他们回应会很快的,论坛地址:https://forum.ghost.org/
  2. 求助我,QQ:1204833748,微信:cmlanche

ghost停止、启动命令

ghost stop
ghost start

ghost后台管理

ghost后台管理会再第一次打开会是一个注册界面,要求输入管理员账号和密码,注册成功之后再次打开,如果没有登录的话,就是一个登录界面。所以注册认证只有一次。但是ghost系统并不仅仅只有一个用户,你可以在后台管理邀请其他人加入你的网站系统,通过发邮件邀请的方式。

image-20180902163829192

image-20180902164010699

ghost后台界面一览

ghost CMS博客系统崇尚的是简洁简便,后台管理真的是让人爱不释手,第一次看到它就喜欢上了,因为它我爱上了写博客,让我有了认真写作的心,谢谢你ghost!

image-20180902164103979

posted @ 2018-09-03 08:42  我是一颗小草  阅读(588)  评论(0编辑  收藏  举报