Bboysoul's Blog

首页 公告 RSS

ghost博客部署

September 17, 2017 本文有 1192 个字 需要花费 3 分钟阅读

概述

ghost是基于nodejs构建的开源博客平台
网上有很多部署ghost博客的文章,包括ghost中文网,部署的方法很多,但是我觉得最方便的就是用ghost_cli去部署ghost,ghost-cli是1.0版本之后出现的新工具。简单来说就是它能够帮助我们更加方便地安装,启动,升级和管理我们的ghost-blog.
下面就来介绍这种部署的方式

系统要求

下面是官方要求的系统和系统环境

  • Ubuntu 16.04
  • MySQL
  • NGINX (minimum of 1.9.5 for SSL)
  • Systemd
  • Node v6 installed via NodeSource
  • At least 1GB memory (swap can be used)
  • A non-root user for running ghost commands

安装部署

因为官方推荐使用ubuntu16.04,所以我的系统也是ubunut16.04的,大家最好也和我一样

用户设置

为了安全建议使用非root的用户去管理关于ghost博客的东西,所以推荐要新建一个账户,专门用来管理ghost
sudo adduser ghost
把这个用户添加到sudo用户组中,使它具有使用sudo的权限
sudo usermod -aG sudo ghost
以ghost用户身份登录
su - ghost

更新一下系统

sudo apt update && sudo apt upgrade

安装nginx

sudo apt-get install nginx

打开HTTP / HTTPS的防火墙

查看一下ufw是不是被激活

ghost@bboysoul:/etc/init.d$ sudo service ufw status
● ufw.service - Uncomplicated firewall
   Loaded: loaded (/lib/systemd/system/ufw.service; enabled; vendor preset: enabled)
   Active: active (exited) since Sat 2017-09-16 15:24:12 CST; 29min ago
 Main PID: 337 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/ufw.service

Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

如果被激活,那么要确保防火墙允许http/https的连接

ghost@bboysoul:/etc/init.d$ sudo ufw allow 'Nginx Full'
Rules updated
Rules updated (v6)

安装mysql

sudo apt-get install mysql-server

安装nodejs

因为ghost博客是用nodejs写的,所以要使用安装nodejs
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash
sudo apt-get install -y nodejs

安装Ghost-CLI

因为身处中国,所以要切换一下nodejs的源,不然下载会很慢
npm config set registry https://registry.npm.taobao.org
之后安装ghost-cli
sudo npm i -g ghost-cli

ghost@bboysoul:/etc/init.d$ sudo npm i -g ghost-cli
[sudo] password for ghost: 
npm WARN deprecated [email protected]: Use uuid module instead
/usr/bin/ghost -> /usr/lib/node_modules/ghost-cli/bin/ghost
/usr/lib
└── [email protected] 

安装ghost

首先新建一个站点文件夹
sudo mkdir -p /var/www/ghost
把这个文件夹的所有者改为ghost
sudo chown ghost:ghost /var/www/ghost/
切换到这个文件夹中
cd /var/www/ghost/
安装ghost
ghost install

ghost@bboysoul:/var/www/ghost$ ghost install
✔ Checking system Node.js version
✔ Checking current folder permissions
✔ Checking operating system
✔ Checking MySQL is installed
✔ Checking for latest Ghost version
✔ Setting up install directory
✔ Downloading and installing Ghost v1.8.6
✔ Finishing install process
? Enter your blog URL: http://localhost:2368
? Enter your MySQL hostname: localhost
? Enter your MySQL username: root
? Enter your MySQL password: [hidden]
? Enter your Ghost database name: ghost
✔ Configuring Ghost
✔ Setting up instance
Running sudo command: chown -R ghost:ghost /var/www/ghost/content
[sudo] password for ghost: 
✔ Setting up "ghost" system user
? Do you wish to set up Nginx? No
ℹ Setting up Nginx [skipped]
Task ssl depends on the 'nginx' stage, which was skipped.
ℹ Setting up SSL [skipped]
? Do you wish to set up "ghost" mysql user? No
ℹ Setting up "ghost" mysql user [skipped]
? Do you wish to set up Systemd? Yes
✔ Creating systemd service file at /var/www/ghost/system/files/ghost_localhost.service
Running sudo command: ln -sf /var/www/ghost/system/files/ghost_localhost.service /lib/systemd/system/ghost_localhost.service
Running sudo command: systemctl daemon-reload
✔ Setting up Systemd
✔ Running database migrations
? Do you want to start Ghost? Yes
✔ Validating config
Running sudo command: systemctl start ghost_localhost
✔ Starting Ghost
You can access your blog at http://localhost:2368/

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网站,如果访问不了请耐心等一下,因为程序的启动可能会比较慢,如果你要在别的机器上访问自己的博客。那么修改它的配置文件,就像下面
vim config.production.json

{
  "url": "http://192.168.1.102:2368/",
  "server": {
    "port": 2368,
    "host": "192.168.1.102"
  },
  "database": {
    "client": "mysql",
    "connection": {
      "host": "localhost",
      "user": "root",
      "password": "woyaoxuehuilinux",
      "database": "ghost"
    }
  },
  "mail": {
    "transport": "Direct"
  },
  "logging": {
    "transports": [
      "file",
      "stdout"
    ]
  },
  "process": "systemd",
  "paths": {
    "contentPath": "/var/www/ghost/content"
  }
}

注意修改的是url和host要改为自己机器的实际ip而不是127.0.0.1
当然我没有配置nginx,如果你配置了nginx,只要修改nginx中的配置文件就可以了
Have Fun


Tags:

本站总访问量 本站总访客数