安装
安装node.js
安装git
命令行安装cnpm
1 2 3 4 5
| npm install -g cnpm --registry==https://registry.npm.taobao.org
cnpm -v
|
命令行安装hexo
1 2 3 4 5
| cnpm install -g hexo-cli
hexo -v
|
hexo初始化
1 2 3 4 5 6 7 8 9 10 11
| hexo init
hexo init myblog
hexo g
hexo s
|
启动后,打开浏览器访问 http://localhost:4000 即可看到内容.
将博客部署到 github 个人主页上
1
| npm install hexo-deployer-git --save # 安装插件
|
1 2 3 4
| deploy: type: git repository: 'github个人项目链接地址' branch: master
|
1
| hexo clean;hexo g;hexo d
|
搭建好hexo
后,在本地能够正常访问。
使用git
上传到github
后,发现能访问页面,但是不能加载CSS
样式文件和JQuery
文件.
解决方法参考 (177条消息) hexo+Github搭建博客,能访问但无法加载css文件_StarryaSky的博客-CSDN博客
主题选择
选择不同主题进行部署及魔改
部署腾讯云
部署策略:宝塔linux + Git
安装宝塔linux
采用腾讯云宝塔linux版本,用服务器模板,内置安装,省时省力,十分简单
安装git
旧版本足够使用,无需安装最新版。
创建git用户
1 2
| chmod 740 /etc/sudoers vim /etc/sudoers
|
按 i
键进入文件的编辑模式,按向下键找到如下字段
在其后面增加一句:
按 Esc
键退出编辑模式,输入:wq
保存退出。(先输入:
,然后输入wq
回车)
配置秘钥
将id_rsa.pub
里面的密钥复制,在服务器运行下面命令,创建.ssh文件夹
创建.ssh/authorized_keys
文件,打开authorized_keys
文件并将刚才在本地机器复制的内容拷贝其中并保存
1
| vim ~/.ssh/authorized_keys
|
按i
进入编辑模式粘贴完按 Esc
键退出编辑模式,输入:wq
保存退出。(先输入:
,然后输入wq
回车)
1 2 3
| chmod 755 ~ chmod 700 ~/.ssh chmod 600 ~/.ssh/authorized_keys
|
在本地电脑git bash here
1 2
| //yourIp为远程服务器的ip地址 ssh -v git@yourIp //yourIp为你的服务器ip
|
创建git仓库
- 切换到root用户,创建一个目录用于存储网站的根目录
1
| chown git:git -R /www/wwwroot/***
|
自动化部署
1 2
| cd /www/wwwroot/*** git init --bare blog.git
|
1
| chown git:git -R blog.git
|
- 在
/home/hexo/blog.git
下,有一个自动生成的 hooks
文件夹,我们创建一个新的 git
钩子 post-receive
,用于自动部署。
1
| vim blog.git/hooks/post-receive
|
- 按
i
键进入文件的编辑模式,在该文件中添加两行代码(将下边的代码粘贴进去),指定 Git 的工作树(源代码)和 Git 目录
1 2
| #!/bin/bash git --work-tree=/www/wwwroot/*** --git-dir=/www/wwwroot/***/blog.git checkout -f
|
按 Esc
键退出编辑模式,输入:wq
保存退出。(先输入:
,然后输入wq
回车)
1
| chmod +x /www/wwwroot/***/blog.git/hooks/post-receive
|
添加站点

配置_config.yml
1 2 3 4
| deploy: type: git repo: root@***(服务器ip,内网外网都行):/www/wwwroot/***/blog.git #仓库地址 branch: master #分支
|
1 2 3 4 5 6 7
| deploy: - type: git repo: root@***(服务器ip,内网外网都行):/www/wwwroot/***/blog.git #仓库地址 branch: master #分支 - type: git repo: # github仓库地址 branch: master
|
推送
1 2 3
| hexo clean hexo g hexo d
|
输入hexo d
后,推送到服务器需输入服务器密码。
输入密码不会有显示,输完回车就可以
- 如果出现
bash: git-receive-pack: command not found
,则运行:
1
| sudo ln -s /usr/local/git/bin/git-receive-pack /usr/bin/git-receive-pack
|