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

目录
相关文章
|
关系型数据库 MySQL Shell
python检测服务器是否ping通
好想在2014结束前再赶出个10篇博文来,~(>_ result.txt 思路也很简单,将IP列表读取来写进一个iplist文件,然后再对这个文件fping(调用fping.sh)批量执行的结果写进result文件: def check_online_ip(): ip = my...
2587 0
|
JavaScript Windows Shell
windows下node.js调用bat
node.js调用bat需要用到Child Processes模块 因为bat是文件,所以需要使用execFile方法   如果指定了cwd,它会切换bat执行的目录,类似cd的功能,如果未指定默认为当前调用程序的目录。
2220 0
|
关系型数据库 数据库 Ruby
CentOS 下装 Ruby On Rails开发环境
下载相应的软件进行安装 http://rubyonrails.org/download/  不配置默认安装到 /usr/local/ruby下面的 进入 /usr/local/ruby/bin/gem install rails rails new 应用名  rails new blog ...
1228 0
|
JavaScript 开发工具 git
ruby on rails在fedora18上install
ruby on rails 在fedora18下的安装 天朝的网络原因,安装不是很顺畅,所以把过程记录下备用 前面下载rubygem什么的都比较快,新建一个project的时候会出问题 gem new my_project  会在bundle_install处卡很久,然后提示说某某东西没装,让装一下。
1396 0
|
JavaScript
as3与node.js的socket通信
这里使用了一个单例的SocketManager类: 1: conn = new Socket(); 2: 3: conn.
868 0
|
Web App开发 监控 JavaScript
CoffeeScript学习笔记
CoffeeScript编程语言构建于Javascript之上,它可编译成高效JavaScript。可以在Web浏览器上,或者结合Node.js一类的技术构建服务端应用程序。   The golden rule of CoffeeScript is: "It's just JavaScript".
933 0
webstorm配置node.js--webstorm下载配置node失败解决办法
  webstorm是开发node.js最好的工具,大家可以去网上下载最新版本。他是付费软件,有30天的试用时期,大家可以找破解版来用,我下载的是4.0版本,网上找了破解密钥。 密钥内容: username:solq 35758-12042010 00001cIW59IBVHRPp019pvqMI0zUcw RqOCGkr4xcLxYJaUE6RgIfTVRv43kV 80GauemJf4PvNrFQdFYdjTGBTmZZXQ   软件安装完毕就需要为其配置node,方法如下:   点击圈中的icon,会有对话框弹出。
1142 0
|
Web App开发 前端开发 JavaScript
php推送
需求: 我想做个会员站内通知的功能。不想用以前的ajax查询,听说有个推技术。以下文章介绍的不错,来自转载, ================================================================================== PHP中Push(推送)技术的探讨  [http://vistaswx.com/blog/article/php-server-push]   随着人们对Web即时应用需求的不断上升,Server Push(推送)技术在聊天、消息提醒尤其是社交网络等方面开始兴起,成为实时应用的数据流核心。
1360 0
|
Android开发 开发工具 数据格式
自己开发一个 vsts agent 的 task
vsts 中支持自定义Build/Release的过程Task 目标:做一个可以读取 Xamarin.Android 所生成的 APK 的 基本信息的 task ,包括 package(包名) / application label(应用标题 )/version name(版本号)/version code(版本代码)   下面简述流程 1.
1526 0
|
JavaScript Apache
Cordova WP8 平台安装部署
原文:Cordova WP8 平台安装部署   Cordova是一个开放源码移动开发框架。 它允许您使用标准的 web 技术如 HTML5、 CSS3 和 JavaScript 进行跨平台开发,避免每个移动平台的本机开发语言。
1112 0