Total Pageviews

Sunday, 17 November 2013

在linux vps上搭建基于nodejs+sqlite3的博客程序-ghost

wget http://nodejs.org/dist/v6.9.0/node-v6.9.0.tar.gz
tar zxvf node-v6.9.0.tar.gz
cd node-v6.9.0
./configure
make
make install (这样就编译好了node的6.9.0版)


wget https://github.com/TryGhost/Ghost/releases/download/0.11.9/Ghost-0.11.9.zip
unzip Ghost-0.11.9.zip -d Ghost-0.11.9
cd Ghost-0.11.9

root@localhost:~/Ghost-0.11.9#  cp config.example.js config.js
root@localhost:~/Ghost-0.11.9# nano config.js
(编辑如下:
...
production: {
url: 'http://mydomain.com',
...
 server: {
     host: '127.0.0.1',
     port: '2368'
 } )

root@localhost:~/Ghost-0.11.9# npm install --production

运行npm start (启动ghost的开发模式。注意:Ghost needs Node version为0.10.x, 0.12.x, 4.2.3, 6.9.x, 建议使用6.9.x版不要用git clone的方式去下载node的源码,用git clone的方式下载的源码是最新版)
ctrl+c,退出shell.

root@localhost:~/Ghost-0.11.9# npm install -g forever
root@localhost:~/Ghost-0.11.9# 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@localhost:~/Ghost-0.11.9#


这里http://docs.ghost.org/installation/deploy/ 说的那些把ghost作为service运行的方法
(Forever,supervisor,init script),我测试Forever成功。

若想绑定域名,可使用nginx做反向代理,修改nginx的配置文件,加入如下的server段:
  • server {
        listen 80;
        server_name mydomain.com;
        location / {
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   Host      $http_host;
            proxy_pass         http://127.0.0.1:2368;
        }
    }
    
  • Change server_name's value to your domain
    then restart nginx.   或者使用apache做反向代理也行。
  •  
  • 然后访问http://mydomain.com/ghost and create your admin user to login to the Ghost admin panel
我的示例网站:http://ghost-blog.smt.biz.st/
http://blog.sylee.tw/
项目地址:http://ghost.org,https://github.com/TryGhost/Ghost
http://docs.ghost.org/installation/linux/
http://docs.ghost.org/installation/deploy/
安装指南:
http://www.ghostchina.com/install-ghost-on-ali-ecs-forth-step-install-ghost/
http://ghost.pellegrom.me/installing-ghost-on-ubuntu/
http://0v.org/installing-ghost-on-ubuntu-nginx-and-mysql/#.Uohn3id6XfI
http://howtoinstallghost.com/
http://www.kickstarter.com/projects/johnonolan/ghost-just-a-blogging-platform


Ghost needs Node version ^4.2.3 || ^6.9.0
Please see http://support.ghost.org/supported-node-versions/ for more information.
--------------
升级ghost


  • First you’ll need to find out the URL of the latest Ghost version. It should be something like http://ghost.org/zip/ghost-latest.zip.
  • Fetch the zip file with wget http://ghost.org/zip/ghost-latest.zip (or whatever the URL for the latest Ghost version is).
  • Delete the old core directory from your install
  • Unzip the archive with unzip -uo ghost-latest.zip -d path-to-your-ghost-install
  • Run npm install --production to get any new dependencies
  • Finally, restart Ghost so that the changes will take effect
想不到Ghost更新还是挺简单的,几分钟就把Ghost更新到了0.5.3.
-----------
 最新版的ghost的安装方法


首先安装nvm.
nvm install 6.9.0

git clone https://github.com/TryGhost/Ghost ghost-blog-cloned
cd ghost-blog-cloned
npm install --production
npm install -g knex-migrator
knex-migrator init
git submodule init
git submodule update
(这2个步骤是安装casper theme)
npm start

然后会显示:
> ghost@1.0.0-alpha.21 start /root/ghost-blog-cloned
> node index

Welcome to the Ghost 1.0.0 Alpha - this version of Ghost is for development only.
Ghost is running in development... 
Listening on 127.0.0.1:2368 
Url configured as: http://localhost:2368/ 
Ctrl+C to shut down

若想绑定域名,可使用nginx做反向代理,修改nginx的配置文件,加入如下的server段:

  • server {
        listen 80;
        server_name example.com;
        location / {
            proxy_set_header   X-Real-IP $remote_addr;
            proxy_set_header   Host      $http_host;
            proxy_pass         http://127.0.0.1:2368;
        }
    }
    
  • Change server_name's value to your domain,
    then restart nginx.

---------------------------------------------------------------------

安装ghost blog

Introduction

Ghost blog is a very popular, fast and open source blogging and publishing platform,  written in JavaScript, using the Node.js framework. As stated on the their website, “the inventors of JavaScript, Android and StackOverflow all use Ghost for their blogs”.
So let’s install and configure Ghost on an Ubuntu 16.04

Getting started – Install Node.js

It is possible to install Node.js using NodeSource binary distributions repository. To accomplish this task, execute the following commands:
$ curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
$ sudo apt-get install -y nodejs
Install build tools, required for building and installing npm, with apt:
# apt-get -y install build-essential

Install Ghost

If it doesn’t already exist, create the directory /var/www/:
# mkdir -p /var/www/
There, download Ghost, grabbing the latest version from Ghost.org:
# cd /var/www
# curl -L https://ghost.org/zip/ghost-latest.zip -o ghost.zip
Next, unzip the downloaded archive:
# unzip -uo ghost.zip -d ghost
Move to the new ghost directory, and install Ghost using npm:
# cd ghost
# npm install --production
This is a very fast process, and is totally automated. At the end, Ghost will be correctly installed on the server. Start Ghost (for this moment, just for testing) :
# npm start --production
By default, Ghost runs on http://192.168.1.1:2368 (replace 192.168.1.1 with your server IP Address)
Let’s open http://192.168.1.1:2368 in our browser, we should now see:
In the terminal used for starting Ghost, the process should display a WARNING message:
WARNING: Ghost is attempting to use a direct method to send email.
It is recommended that you explicitly configure an email service.
Right now, this is not a problem and can be ignored. Stop the process with CTRL+C.

Ghost configuration

First of all, create a new user used to run Ghost with the following command:
# useradd -d /var/www -s /bin/bash ghost
# passwd ghost
Change the owner of the Ghost root directory:
# chown -R ghost:ghost /var/www/ghost
After running Ghost for the first time, looking in its root directory you should see different files. We are interested in the one named config.js .
If you haven’t yet run Ghost for the first time, you will see only config.example.js. Copy it:
# cp config.example.js config.js
Open this file with a text editor:
# $EDITOR config.js
In that, we are interested in the production block:
production: { 
 url: 'http://my-ghost-blog.com',
 mail: {},
 database: {
 client: 'sqlite3',
 connection: {
 filename: path.join(__dirname, '/content/data/ghost.db')
 },
 debug: false
 }, 

 server: {
 host: '127.0.0.1',
 port: '2368'
 }
 },
This is the default. We will change it after configuring the server.

Install and configure Apache Web Server

Install Apache with apt:
# apt-get install apache2
Next, enable SSL for Ghost. To do this, create a directory which will contain the SSL certificates:
# mkdir -p /etc/apache2/certs
Generate the certificate (self-signed) with OpenSSL, executing the command:
# openssl req -x509 -nodes -days 365 -newkey rsa:4096 -keyout /etc/apache2/certs/ghost.key -out /etc/apache2/certs/ghost.crt
Change permissions on the certificate file:
# chmod 600 /etc/apache2/certs/*
Next step is to create a new Virtual Host file for Ghost. With a text editor, create a new file:
# $EDITOR /etc/apache2/sites-available/ghost.conf
In this file, paste the following content:
<VirtualHost *:80>
    ServerName myblog.com
    ServerAlias www.myblog.com
    # Force http to https
    Redirect permanent / https://myblog.com/
#    ProxyRequests off 
#    ProxyPass / http://127.0.0.1:2368/ 
#    ProxyPassReverse / http:/127.0.0.1:2368/     
</VirtualHost>

<VirtualHost *:443>

   ServerName myblog.com

   SSLEngine on
   SSLCertificateFile /etc/apache2/certs/ghost.crt
   SSLCertificateKeyFile /etc/apache2/certs/ghost.key

   ProxyPass / http://127.0.0.1:2368/
   ProxyPassReverse / http:/127.0.0.1:2368/
   ProxyPreserveHost   On

   RequestHeader set X-Forwarded-Proto "https"

</VirtualHost>
Save, exit, and activate the SSL Apache module with the following command:
# a2enmod ssl headers
Next, restart Apache:
# systemctl restart apache2

Edit Ghost configuration file

Open the config.js file we have already seen:
# $EDITOR /var/www/ghost/config.js
Change the URL line in the production block, as follows:
url: 'https://myblog.com'
Save and exit. With this change, all requests made via plain HTTP will be redirected to HTTPS.

Create a new systemd service for Ghost

To make it easier to start Ghost, we will create a new systemd service. With a text editor, create a new file:
# $EDITOR /lib/systemd/system/ghost.service
In this empty file, paste the following content:
[Unit]
Description=Ghost - Blogging platform
After=network.target

[Service]
Type=simple
WorkingDirectory=/var/www/ghost
User=ghost
Group=ghost
ExecStart=/usr/bin/npm start --production
ExecStop=/usr/bin/npm stop --production
Restart=always
SyslogIdentifier=Ghost

[Install]
WantedBy=multi-user.target
Save and exit.
Reload the systemd daemon:
# systemd daemon-reload
Using systemd, start Ghost and enable it to start at boot time:
# systemctl start ghost
# systemctl enable ghost
Now, with a web browser, go to URL https://myblog.com and you should see the Ghost Welcome Page.

Conclusion

Ghost is an easy to configure blogging and publishing platform, used by many companies worldwide, like Mozilla and SkyNews. It’s a free and open source software which makes it possible for anyone to easily create a new blog. In this tutorial, we have shown how a full installation and configuration can be completed in just a few steps, using Ubuntu 16.04 and Apache as your web server. Blog away!
-------------

Ghost桌面版程序正式发布,能同时管理多个 Ghost博客





虽然通过浏览器管理 Ghost 博客虽然很方便,但是在多个 tab 之间切换有时候也会很麻烦,嗯,如果能有一个独立的 app 应该使用起来会更爽一些!
今天的主角来了,Ghost 桌面版 APP -- Ghost Desktop!
目前,Ghost Desktop 还处于早期阶段,但是已经是一个全功能版本了,并且 Ghost Desktop 运行良好,支持自动更新,已经完全支持 Mac、Windows 和 Linux 平台了。补充一下,Ghost Desktop 是完全开源的(这还用说吗?)。
其实 Ghost Desktop 于数周前就已经开放给大家预览了。
众所周知,Ghost 是一个有非盈利组织支持的开源项目。Ghost Desktop 由志愿者 Felix Rieseberg 独立开发的,并且他还是一位微软的开源布道者。
官方下载地址(且慢点击,先看下面):https://ghost.org/downloads/
由于 众所周知 的原因,某些网站或服务在国内是不存在的,这其中就包括 Amazon 的云存储,悲伤的是 Github 用的就是 Amazon 的云存储,更悲伤的是 Ghost Desktop 利用的是 Github 提供的下载,说白了,你在国内还真下载不了。所以 GhostChina 把安装包搬运到墙内给大家提供一点儿方便:
-------------------------

Roon

The Roon theme for Ghost.
To download, visit the releases page. See the demo.

from https://github.com/TryGhost/Roon
------------

安装Ghost博客过程

各种系统下安装的教程有很多,但是到了更具体的系统环境下,仍然可能会多出一些问题,为了方便新手学习Ghost blog的安装过程,记录下这篇文章。整个流程基本都一样,但是会出现一些细节问题,主要还是以下几个方面需要注意
  1. nodejs的安装,需要安装Ghost支持的版本。
  2. Ghost的安装。国内网络的特色,导致npm安装失败
以下过程演示在腾讯云Ubuntu14.04 x86系统上,不同的系统可能有细微的差别。

一、环境安装

sudo apt-get update
sudo apt-get install nodejs npm nginx -y

执行完成上列命令后,使用node -v命令查询node版本,到Ghost的Github页面查询支持的版本,确认版本无误。如果命令报错”找不到命令”,不要着急,添加一条软链接即可解决。
sudo ln -s /usr/bin/nodejs /usr/bin/node

二、Ghost的安装

这里是使用Ghost Blog China 制作的中文版本,其中含有一些中国特色的功能,例如七牛云图床等,为了避免之后的麻烦,这里选择使用集成node_modules的完整版,
sudo mkdir /var/www
cd /var/www
sudo wget http://dl.ghostchina.com/Ghost-0.7.4-zh-full.zip
sudo unzip Ghost* -d ghost
cd ghost
sudo npm install node-pre-gyp -g
sudo npm install sqlite3 forever
安装部分到这里就算完成了,接着稍微配置一下,sudo vim config.js,编辑my-ghost-blog成自己的域名,保存退出,接着执行NODE_ENV=production forever start index.js,使用forever以生产模式运行Ghost。

三、Nginx配置

sudo vim /etc/nginx/sites-available/ghost.conf
加入下列内容,修改example成自己的域名
server {
listen 80;
server_name example.com; 
location / { 
proxy_set_header X-Real-IP $remote_addr; 
proxy_set_header Host $http_host;
proxy_pass http://127.0.0.1:2368; } 
}
sudo ln -s /etc/nginx/sites-available/ghost.conf /etc/nginx/sites-enabled/ghost.conf
sudo service nginx restart
添加软链接,重启Nginx生效。当然,还需要域名添加一条a记录指向自己的VPS IP。
-----------

Ghost博客全自动备份

Ghost博客目前没有多少可用的插件,所以整个过程需要在VPS下用脚本完成,把Ghost的数据库与图片备份到Dropbox网盘。

一、所需工具

  • Dropbox账号
  • Ghost博客

二、配置过程

首先,登录Dropbox,打开https://www.dropbox.com/developers/apps,点击creat app创建新的app,依次点击Dropbox APIFull Dropbox,app name随便取名,创建成功后进入刚刚创建的app管理页面,能看到App key、App secret后这个地方就完成了。
使用SSH连接上自己的VPS,进行如下操作:
mkdir backup #创建目录
cd backup #进入目录
wget https://raw.github.com/andreafabrizi/Dropbox-    Uploader/master/dropbox_uploader.sh --no-check-certificate #下载dropbox备份脚本
chmod +x dropbox_uploader.sh #加执行权限
sh dropbox_uploader.sh #运行脚本
首次运行,需要输入之前创建的app的两个key,之后输入f回车,接着复制出现的链接在浏览器中打开,完成授权,至此网盘配置完成。
之后,需要写一个shell脚本,使用顺手的编辑器编辑,我是使用vim,在其中粘贴进去以下内容:
#!/bin/bash
SCRIPT_DIR="/home/user/tools" #这个改成你存放刚刚下    载下来的dropbox_uploader.sh的文件夹位置
DROPBOX_DIR="/backup" #这个改成你的备份文件想要放在Dropbox下面的文件夹名称,如果不存在,脚本会自动创建
BACKUP_SRC="/var/www/ghost/content/images  /var/www/ghost/content/data/ghost.db" #这个是你想要备份的本地VPS上的文件,不同的目录用空格分开
BACKUP_DST="/tmp" #这个是你暂时存放备份压缩文件的地方,一般用/tmp即可

# 下面的一般不用改了
NOW=$(date +"%Y.%m.%d")
DESTFILE="$BACKUP_DST/$NOW.tar.gz"

# 压缩文件
tar cfz "$DESTFILE" $BACKUP_SRC

# 用脚本上传到Dropbox
$SCRIPT_DIR/dropbox_uploader.sh upload "$DESTFILE"     "$DROPBOX_DIR/$NOW.tar.gz"

# 删除本地的临时文件
rm -f "$NOW-Databases.sql" "$DESTFILE"
ghost博客需要备份ghost/content/data/ghost.dbghost/content/images这两个文件夹下的内容即可,或者可以三个月或半年备份一次整个Ghost目录。之前脚本中Ghost的绝对目录位置需要修改。之后继续加执行权,运行脚本就能备份博客到Dropbox了。
最后,需要让这个脚本定时启动,输入crontab -e,在最底部添一行50 1 * * * sh /home/user/backup/backup.sh就能在每天一点50分运行脚本。如需要其他的启动周期,详情请谷歌查crontab命令的使用方法。