安装n模块:html
npm install -g n
升级node.js到最新稳定版node
n stable
note: 参考github,不要去其官网: https://github.com/hexojs/hexopython
安装Hexolinux
npm install hexo-cli -g
Setup your blognginx
hexo init blemesh cd blemesh
安装Cactus主题,众多开源主题中比较简洁的一个:
主题页: https://hexo.io/themes/
Cactus页: https://github.com/probberechts/hexo-theme-cactusgit
git clone https://github.com/probberechts/hexo-theme-cactus.git themes/cactus
修改主题配置:github
vim _config.yml # Extensions ## Plugins: https://hexo.io/plugins/ ## Themes: https://hexo.io/themes/ ## theme: landscape theme: cactus theme_config: colorscheme: white
Create pages and articles with the hexo new [layout] <title> command. For example, to create an "about me" page, run:web
hexo new page about
This will create a new file in source/about/index.md Similary, you can create a new article with算法
hexo new post "hello world"
and add some interesting content in source/_posts/hello-world.md.npm
Start the server:
hexo server
8001 port:
hexo server -p 8001
安装:
npm install --save hexo-admin
打开目录下的_config.yml配置hexo-admin:
admin: username: XXXX(本身设置用户名) password_hash: XXXXXXXXX(密码,可是是明文通过bcrypt hash加密后生成的) secret: hey hexo(用于cookie安全) deployCommand: './admin_script/hexo-generate.sh'(调用该脚本)
注:
1)其中password_hash是你本身的明文密码通过加密后的字符串,可是若是用相似下面的网址: https://bcrypt-generator.com/ 会生成:$2y$10$pJjIxxxxxfMn9U/xxxxxNuuA20kh1eoB7vZxxxxx/7WpeV7IOxxxx
相似的加密串,可是运行会报invalid salt revision
错误,其缘由是:
➜ blemesh cat node_modules/hexo-admin/www/bundle.js | head -4851 | tail -10 if (salt.charAt(0) != '$' || salt.charAt(1) != '2') throw "Invalid salt version"; if (salt.charAt(2) == '$') off = 3; else { minor = salt.charAt(2); if (minor != 'a' || salt.charAt(3) != '$') throw "Invalid salt revision"; off = 4; }
须要版本号是2a的加密方式,所以只能用python本身写了:
https://pypi.org/project/bcrypt/3.1.0/
>>> hashed = bcrypt.hashpw(password, bcrypt.gensalt(prefix=b"2a")) >>> print(hashed) b'$2a$12$PAoJr3USOBxxxxxxxxxxxxxxV/.h.QNbh/6q.xxxxxxxxxxxxxxxxcDcJ.'
2)其中配置中有个脚本: ./admin_script/hexo-generate.sh 须要本身建立:
➜ blemesh cat admin_script/hexo-generate.sh hexo g ➜ blemesh chmod +x admin_script/hexo-generate.sh
这个脚本有什么用,啥时候触发?能够参考: https://www.jianshu.com/p/68e727dda16d step 5,admin后台管理博客有个deploy按钮,点击这个按钮就会执行这个脚本,该脚本会将md文件生成静态网页,若是用nginx配置去访问静态网页,速度会快不少。
配置nginx:编辑 /etc/nginx/nginx.conf 插入下面代码:
server { listen 3001; server_name www.beautifulzzzz.com; index index.html index.htm index; root /root/App/blemesh/public; }
以后重启nginx:nginx -s reload
注:
执行nginx后会报错误:nginx 403 Forbidden,缘由是配置文件nginx.conf文件的执行用户和当前用户不一致致使的,把以前的nobody改为当前用户root。再有错误能够参考[7] [8]。
hexo主页下的tag标签、category标签无显示找不到:
➜ blemesh cat ./source/tags/index.md --- type: "tags" comments: false date: 2019-02-24 02:53:03 ---
➜ blemesh cat ./source/category/index.md --- type: "category" comments: false date: 2019-02-24 02:53:34 ---
➜ blemesh cat ./source/about/index.md --- title: about type: "about-me" comments: false date: 2019-02-22 00:09:58 ---
hexo server进程一直在后台运行的办法(执行hexo server -d &在一段时间后会中止hexo,此时没法打开后台),采用pm2接管hexo进程:
npm install -g pm2
在博客的根目录下建立一个hexo_run.js的文件,文件内容以下:
➜ blemesh cat hexo_run.js const { exec } = require('child_process') exec('hexo server -p 8001 -d',(error, stdout, stderr) => { if(error){ console.log('exec error: ${error}') return } console.log('stdout: ${stdout}'); console.log('stderr: ${stderr}'); })
运行开启命令: pm2 start hexo_run.js
最后附上 zhouwaiqiang 写的一个hexo重启脚本restart_hexo.sh(须要先配置好nginx),须要重启刷新的时候执行source restart_hexo.sh便可:
➜ blemesh cat restart_hexo.sh #!/bin/bash PROCESS=`ps -ef|grep hexo|grep -v grep|grep -v PPID|awk '{ print $2 }'` PROC_NAME="pm2" for i in $PROCESS do echo "Kill the $1 process [ $i ]" kill -9 $i done hexo clean #清除数据 hexo generate #生成静态文件public文件夹 ProcNumber=`ps -ef |grep -w $PROC_NAME|grep -v grep|wc -l` if [ $ProcNumber -le 0 ];then pm2 start hexo_run.js else pm2 restart hexo_run.js fi service nginx restart
: 完~
: 你们以为不错,能够点推荐给更多人~
[1]. linux下在线升级nodejs
[2]. hexo github
[3]. Cactus theme
[4]. hexo documentation
[5]. Error: EACCES: permission denied, mkdir '......node-sass/build'错误解决方案
[6]. bcrypt加密算法
[7]. nginx 403 Forbidden错误的缘由和解决方法
[8]. Failed to start A high performance web server and a reverse proxy server 错误提示
[9]. 重要-hexo搭建我的博客完整版
[10]. 如何优雅地发布Hexo博客
@beautifulzzzz 以蓝牙技术为基础的的末梢无线网络系统架构及创新型应用探索! 领域:智能硬件、物联网、自动化、前沿软硬件 博客:https://www.cnblogs.com/zjutlitao/ 园友交流群|微信交流群:414948975|园友交流群