Ghost 的高可用安装 安装篇

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: 前面详细的讲述了,在 Node.js 4.x 环境下安装 Ghost 博客平台的准备工作,包括配置、系统的选择,组建的选择等等,如果没有看过的同学,一定要去看一下! 门:《Ghost 的高可用安装 准备篇》

前面详细的讲述了,在 Node.js 4.x 环境下安装 Ghost 博客平台的准备工作,包括配置、系统的选择,组建的选择等等,如果没有看过的同学,一定要去看一下! 门:《Ghost 的高可用安装 准备篇》

下载、准备

这里我们推荐安装的是由王赛翻译的 Ghost 中文版(非官方,因为官方也没有出中文版。)因为,它不仅被翻译了,而且其去除了像谷歌字体这样的会拖慢速度的内容;集成 node_modules 免去了大陆主机无法运行的问题。

下载 http://dl.ghostchina.com/Ghost-0.7.4-zh-full.zip 到相应目录,例如我设置的是 /data/wwwroot/mf8

mkdir -p /data/wwwroot/mf8/ //如果没有就要创建
cd /data/wwwroot/mf8/  //进入目录
wget http://dl.ghostchina.com/Ghost-0.7.4-zh-full.zip  //下载中文版
unzip Ghost-0.7.4-zh-full.zip //解压
npm install --production //跑跑试试,4.x 版本可能会提醒你兼容问题,其实没关系的,不理会即可

然后打开 http://yourdomain:2368 看看能不能访问

编辑 config

我们要修改 config.js 文件,如果没有就讲 config.example.js 改了,

cp config.example.js config.js

一,修改域名

url: 'http://my-ghost-blog.com', 修改成 url: 'http://你的域名',

如果使用了 ssl,且不想全站的话,再添加:urlSSL: https://s你的域名

二,修改,邮箱

mail: {}, 修改成

        mail: {
           transport: 'SMTP',
           from: '发件人地址',
           options: {
                     host: 'smtp 邮件发送服务器',
                     secureConnection: true, // 填 true 则使用加密传输.false 则不
                     port: 465, //如果上面填 true,这里填465;如果上面填 false,这里填 25
                     auth: {
                            user: '邮箱地址',
                            pass: 'A邮箱密码'
                            }
                    }
                },

如果你不想多用户合作,其实不设置也没关系。

三,修改数据库

如果,你想使用 sqlite 的话,则不用改,如果使用 pg 或者 MariaDB(Mysql) 则改。

        database: {
            client: 'sqlite3',
            connection: {
                filename: path.join(__dirname, '/content/data/ghost.db')
            },

MariaDB(Mysql)

        database: {
            client: 'mysql', // MariaDB 也填这个
            connection: {
                host     : 'localhost', //如果使用 RDS 等云数据库则修改为连接地址
                user     : '用户名称',
                password : '用户密码',
                database : '数据库名称',
                charset  : 'utf8' //字符集
            },
            debug: false
        },

这里的话,默认连接次数是 min: 2, max: 10,如果需要改动,则添加:


pool: {
    min: 2,
    max: 20
  }

一只保持连接,则设置 min: 0

PostgreSQL

database: {
            client: 'pg',
            connection: {
                host     : 'localhost',
                user     : '用户名称',
                password : '用户密码',
                database : '数据库名称',
                charset  : 'utf8' //字符集
                //port     : '如果要设置端口,请在这里填写'
            }
        },

四,设置端口

        server: {
            host: '127.0.0.1', //部分配置可能需要设置成 0.0.0.0
            port: '2368' //端口,如果要安装多个博客,那就要设置多个端口了。
        },

五,设置附件

内容较多,而且 Ghostchina 的设置教程也都失效了,有空我单独写一篇介绍一下,会点英语的都看的懂的。

如果你还要设置更多,请参考官方文档:http://support.ghost.org/config/

运行

    npm install --production
    npm start

再打开 http://yourdomain:2368 就能跑气来了,如果你发现你修改的参数并没有生效,则可能是因为运行在 development 模式,而非 production
所以,我们需要修改 /core/index.js 文件,将

    process.env.NODE_ENV = process.env.NODE_ENV || 'development';

修改为:

process.env.NODE_ENV = process.env.NODE_ENV || 'production';

守护进程

当你将 SSH 关闭,或者 Ctrl + c 后,会发现网站就打不开了,因此这里我们需要来维持 Ghost 的运行。

守护进程一般用如下软件:

Upstart:只能在开机启动,无法守护进程

PM2:可开机自启动,程序崩溃自动重新打开,可监控运行
Supervisor:可开机自启动,程序崩溃自动重新打开
Forever:不能开机自启动

所以,这里我们选择 Supervisor 或 PM2,MF8.biz 使用后者。

Supervisor

Debian/Ubuntu: apt-get install supervisor
Fedora/RHEL: yum installsupervisor
其他大多数发行版: easy_install supervisor

确保使用service supervisor start启动了 supervisor ,然后为ghost创建安装脚本, vi /etc/supervisor/conf.d/ghost.conf 输入以下内容,记得替换{ghost_path}

注: {ghost_path} 就是你安装 Ghost 的路径,例如米饭粑的 Ghost 在/data/wwwroot/mf8 那么路径就是这个。

[program:ghost]
command = node {ghost_path}/index.js
directory = {ghost_path}/ghost
user = ghost
autostart = true
autorestart = true
stdout_logfile = /var/log/supervisor/ghost.log
stderr_logfile = /var/log/supervisor/ghost_err.log
environment = NODE_ENV="production"

PM2

安装

npm install pm2 大陆主机安装了 cnpm,就用 cnpm install pm2

在你的 ghost 目录,运行,

NODE_ENV=production pm2 start index.js --name "ghost"

开机自启动,

pm2 startup ubuntu //可以换成,centos、debian

保存,

pm2 save

Nginx 反代

在对应域名的 conf 中,添加

    location / {
        proxy_set_header   X-Real-IP $remote_addr;
        proxy_set_header   Host      $http_host;
        proxy_pass         http://127.0.0.1:2368;
    }

就可以反代了,如果是 https,则是:

    location ~ ^/(?:ghost|signout) {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header Host $http_host;
        proxy_pass http://127.0.0.1:2368;
        add_header Cache-Control "no-cache, private, no-store, must-revalidate, max-stale=0, post-check=0, pre-check=0";
        proxy_set_header X-Forwarded-Proto https;
    }
相关实践学习
基于函数计算快速搭建Hexo博客系统
本场景介绍如何使用阿里云函数计算服务命令行工具快速搭建一个Hexo博客。
目录
相关文章
|
关系型数据库 MySQL Linux
linux安装mysql集群
mysql主从复制
108 0
|
负载均衡 NoSQL 算法
Ubuntu搭建Redis集群
Ubuntu搭建Redis集群
332 0
Ubuntu搭建Redis集群
|
Ubuntu 关系型数据库 MySQL
Ubuntu搭建mysql主从。
Ubuntu搭建mysql主从。 实验环境: Ubuntu16.04 两台,mysql 5.7 本次实例为master -slave。 1)安装mysql 在Ubuntu环境中,使用apt-get install mysql-server 安装mysql。
2480 0
|
NoSQL Linux Redis
centos7搭建redis集群系统
这里创建6个redis节点,其中三个为主节点,三个为从节点。 redis和端口对应关系: 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 从: 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 步骤: 1,下载redis。
1639 0
|
存储 SQL 数据安全/隐私保护
|
安全 数据安全/隐私保护
|
关系型数据库 MySQL API