Ghost是一款很是出色的开源博客平台,不管是从架构、设计、易用性,它都要比Wordpress要好,界面简洁,专一写做,支持在线预览,在线写做,不管您是在哪里,均可以去写博客,尽情的享受写做带来的快感。php
技术上,采用NodeJs,在可预见的将来里,无疑比PHP有更多优点,并发能力远超Wordpress,虽然NodeJs后期维护成本高,可是咱们只是借它作博客而已。html
易用性上,专一写做,评论,超炫皮肤,完美支持 MarkDown,没有Wordpress那么臃肿,回归到博客最原始的状态,传递文字最原始的力量。node
须要配套支持Node环境的虚拟机,通常免费的不多支持,这时必须得掏腰包了。linux
后台简陋,许多功能还未完善,不过写做这一块没啥大问题。nginx
采用Ghost中文版最新版0.6.3保证了最新功能以及教程的实时性,目前已经更新到了0.7.0,教程所写日期时,最新版本为0.6.3。git
采用Mysql做为数据库,通用快速上手,这里也能够用其余数据库好比Sqlite。github
Nginx做为反向代理,配置多个Ghost博客,同时也能增长了网站的负载。web
很是简易化的Ubuntu的Node.js安装方法,不用编译打包。sql
安装系统服务,开机重启Ghost服务,免去往后之后操做。
采用Font Awesome做为社交按钮,也能够自定义图标。
highlight.js 做为主题的代码高亮引擎
整合Disqus评论系统,创建属于本身的Discuss圈
国外优秀免费Ghost主题资源分享
废话很少说,直接上干货!
Ubuntu 14.04,MySql 5.5.43,Nginx 1.4.6,Node 0.10.33
# 安装MySql $ apt-get update # 更新组件 $ apt-get install mysql-server mysql-client -y # 快速安装-y表明默认选择y省去了回车,这时只须要设置mysql的root密码 # 设置mysql的编码 $ sudo vi /etc/mysql/my.cnf # 搜索到[mysqld] 插入collation-server = utf8_unicode_ci init-connect = 'SET NAMES utf8' character-set-server = utf8 $ service mysql restart # 重启生效 $ mysql -u root -p # 输入上面设置的密码 $ show variables like 'char%' $ show variables like 'collation%' # 查看是否改为utf-8了不然以后数据库内存中文存放的是乱码 # 建立Ghost数据库 $ create database mousycoder # 这里把mousycoder换成你想换成的数据库名,建议和域名保持一致,方便之后维护。 $ create database mousycoderDev # 这个是Ghost启动有2种模式 一种开发模式 一种生产模式 这个是开发模式的数据库,若是不想那么麻烦,只用创建一个数据库便可。 $ create user 'mousycoder'@'localhost' identified by '123456' # 这里新建一个用户mousycoder密码为123456,固然个人密码确定不是123456咯,换成你本身的啦 = =,一样也建议用户名,数据库名,服务名,组名,都和域名保持一致,这里是创建一个只有本地操做的用户,远程没法操做,安全策略。 $ grant all privileges on mousycoder.* to 'mousycoder'@'localhost' $ grant all privileges on mousycoderDev.* to 'mousycoder'@'localhost' # 这里是赋予mousycoder这个本地用户全部对数据库mousycoder以及mousycoderDev的权限,固然这里你能够根据实际须要赋予权限。 $ FLUSH PRIVILEGES # 从新读取权限表中的数据到内存,不用重启mysql就可让权限生效,好处能够防止修改错误后,没有余地再去反悔。
补充说明
mysql 移除匿名帐户,禁用root远程登陆: $ sudo mysql_secure_installation;
回答n,y,y,y,y
grant 用法:grant 权限1,权限2,…权限n on 数据库名称.表名称 to 用户名@用户地址 identified by '口令'
其中权限1,权限2,…权限n表明 select,insert,update,delete,create,drop,
index,alter,grant,reload,references,shutdown,process,file14个权限。
例如:`grant select,insert,update,delete,create,drop on mousycoder.employee to
hello@10.163.225.87 identified by ‘123456′`
表明给来自10.163.225.87的用户hello分配可对数据库mousycoder的employee表进行select,insert,update,delete,create,drop等操做的权限,并设定口令为123456。
mysql乱码缘由详细解能够参考曾是土木人的博客
# 安装nginx $ apt-get install nginx -y $ apt-get install curl -y # curl是一种命令行工具,做用是发出网络请求,而后获得和提取数据。 $ curl -i 127.0.0.1 # 确保Nginx 运行,默认监听80端口 # 设置web目录和cache目录 $ mkdir /var/www $ mkdir -p /var/cache/nginx # -p 能够一会儿把中间路径中不存在的文件夹也一块儿创建,很是实用 $ chown www-data:www-data /var/www # nginx安装会自动创建用户www-data而且默认用这个用户操做 $ chown www-data:www-data /var/cache/nginx # 修改配置文件(通常不操做这个文件) $ cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.old # 备份原来配置 $ vi /etc/nginx/nginx.conf # 能够修改默认用户为其余用户 # 为Ghost单首创建nginx配置文件 $ rm /etc/nginx/sites-enabled/default # 删掉默认的配置 $ vi /etc/nginx/sites-available/mousycoder # 创建一个nginx配置文件
nginx配置文件
server { listen 0.0.0.0:80; # 监听的端口号 server_name mousycoder.com; # 把mousycoder.com换成本身的域名,若是没有域名或者网站还没备案下来这里能够写ip,例如120.25.150.209,若是配置多个网站的话,这里能够经过不一样的端口对应不一样的网站,例如:120.25.150.209:81等 前提是这些端口外网还能访问。 access_log /var/log/nginx/mousycoder.log; location / { proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_set_header X-Real-IP $remote_addr; proxy_pass http://127.0.0.1:2368; # 这里是Ghost启动时的默认端口,能够根据实际状况变化,默认也能够 #proxy_buffering off; proxy_redirect off; } }
而后重启服务
$ ln -s /etc/nginx/sites-available/mousycoder /etc/nginx/sites-enabled/mousycoder # 创建软连接到到实际配置路径,方便统一维护配置文件变化。 $ service nginx restart # nginx安装好时已经默认注册了系统的服务,咱们就能够直接重启nginx服务,让配置文件生效
补充说明
nginx 这里主要是作端口转发映射做用,固然它很是能抗压。
$ wget http://nodejs.org/dist/v0.10.39/node-v0.10.39-linux-x64.tar.gz $ tar zxf node-v0.10.39-linux-x64.tar.gz && cd node-v0.10.39-linux-x64 $ cp bin/* /usr/bin # 拷贝执行目录,至关于去设置一个环境变量到用户的bin目录
补充说明
这里下载的并非最新版的nodejs,为了稳定。
Ghost官网解释
从 Ghost 0.6.0 版本开始,Ghost 中文版完整包已经集成了 Nodejs 0.12 版本的 sqlite3 原生库,在 windows(32/64 bit)、Linux(32/64 bit)、Mac(64 bit)操做系统上能够直接在 Nodejs 0.10.x 和 0.12.x 版本上运行。可是,咱们强烈建议使用 Node.js 0.10.x 最新版本。对 Node.js 0.12.x 版本的支持还有待考验!
详情见 ghost中文网,固然NodeJs有不少种安装方法,我的以为这种是在这里最适合的方法。
$ cd /var/www/ $ curl -L http://dl.ghostchina.com/Ghost-0.6.3-zh.zip -o mousycoder.zip $ unzip mousycoder.zip -d mousycoder $ cd mousycoder/
Ghost有两种运行模式:开发模式和产品模式,经过config.js配置
$ cp config.example.js config.js $ vi config.js
在config.js配置文件里配置
- production # 生产模式 production:{ url: 'http://mousycoder.com', main:{}, database:{ client :'mysql', connection:{ host:'127.0.0.1', user:'mousycoder', # 数据库链接的用户 password:'123456', database:'mousycoder', charset:'utf-8' } } } - development # 开发模式 production:{ url: 'http://mousycoder.com', main:{}, database:{ client :'mysql', connection:{ host:'127.0.0.1', user:'mousycoder', # 数据库链接的用户 password:'123456', database:'mousycoderDev', charset:'utf-8' } } }
根据package.json 安装依赖包,进入当前mousycoder目录下
$ cd /var/www/mousycoder $ npm install --production # 产品模式;只安装运行的包 $ npm install # 开发模式,默认是开发模式
用mousycoder运行Ghost(非root帐户运行Ghost更安全)
$ adduser -shell /bin/bash --gecos 'mousycoder blog' mousycoder $ chown -R mousycoder:mousycoder /var/www/mousycoder
安装forever,保持Ghost一直在后台运行
$ cd /var/www/mousycoder $ npm install forever -g # 全局安装forever模块 $ NODE_ENV=production forever start index.js # 生产模式后台运行ghost
安装系统服务
$ curl https://raw.githubusercontent.com/TryGhost/Ghost-Config/master/init.d/ghost -o /etc/init.d/mousycoder # 下载Ghost提供的脚本到/etc/init.d/目录,该目录是系统服务目录 $ chmod +x /etc/init.d/mousycoder # 给脚本赋予执行权限 $ usermod -aG mousycoder www-data # 把www-data用户加入mousycoder组,让其能够操做源文件等目录 $ update-rc.d mousycoder defaults # 用update-rc.d 安装服务 mousycoder $ update-rc.d mousycoder enable # 刷新一遍服务,防止以前有重名的 $ service mousycoder status # 查看mousycoder 服务的状态 $ service mousycoder start # 这样开机就会自动启动ghost生产环境,不信reboot一下
补充说明
curl 经常使用命令 详情能够参考阮一峰的博客
$ curl -L https://raw.githubusercontent.com/TryGhost/Ghost-Config/master/init.d/ghost -o ghost # -L 解决网站地址自动跳转后拿不到文件 $ curl -v www.baidu.com # 显示详细过程包含http头 $ curl -u username:password url 解决页面须要受权输入用户名密码状况 $ curl -u username --data "param1=value1¶m2=value2" https://api.github.com # post请求 $ curl -I -X DELETE https://api.github.com # 解决get post之外的请求方式 $ curl --form "fileupload=@filename.txt" http://hostname/resource # 上传文件
chmod 命令
$ chmod -R a-w abc # 取消/abc目录的-w(写)权限
drwxr-xr-x 第一列d 目录 第2-4列 拥有者权限 rwx 5-7列 r-x同组用户权限 r-x是其余组用户权限,其中rwx对应4,2,1
系统服务启动顺序
$ update-rc.d A start 50 1 2 3 4 5 stop 51 0 6 $ start 50 1 2 3 4 5 # 表示在1,2,3,4,5这5个运行级别中,按前后顺序,由小到大执行,第50个开始运行脚本 $ stop 50 0 6 # 表示在0,6这两个运行级别中,按照前后顺序,由小到到执行,第52个中止这个脚本运行 $ update-rc.d mousycoder remove # 卸载mousycoder开机服务
打开浏览器,输入以前配置的ip或者域名
首页 http://hostname.com/ghost
Ghost后台 http://hostname.com/ghost
如今你就能够尽情享受Ghost带给你的极致简洁了,快来书写吧!
主题地址:https://github.com/mousycoder/mouse
欢迎fork
感谢您的耐心阅读,若是您发现文章中有一些没表述清楚的,或者是不对的地方,请给我留言,你的鼓励是做者写做最大的动力,
若是您认为本文质量不错,读后以为收获很大,不妨小额赞助我一下,让我更有动力继续写出高质量的文章。
支付宝
微信
做 者 : @mousycoder
原文出处 : http://mousycoder.com/2015/10/12/classic-tutorial-of-ghost-blog/
创做时间:2015-7-1
更新时间:2015-10-14