在Ubuntu中安装Ghost博客系统


#其他#


2014-05-16

本文翻译自:http://ghost.pellegrom.me/installing-ghost-on-ubuntu/。

这篇文章会讲述如何在Ubuntu下安装Ghost。我们先假定你有一个ubuntu服务器,并有一个域名指向了服务器的IP。

1. 安装Node

如果服务器是远程主机的话,可以使用ssh连接到远程主机。先执行下面的命令:

sudo apt-get update
sudo apt-get upgrade
sudo aptitude install build-essential zip

然后到nodejs.org 下载最新版本的.tar.gz打包的文件,解压文件,安装Node:

wget http://nodejs.org/dist/latest/node-v0.10.18.tar.gz
tar -zxvf node-v0.10.18.tar.gz
cd node-v0.10.18
./configure
make
sudo make install

2. 安装Ghost

运行下面的命令下载和安装Ghost:

sudo mkdir -p /var/www
cd /var/www
sudo wget {url to ghost download}
sudo unzip ghost-{version}.zip
sudo npm install

笔者补充:国内可以到https://github.com/TryGhost/Ghost/releases下载Ghost。 解压Ghost后应该先进入Ghost目录,再执行npm install。

3. 配置Ghost

安装完成后,需要修改一下配置文件:

sudo nano config.js

你需要修改下面的值已满足个人需求:

 url: 'http://mysite.com',
 server: {
     host: 'mysite.com',
     port: '80'
 }

config.js中指定了多种运行模式,例如developmentproduction,在生产环境中,应该修改production模式下的相应内容。 你可以在development对应的。要以指定环境运行Ghost,也可以通过NODE_ENV设置,例如:

NODE_ENV=production npm start

4. 将Ghost作为服务(service)运行

建立一个新的服务配置文件:

sudo nano /etc/init/ghost.conf

加入以下内容:

# /etc/init/ghost.conf
description "Ghost Blog"
author "Your Name"
# Start the service after everything loaded
start on (local-filesystems and net-device-up IFACE=eth0)
stop on shutdown
# Automatically restart service
respawn
respawn limit 99 5
script
    # Navigate to your app directory
    cd /var/www
    
    # Run the script with Node.js and output to a log
    export NODE_ENV=production
    exec /usr/local/bin/npm start /var/www 2>&1 >> /var/log/ghost.log
end script

之后就可以使用下面的命令控制这个新的服务了:

sudo service ghost start
sudo service ghost stop
sudo service ghost restart
sudo service ghost status

如果你重启ubuntu服务器或者Ghost崩溃了,init进程会自动刹产生另外一个Ghost实例。

5.最后

通过下面的命令运行Ghost:

sudo service ghost start

访问http://mysite.com或者你设置的网址(别忘了端口号),应该能看到Ghost生成的内容了。关于运行Ghost的更多内容请参考docs.ghost.org

笔者补充

4.将Ghost作为服务(service)运行中的脚本属于upstart的配置文件,关于upstart更多内容请移步upstart官网

要让Ghost一直运行,也有其他方式,具体请见Getting Ghost Live


笔者无心在翻译上花费太大精力,另外也可能在正文中加入笔者的一些想法,有不当处还请指正。


( 本文完 )