Linux下Hexo+GitHub搭建个⼈博客
配置信息
[root@iZwz9c74ta983j746ynevpZ ~]# uname -a
Linux iZwz9c74ta983j746ynevpZ 3.10.0-1127.10.1.el7.x86_64 #1 SMP Wed Jun 3 14:28:03 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
更新源(可略过)
## 备份原源⽂件
[root@iZwz9c74ta983j746ynevpZ ~]# mv /pos.d /pos.d.bak
五一节短信[root@iZwz9c74ta983j746ynevpZr ~]# mkdir /pos.d
## 阿⾥云
[root@iZwz9c74ta983j746ynevpZ ~]# wget -O /pos.po mirrors.aliyun/po --no-check-certificate
[root@iZwz9c74ta983j746ynevpZ ~]# yum clean all
[root@iZwz9c74ta983j746ynevpZ ~]# yum makecache
[root@iZwz9c74ta983j746ynevpZ ~]# yum update -y
Hexo搭建
[root@iZwz9c74ta983j746ynevpZ ~]# yum install -y git
node.js安装
node.js安装包下载
下载对应⼆进制安装包:
[root@iZwz9c74ta983j746ynevpZ ~]# wget /mirrors/node/v14.6.0/node-v14.6. --no-check-certificate
node.js安装部署
[root@iZwz9c74ta983j746ynevpZ ~]# tar -zxf node-v14.6.罗浩的前妻
[root@iZwz9c74ta983j746ynevpZ ~]# mv node-v14.6.0-linux-x64 /opt/nodejs
# 创建软连接
[root@iZwz9c74ta983j746ynevpZ ~]# ln -s /opt/nodejs/bin/node /usr/local/bin/node
[root@iZwz9c74ta983j746ynevpZ ~]# ln -s /opt/nodejs/bin/npm /usr/local/bin/npm
Hexo安装部署
Hexo安装
[root@iZwz9c74ta983j746ynevpZ ~]# npm install hexo-cli -g
/opt/nodejs/bin/hexo -> /opt/nodejs/lib/node_modules/hexo-cli/bin/hexo
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/hexo-cli/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"}) + hexo-cli@4.0.0
added 61 packages from 315 contributors in 46.255s
若安装hexo报错如下:
[root@iZwz9c74ta983j746ynevpZ ~]# npm install hexo-cli -g
npm ERR! code CERT_NOT_YET_VALID
npm ERR! errno CERT_NOT_YET_VALID
npm ERR! request to /hexo-cli failed, reason: certificate is not yet valid
npm ERR! A complete log of this run can be found in:
npm ERR!    /root/.npm/_logs/2010-03-31T20_55_08_156Z-debug.log
[root@iZwz9c74ta983j746ynevpZ ~]# npm install hexo-cli -g --no-check-certificate
npm ERR! code CERT_NOT_YET_VALID
npm ERR! errno CERT_NOT_YET_VALID
npm ERR! request to /hexo-cli failed, reason: certificate is not yet valid
npm ERR! A complete log of this run can be found in:
npm ERR!    /root/.npm/_logs/2010-03-31T20_55_35_518Z-debug.log
原因是https的⾃签名失败,临时解决办法:关闭ssl
[root@iZwz9c74ta983j746ynevpZ ~]# npm config set strict-ssl false
Hexo部署
将 hexo 命令添加到全局,采⽤软连接⽅式。
[root@iZwz9c74ta983j746ynevpZ ~]# ln -s /opt/nodejs/lib/node_modules/hexo-cli/bin/hexo /usr/local/bin/hexo
Hexo博客环境部署
初始化Hexo博客根⽬录
强烈建议先换npm源见:
[root@iZwz9c74ta983j746ynevpZ ~]# mkdir /var/hexoblog
[root@iZwz9c74ta983j746ynevpZ ~]# hexo init /var/hexoblog/
INFO  Cloning hexo-starter github/hexojs/hexo-starter.git
Submodule 'themes/landscape' (github/hexojs/hexo-theme-landscape.git) registered for path 'themes/landscape'
Cloning into 'themes/landscape'...
remote: Enumerating objects: 8, done.
remote: Counting objects: 100% (8/8), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 1071 (delta 1), reused 5 (delta 1), pack-reused 1063
Receiving objects: 100% (1071/1071), 3.22 MiB | 12.00 KiB/s, done.
Resolving deltas: 100% (586/586), done.
Submodule path 'themes/landscape': checked out '73a23c51f8487cfcd7c6deec96ccc7543960d350'
INFO  Install dependencies
[ .................] - fetchMetadata: sill pacote range manifest for kind-of@^3.0.2 fetched in 386ms
[ .................] - fetchMetadata: sill pacote range manifest for kind-of@^3.0.2 fetched in 386ms
[ .................] - fetchMetadata: sill pacote range manifest for kind-of@^3.0.2 fetched in 386ms
[ .................] - fetchMetadata: sill pacote range manifest for kind-of@^3.0.2 fetched in 386ms
[ .................] - fetchMetadata: sill pacote range manifest for kind-of@^3.0.2 fetched in 386ms
[ .................] - fetchMetadata: sill pacote range manifest for kind-of@^3.0.2 fetched in 386ms
卡住在这......,猜测是npm源问题,更换国内源
更换npm源
## 查看默认源
[root@iZwz9c74ta983j746ynevpZ hexoblog]# npm config get registry
/
## 更换阿⾥源
[root@iZwz9c74ta983j746ynevpZ hexoblog]# npm config set registry registry. [root@iZwz9c74ta983j746ynevpZ hexoblog]# npm config get registry
registry./
若init失败,须清空⽂件夹下内容,ls -a 查看还有⼀个影藏⽂件,再次初始化。
[root@iZwz9c74ta983j746ynevpZ hexoblog]# rm ./* -rf
[root@iZwz9c74ta983j746ynevpZ hexoblog]# ls -a
.  ..  .gitignore
[root@iZwz9c74ta983j746ynevpZ hexoblog]# rm .gitignore -f
启动环境
⽣成静态⽂件
[root@iZwz9c74ta983j746ynevpZ hexoblog]# hexo g
[root@iZwz9c74ta983j746ynevpZ hexoblog]# ls -l
total 132
-rw-r--r--  1 root root  2367 Jul 28 15:54 _l
-rw-r--r--  1 root root 25111 Jul 28 15:59 db.json
drwxr-xr-x 189 root root  4096 Jul 28 15:54 node_modules
-rw-r--r--  1 root root  581 Jul 28 15:59 package.json
小小周正面曝光-rw-r--r--  1 root root 74694 Jul 28 15:54 package-lock.json
drwxr-xr-x  7 root root  4096 Jul 28 15:59 public  ## 存放⽣成的静态⽂件
drwxr-xr-x  2 root root  4096 Jul 28 15:54 scaffolds
drwxr-xr-x  3 root root  4096 Jul 28 15:54 source
drwxr-xr-x  3 root root  4096 Jul 28 15:54 themes
启动服务
[root@iZwz9c74ta983j746ynevpZ hexoblog]# hexo s
INFO  Start processing
INFO  Hexo is running at localhost:4000 . Press Ctrl+C to stop.
浏览器访问
localhost:4000
服务器IP地址:4000/
GitHub配置
创建github.io仓储
新建仓库,仓库名为:your_github_user_name.github.io
GitHub Pages(默认已开启)
选择主题
浏览器访问
添加SSH keys(已有忽略)
# ⽣成SSH Key,等待输⼊按下 Enter 回车键三次
ssh-keygen -t rsa
# 复制公钥添加到 github
cat ~/.ssh/id_rsa.pub
汽车轮胎品牌排行榜
测试GitHub连接
有什么好歌曲
[root@iZwz9c74ta983j746ynevpZ hexoblog]# ssh -T git@github
The authenticity of host 'github (52.74.223.119)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
RSA key fingerprint is MD5:16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48.
女星露底照Are you sure you want to continue connecting (yes/no)? yes
Hi JakeLin0fly! You've successfully authenticated, but GitHub does not provide shell access.
设置Github账户信息
git config --global user.name "GitHub⽤户名"
git config --ail "GitHub邮箱"
Hexo部署到GitHub Pages
Hexo _l修改
# Deployment
## Docs: hexo.io/docs/deployment.html
deploy:
type: git
repo: git仓库地址
branch: master
同步到GitHub
需要安装插件 hexo-deployer-git
npm install --save hexo-deployer-git
hexo cl ## 删除 public/  db.json
hexo g ## 构建项⽬主要是⽣成 public/  db.json
hexo d ## 部署到配置⽂件中设置的仓库