• Ghost博客安装


    Ghost博客是一个基于Node.js 的开源博客平台,由前WordPress UI 部门主管John O’Nolan 和WordPress 高级工程师Hannah Wolfe 创立,目的是为了给用户提供一种更加纯粹的内容写作与发布平台。

    目前来看,Ghost博客相对于Wordpress来说没有太明显的优势,现在的用户也都是码农们和喜欢尝鲜的朋友居多。当然Ghost博客体验良好的markdown编辑器、响应式前后台设计、采用的实时架构,让博客变得更有效率。

    Ghost博客从2013年10月开始发布,现在已经更新了多个版本,各方面也逐渐完善起来了,但是普及率还有待于提高。Ghost需要Node.js环境和搭建难度过大,应该是Ghost博客推广的主要障碍。未来Ghost博客有很大的发展潜力。

    安装Node运行环境

    Node.js是一个可以快速构建网络服务及应用的平台,基于Chrome's JavaScript runtime,即Google V8引擎,是一款高性能的服务架构平台。

    yum安装

    yum install nodejs(适用于Centos等)
    

    apt-get方式安装(适用于Ubutun等)

    apt-get install nodejs
    

    windows安装
    直接下载安装包安装nodejs

    命令行执行命令:node -v,可以查看是否成功安装Node.js,npm -v可以查看是否安装了npm。

    如果没有安装npm,输入

    yum install npm
    

    安装 Ghost

    建议先阅读http://www.ghostchina.com/download/。

    Ghost 中文集成版下载(建议下载此版本,包含组件sqlite等)
    最新版本:Ghost v0.7.0 full (zh)

    cd /www/
    #中文集成版
    wget http://dl.ghostchina.com/Ghost-0.7.0-zh-full.zip
    
    #中文标准版
    #wget http://dl.ghostchina.com/Ghost-0.7.0-zh.zip 
    
    mkdir ghost
    cd ghost
    unzip Ghost-0.7.0-zh-full.zip
    

    以上地址可能会更新,请以官网的为主。

    本地测试运行

    cp config.example.js config.js
    

    本地环境测试运行不用改任何配置(数据库默认使用SQLite):

    node index.js
    

    正常运行会输出:

    Migrations: Up to date at version 004
    Ghost is running in development... 
    Listening on 127.0.0.1:2368 
    Url configured as: http://localhost:2368 
    Ctrl+C to shut down
    

    在浏览器输入http://localhost:2368即可。但是通过node index.js启动的会独占窗口,也不稳定,建议仅测试的时候用。

    配置 Ghost 域名

    设置域名解析

    例如g.52fhy.com,添加A记录,设置记录值为主机的IP地址即可。

    配置nginx

    在/usr/local/nginx/conf/vhosts/新增一个配置文件g.52fhy.com.conf,内容为:

    server {  
        listen 80;
        server_name g.52fhy.com;
    
        location / {
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   Host      $http_host;
            proxy_pass         http://127.0.0.1:2368;
        }
    }
    

    以上是Nginx作为Ghost博客的反向代理。

    重启nginx

    /usr/local/nginx/sbin/nginx -s relaod
    

    让 Ghost 一直运行

    前面提到的启动 Ghost 使用 npm start 命令。这是一个在开发模式下启动和测试的不错的选择,但是通过这种命令行启动的方式有个缺点,即当你关闭终端窗口或者从 SSH 断开连接时,Ghost 就停止了。为了防止 Ghost 停止工作,有两种方式解决这个问题。

    Forever

    你可以使用 forever 以后台任务运行 Ghost 。forever 将会按照 Ghost 的配置,当进程 crash 后重启 Ghost。

    • 通过 npm install forever -g 安装 forever
    • 运行Ghost forever start index.js
    • 为了让 forever 从 Ghost 安装目录运行,输入
    #注意production 为生产环境
    NODE_ENV=production forever start index.js;
    
    • 通过 forever stop index.js 停止 Ghost;
    • 通过 forever list 检查 Ghost 当前是否正在运行。
    [root@test ghost]# NODE_ENV=production forever start index.js
    warn:    --minUptime not set. Defaulting to: 1000ms
    warn:    --spinSleepTime not set. Your script will exit if it does not stay up for at least 1000ms
    info:    Forever processing file: index.js
    
    [root@test ghost]# forever list
    info:    Forever processes running
    data:        uid  command       script   forever pid   id logfile                 uptime      
    data:    [0] 0JVT /usr/bin/node index.js 12148   12157    /root/.forever/0JVT.log 0:0:0:1.555 
    

    Supervisor

    流行的 Linux 发行版——例如 Fedora, Debian 和 Ubuntu,都包含一个 Supervisor 包:一个进程控制系统,允许在启动的时候无需初始化脚本就能运行 Ghost。不像初始化脚本一样,Supervisor 可以移植到不同的发行版和版本。

    根据不同的 Linux 发行版 安装 Supervisor 。如下所示:

    • Debian/Ubuntu: apt-get install supervisor
    • Fedora: yum install supervisor
    • 其他大多数发行版: easy_install supervisor
    • 通过 service supervisor start 确保 Supervisor 运行
    • 为 Ghost 创建一个启动脚本。通常为 /etc/supervisor/conf.d/ghost.conf ,例如:
    [program:ghost]
    command = node /path/to/ghost/index.js
    directory = /path/to/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"
    
    • 使用 Supervisor 启动 Ghost:supervisorctl start ghost

    • 停止 Ghost: supervisorctl stop ghost

    详细内容请参阅 Supervisor文档

    增加评论

    • 多说
    • disqus 评论系统

    增加 CDN

    使用 CDN 缓存页面可以加快访问速度,减轻服务器的压力。
    免费的 CDN 有很多,这里就不列举了。

    设置SMTP发邮件

    给Ghost博客设置SMTP只需要编辑:vim config.js,在production下的Mail中加入SMTP信息即可。

    mail: {
        transport: 'SMTP',
        options: {
            service: 'Gmail',
            auth: {
                user: 'youremail@gmail.com',
                pass: 'yourpassword'
            }
        }
    }
    

    Ghost博客Google Fonts字体、备份和设置Apache反代

    1、Ghost博客默认的主题加载了Google Fonts,导致博客打开变慢或者根本上打不开,解决的办法就是去掉主题中加载的Google Fonts链接。

    2、Ghost博客后台去掉Google Fonts需要进入到:core/server/views/default.hbs·和·core/server/views/user-error.hbs,把里面的fonts.googleapis.com链接删除了。

    3、默认的主题去掉Google Fonts需要进入到:content/themes/casper/default.hbs,把里面的fonts.googleapis.com链接删除了。

    4、Ghost博客备份与恢复。Ghost 博客的所有文章内容都是存储在 sqlite3 数据库中的,其位置是 /content/data/ghost.db。另外,所有上传的图片都放在了 /content/images/ 目录下。

    5、Ghost博客自带了一个备份与恢复的页面,地址是:域名/ghost/debug/。 点击 Export 按钮就可以将博客内容导出为 .json 文件,还有一个导入工具 Import ,可以将 .json 格式的备份内容导入Ghost 系统。 最后一个红色按钮 Delete all content 是用来删除所有内容(即清空数据库)。

    6、设置Apache反代。本文中使用了Nginx作为Ghost博客的反代,如果你喜欢使用Apache,可以用以下代码实现Apache反代Ghost。

    7、CentOS(或Redhat)系统中,Apache 的配置文件位于/etc/httpd/conf.d目录下;而 Ubuntu 系统中则是位于 /etc/apache 目录下。将下面给出的这段配置信息添加到 Apache 的配置文件中(注意替代成你的域名):

    NameVirtualHost *:80  
    <VirtualHost *:80>
         ServerName your-domain-name.com
         ServerAlias www.your-domain-name.com
         ProxyRequests off
         ProxyPass / http://127.0.0.1:2368/
         ProxyPassReverse / http:/127.0.0.1:2368/
    </VirtualHost>
    

    8、如果你想用Apache反代多个Ghost博客,使用以下代码:

    NameVirtualHost *:80  
    <VirtualHost *:80>
         ServerName your-domain-name.com
         ServerAlias www.your-domain-name.com
         ProxyRequests off
         ProxyPass / http://127.0.0.1:2368/
         ProxyPassReverse / http:/127.0.0.1:2368/
    </VirtualHost>
    
    <VirtualHost *:80> 
         ServerName yoursecond--domain-name.com
         ServerAlias www.yoursecond--domain-name.com
         ProxyRequests off
         ProxyPass / http://127.0.0.1:8080/
         ProxyPassReverse / http://127.0.0.1:8080/
    </VirtualHost> 
    

    9、最后重启 Apache生效。
    在 CentOS 系统中执行如下命令: service httpd restart
    在 Ubuntu 系统中执行: service apache2 restart

    DIY 一个主题

    参考官方文档 http://themes.ghost.org/

    参考:
    1、在树莓派上搭建一个博客
    http://blog.eqoe.cn/posts/website-on-raspberry-pi.html
    2、Ghost博客安装与使用教程-Node.js,Nginx,MySQL,Ghost搭建与配置
    http://www.freehao123.com/ghost-node-js/
    3、http://www.ghostchina.com/download/
    4、http://docs.ghostchina.com/zh/installation/deploy/
    5、supervisor安装配置与使用 - 其他 - 红黑联盟
    http://www.2cto.com/os/201503/378878.html

  • 相关阅读:
    Android中xml解析
    [转]谈谈Java中"=="与"equals()"
    Java多线程之interrupt()的深度研究
    android:inputType参数类型说明
    Android中不能在子线程中更新View视图的原因
    美团2017秋招笔试题 拼凑钱币
    关于springmvc json交互产生的406错误
    Redis事务
    java 访问剪切板(读取与设置)
    Ajax之跨域访问与JSONP
  • 原文地址:https://www.cnblogs.com/52fhy/p/5036742.html
Copyright © 2020-2023  润新知