惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
The Exploit Database - CXSecurity.com
G
Google Developers Blog
爱范儿
爱范儿
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 叶小钗
C
Check Point Blog
F
Fortinet All Blogs
WordPress大学
WordPress大学
S
SegmentFault 最新的问题
博客园 - 【当耐特】
Jina AI
Jina AI
T
The Blog of Author Tim Ferriss
P
Palo Alto Networks Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
L
LINUX DO - 热门话题
M
MIT News - Artificial intelligence
Vercel News
Vercel News
博客园 - 司徒正美
Recorded Future
Recorded Future
阮一峰的网络日志
阮一峰的网络日志
P
Proofpoint News Feed
P
Privacy & Cybersecurity Law Blog
Webroot Blog
Webroot Blog
博客园_首页
C
CXSECURITY Database RSS Feed - CXSecurity.com
云风的 BLOG
云风的 BLOG
D
DataBreaches.Net
Y
Y Combinator Blog
J
Java Code Geeks
B
Blog
A
About on SuperTechFans
O
OpenAI News
aimingoo的专栏
aimingoo的专栏
T
Tor Project blog
Stack Overflow Blog
Stack Overflow Blog
月光博客
月光博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - Franky
AWS News Blog
AWS News Blog
GbyAI
GbyAI
Application and Cybersecurity Blog
Application and Cybersecurity Blog
IT之家
IT之家
V
V2EX
量子位
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
大猫的无限游戏
大猫的无限游戏
Help Net Security
Help Net Security
W
WeLiveSecurity
C
Cyber Attacks, Cyber Crime and Cyber Security

Dvel's Blog

Rime 全拼双拼混输 CHD 油猴脚本:每日签到自动答题 Rime 配置:雾凇拼音 Hammerspoon 自动切换输入法 修复 Hugo 本地图片的累计布局偏移(CLS)问题 macOS 利用 Karabiner 修改 Emacs 键位为 Vim 键位 macOS 修改 Emacs 键位为 Vim 键位 Surge 配置 汉字的混乱 Netflix 中英双语字幕的好办法 优化 Rime 英文输入体验 判断字符是否为简体字或繁体字 Cloudflare 转入域名提示「出现了问题。请重试转移此域。尚未向您收费。」 图片压缩:Squoosh、TinyPNG、ImageOptim、WebP macOS grep + sed 批量替换多个文件的内容 在 macOS 根目录创建文件夹 博客图床小妙招 折腾 Hugo & PaperMod 主题 利用 Cloudflare Workers 进行批量 301 重定向 将博客部署在 Cloudflare Pages Alfred File Navigation(文件导航器)详解 在 Hugo Goldmark Markdown 中设置以新标签打开链接 日期与时间(UTC、GMT、时间戳、时区) 让 Alfred 以新标签的方式打开 Finder 用 git filter-branch 给 Git 仓库瘦身 qBittorrent 设置教程 联通光猫破解+桥接记录 配置 Mac 终端走代理 Steam for Mac 中文游戏推荐 我的 Mac 软件/工具列表 《Flask Web 开发》笔记 用 sleepwatcher 让 Mac 在睡眠及唤醒时自动执行一些脚本 解决 pyenv 导致的 brew warning 《SQL 必知必会》笔记 Git 自总结 Python 异步 IO 笔记 再见,双点医院! 用 CloudXNS 解决 CNAME 与 MX 记录冲突 你好,Hugo! 为 Mac 打造 zsh command line 环境 新 Mac 新装修 秦皇岛暑期自驾的烦恼 苹果公司开发者账号申请流程 UIScrollView 中使用 Masonry 解决 CocoaPods 的类库 import 没有提示 iOS 使用 CocoaPods 的快速回顾 GitBook 简单生成本地静态 HTML 的方法 About
你好, Hexo!
Dvel · 2016-11-27 · via Dvel's Blog

因为之前的 WordPress 博客域名被墙,加上 Hexo 正好满足于简单的书写要求,所以更换为 Hexo。

