由于ghost只支持4.2以下的node版本,最终选择了hexo这个非常优秀的博客框架。
下文的环境为:
cvm:CentOS
本地:MacOS
特别感谢molunerfinn开发的hexo主题
1. 一些准备工作
本文的主要演示在云服务器上部署个人博客系统,如果仅仅想在本地(macos)体验的可以忽略一些条件。
1.1 部署的准备
- 云服务器(云服务器大大降低了部署门槛)
- 域名与备案工作(也可以暂时通过IP访问)
- 在服务器(本地)安装Git
- 安装node&npm
- 使用npm全局安装pm2
- 安装nginx(为了部署一些二级域名)
- 图床服务器(推荐七牛云,私人有免费10G空间)
2.安装
2.1安装hexo
通过npm全局安装hexo-cli
1 | npm install hexo-cli -g |
小提示:
最好科学上网,或者将npm源切换为淘宝镜像
1.设成淘宝的
1 | npm config set registry http://registry.npm.taobao.org/ |
2.换成原来的
1 | npm config set registry https://registry.npmjs.org/ |
2.2生成博客站点
1 | hexo init myblog |
2.3安装主题
强烈推荐melody这个主题,中文文档在此,图文并茂,简洁明了,另外hexo中文文档
安装
1 | git clone -b master https://github.com/Molunerfinn/hexo-theme-melody themes/melody |
设置
1 | // 在 hexo 的工作目录下找到站点配置文件——_config.yml |
如果你没有pug以及stylus的渲染器,请下载安装: npm install hexo-renderer-jade hexo-renderer-stylus --save or yarn add hexo-renderer-jade hexo-renderer-stylus
2.4主题的一些配置
1 | // 社交 |
这里需要注意,如果开启字数统计需要安装hexo-wordcount,否则会遇到一些问题
1 | npm install hexo-wordcount |
或者用yarn的同学
1 | yarn add hexo-wordcount |
1 | // 友情链接设置(实例就是这个主题的作者哦) |
为了主题的平滑升级, theme-melody 使用了data files特性。
推荐把主题默认的配置文件_config.yml复制到 hexo 工作目录下的source/_data/melody.yml,如果source/_data的目录不存在那就创建一个。
2.5 标签页配置
在站点目录下
1 | hexo new page tags |
前往source/tags/index.md这个文件并修改
1 | --- |
2.6 分类配置
在站点目录下
1 | hexo new page categories |
你会找到source/categories/index.md这个文件并修改
1 | --- |
顺便一提hexo新建一篇博客的方式是
1 | hexo new yourblogtitle |
在source下_post下编辑你的博文md文件
1 | --- |
2.7启动服务
1 | hexo server |
默认端口是4000,也可以自定义端口
1 | hexo server -p 8000 |
到此安装过程已经结束,并且已经可以通过浏览器访问,默认会有hello-world一篇博客
3. pm2进程守护
通过pm2后台运行hexo,完成服务器部署
在站点目录下(这里是myblog)新建app.js
1 | var spawn = require('child_process').spawn; |
运行pm2
1 | pm2 start app.js -x --name myblog |
