本来博客是部署在github上的,但是耐不住网络不稳定,所以就决定在自己的树莓派上也部署一套。
Hexo本地安装步骤:
略。
Hexo服务端安装步骤:
搭建Git服务
1.安装Git
1
| [root@localhost ~]# yum install git
|
2.创建Git用户并配置博客仓库
1 2 3 4 5 6 7 8
| [root@localhost ~]# useradd git [root@localhost ~]# passwd git // 设置密码 [root@localhost ~]# su - git // 这步很重要,不切换用户后面会很麻烦 [git@localhost ~]# mkdir -p hexo/blog // 博客的真实目录 [git@localhost ~]# mkdir repos && cd repos [git@localhost ~]# git init --bare blog.git // 创建一个裸露的仓库 [git@localhost ~]# cd blog.git/hooks [git@localhost ~]# vi post-receive // 创建 hook 钩子函数,输入了内容如下
|
1 2
| #!/bin/sh git --work-tree=/home/git/projects/blog --git-dir=/home/git/repos/blog.git checkout -f
|
文件保存后赋权:
1
| [git@localhost ~]# chmod +x post-receive
|
3.在本地测试git库是否可用
1
| git clone git@server_ip:/home/git/repos/blog.git
|
4.禁用git用户shell登录权限
1 2 3 4
| [root@localhost ~]# cat /etc/shells // 查看 git-shell 是否在登录方式里面 [root@localhost ~]# which git-shell // 查看是否安装 [root@localhost ~]# vi /etc/shells 添加上2步显示出来的路劲,通常在 /usr/bin/git-shell
|
修改/etc/passwd中的权限
1 2 3 4 5
| // 将原来的 git:x:1000:1000::/home/git:/bin/bash
// 修改为 git:x:1000:1000::/home/git:/usr/bin/git-shell
|
搭建nginx服务
1.安装依赖库
1 2
| [root@localhost ~]# yum -y install make zlib zlib-devel gcc-c++ libtool openssl openssl-devel [root@localhost ~]# yum -y install wget
|
2.下载并安装nginx
1 2 3 4 5 6 7
| [root@localhost ~]# cd /usr/local/src [root@localhost ~]# wget http://nginx.org/download/nginx-1.16.1.tar.gz [root@localhost ~]# tar -xzvf nginx-1.16.1.tar.gz [root@localhost ~]# cd nginx-1.16.1 [root@localhost ~]# ./configure [root@localhost ~]# make && make install [root@localhost ~]# alias nginx='/usr/local/nginx/sbin/nginx' // 为 nginx 取别名,后面可直接用
|
3.开放80端口
1 2 3
| [root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent // 添加80端口 [root@localhost ~]# firewall-cmd --reload // 重载防火墙服务 [root@localhost ~]# firewall-cmd --list-ports // 查看开放的端口列表
|
4.启动nginx验证是否安装成
1
| [root@localhost ~]# nginx // 直接来!浏览器查看 server_ip,默认是 80 端口
|
5.修改网站目录
1 2 3 4 5
| nginx -s stop // 先停止nginx cd /usr/local/nginx/conf vi nginx.conf 修改 root 解析路径,如下图 同时将 user 改为 root 如下图,不然nginx无法访问 /home/git/hexo/blog
|
6.启动nginx服务
1
| [root@localhost ~]# nginx
|
配置本地_config.yml文件
1.修改deploy属性:
2.部署到服务器
1 2 3
| hexo clean hexo generate hexo deploy
|
Tips:由于我未配置ssh免密信任,所以部署时会提示需要输入密码。
至此,博客已可正常访问!
参考资料:
- 《带你跳过各种坑,一次性把 Hexo 博客部署到自己的服务器》
- 《Nginx 安装配置》