主要还是记录了自己的搭建过程,因为对 Linux 不太熟悉,以备忘为主。

后面换到了Coding Pages 上搭建,主要是简单方便省心,自带了 https,速度也凑合。

方法一:

本地搭建

安装 node.js

$ brew install node

安装 Hexo

先cd进入创建好的hexo目录:

$ sudo npm install -g hexo-cli
$ hexo init
$ npm install
$ hexo d -fg
$ hexo serve

打开 http://localhost:4000 如果看到 Hexo 的初始页面证明安装成功。

ssh 秘钥

一路回车生成公钥和私钥:

$ ssh-keygen -t rsa -C "email@example.com"

之后在本地目录 ~/.ssh/ 下可以看到私钥 id_rsa 和公钥 id_rsa.pub 已经生成。

安装 ssh-copy-id 等会用,方便上传公钥。

$ brew install ssh-copy-id

VPS 端搭建

更新与安装(centOS)

$ yum update
$ yum install nginx -y
$ yum install git-core

创建 git 用户及设置 ssh 免密码登陆

$ adduser git
$ passwd git
$ chmod 740 /etc/sudoers
$ vim /etc/sudoers
(提示没有安装vim的可以用vi命令,或安装vim:)
$ yum -y install vim*

在编辑器中找到以下内容并添加一行:

## Allow root to run any commands anywhere
root    ALL=(ALL)     ALL
git     ALL=(ALL)     ALL (这行是添加的)

保存退出并执行:

$ chmod 440 /etc/sudoers

接下来切到本地的终端,上传公钥:

$ ssh-copy-id -i ~/.ssh/id_rsa.pub git@123.123.123.123

测试一下,如果 $ ssh git@VPS的IP地址 ,能够免密码登录的话,则表示成功。

回到 VPS,创建 git 仓库:

$ su git
$ cd ~
$ mkdir hexo.git && cd hexo.git
$ git init --bare

创建网站目录并赋予 git 对网站目录的所有权

$ su root
$ cd /var/www
$ mkdir hexo
$ chown git:git -R /var/www/hexo

配置 git hooks

$ su git
$ cd /home/git/hexo.git/hooks
$ vim post-receive

写入以下内容:

