Ghost 的高可用安装 安装篇
本文最后更新于 3002 天前,其中的信息可能已经有所发展或是发生改变。

前面详细的讲述了,在 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
--------------

```js
        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 的运行。

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

Forever:不能开机自启动
Supervisor:可开机自启动,程序崩溃自动重新打开
Upstart:只能在开机启动,无法守护进程
PM2:可开机自启动,程序崩溃自动重新打开,可监控运行

所以,这里我们选择 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;
    }

评论

  1. 8年前
    2016-1-24 9:17:55

    测试

本文评论已关闭
上一篇
下一篇