#!/bin/bash
GIT_REPO=/home/git/hexo.git #git仓库
TMP_GIT_CLONE=/tmp/hexo
PUBLIC_WWW=/var/www/hexo #网站目录
rm -rf ${TMP_GIT_CLONE}
git clone $GIT_REPO $TMP_GIT_CLONE
rm -rf ${PUBLIC_WWW}/*
cp -rf ${TMP_GIT_CLONE}/* ${PUBLIC_WWW}

然后赋予脚本的执行权限

$ chmod +x post-receive

配置 Nginx

启动 nginX:

systemctl status nginx.service      // 查看服务当前状态
systemctl start nginx.service       // 启动nginx服务
systemctl restart nginx.service     // 重新启动服务

systemctl enable nginx.service      // 设置开机自启动
systemctl disable nginx.service     // 停止开机自启动

systemctl list-units --type=service // 查看所有已启动的服务

然后:

$ vim /etc/nginx/conf.d/hexo.conf

插入如下代码:

server {
    listen         80 ;
    root /var/www/hexo;//这里可以改成你的网站目录地址,我将网站放在/var/www/hexo
    server_name example.com www.example.com;//这里输入你的域名或IP地址
    access_log  /var/log/nginx/hexo_access.log;
    error_log   /var/log/nginx/hexo_error.log;
    location ~* ^.+\.(ico|gif|jpg|jpeg|png)$ {
            root /var/www/hexo;
            access_log   off;
            expires      1d;
    }
    location ~* ^.+\.(css|js|txt|xml|swf|wav)$ {
        root /var/www/hexo;
        access_log   off;
        expires      10m;
    }
    location / {
        root /var/www/hexo;//这里可以改成你的网站目录地址,我将网站放在/var/www/hexo
        if (-f $request_filename) {
            rewrite ^/(.*)$  /$1 break;
        }
    }
}

然后重启nginx,此时刷新网页应该显示的是403。

本机的最后配置

位于 hexo 文件夹下,_config.yml ,修改 deploy 选项,例如:

deploy:
  type: git
  message: update  # 这个可以不写,会默认生成update日期
  repo: git@123.123.123.123:hexo.git,master # 逗号后面写分支

部署到多个仓库可以这么写:

deploy: 
  - type: git
    repo: git@git.coding.net:Dvel/Dvel.git,master
  - type: git
    repo: git@github.com:iDvel/Dvel-Hexo.git,master

每次更新博客也可以让github上长点绿草了。。。

接下来安装 hexo-deployer-git ,否则部署时会报这个错"ERROR Deployer not found: git"。

$ npm install hexo-deployer-git --save

接着$ hexo g && hexo d,如果一切正常,静态文件已经被成功的push到了blog的仓库里。

期间我忘了还出了个什么错,删除hexo目录下的.deploy_git后再次hexo g && hexo d就可以了。

以上,博客已经完全建好了。

$ hexo generate是生成静态文件。

$ hexo deploy是部署,我们这里选择了Git,Hexo还支持其他部署形式。

所以每次写完文章,执行这两个命令后,就对网站完成了更新。

简化操作就是:$ hexo g && hexo d ,再简化就是$ hexo d -g,效果一样。

方法二,利用一键安装包

因为不太熟悉 Linux,所以我选择了一键安装包,多站点管理方便些。

我用的这个 -> OneinStack官网

步骤和上面差不多,但是很多路径要改一下,也可以很简单的搭建出Hexo。

方法三,Coding Pages

  1. coding 中创建项目

  2. 站点配置文件_config.ymldeploy 中写好 coding 项目的 git 地址

  3. push 上去:$ hexo d -g

  4. 在 coding 上你的项目,开启 Pages 服务:可以自定义分支,绑定域名,开启 https

  5. 大功告成

这个相对简单一些,Coding Pages 服务目前提供 100M 空间的支持,一般来说没有写文章的话,生成的 public 文件夹大约小于5M。

100M 基本够写很多年的博客,至于图片应该另寻图床,不要放到 coding 上,否则空间很快用完。

编写文章、更新博客

使用一款 MarkDown 编辑器写文章 ,写完后将文件以 *.md 的格式保存在本地 [网站目录]\source_posts 中。

Markdown 编辑器,强烈安利 Typora。

每篇 Blog 都有固定的参数必须填写,参数如下,注意每个参数的 : 后都有一个空格。

title: title
date: yyyy-mm-dd
categories: category  
tags: tag
#多标签请这样写:  
#tags: [tag1,tag2,tag3]
#或者这样写: 
#tags:
#- tag1 
#- tag2  
#- tag3  
---  
正文  

或者使用 $ hexo new 命令,具体官网有详细说明。

编写完后,只需要在hexo文件夹下执行 hexo g && hexo d,博客即可更新。

遇到的坑

设置了 ssh 免密码登陆后,依然需要密码

这整段是以前使用的方法,过时了。。。
设置ssh免密码登陆:
su git
cd ~
mkdir .ssh && cd .ssh
touch authorized_keys
vim authorized_keys  //在这个文件中粘贴进刚刚申请的key(在id_rsa.pub文件中)
设置权限:
chmod o-w ~/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

测试免密码登陆
ssh -vvT git@123.123.123.123   // 你的VPS的IP地址
发现依然需要密码,搜了好几天没找到解决办法,后来采用了ssh-copy-id,解决了这个问题。

如果过程中重新初始化过 VPS 的磁盘,ssh 连接 VPS 的时候可能会提示 Host key verification failed.

运行此命令即可:$ ssh-keygen -R 123.123.123.123,将 123.123.123.123 改成你的 VPS 的 IP。

或者简单粗暴直接删除 known_hosts 文件。