使用Hexo搭建个人博客
一. 服务器配置Git
1. 安装依赖库
yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel -y
2. 安装编译工具
yum install gcc perl-ExtUtils-MakeMaker package -y
3. 查看git的版本
# git version
git version 1.8.3.1
4. 安装高版本的Git
yum install http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-1.noarch.rpm -y
yum install http://opensource.wandisco.com/centos/7/git/x86_64/wandisco-git-release-7-2.noarch.rpm -y
5. 更新
yum update git -y
6. 再次查看git的版本
# git version
git version 2.22.0
7. 创建git用户并且修改权限
adduser even
passwd even
chmod 740 /etc/sudoers
vim /etc/sudoers
root ALL=(ALL) ALL
even ALL=(ALL) ALL
8. 本地windows10使用Gitbash创建密钥
ssh-keygen -t rsa
9. 将本地的id_rsa.pub文件复制
su even
mkdir ~/.ssh
vim ~/.ssh/authorized_keys
10. 本地测试
ssh -v even@服务器ip
二. 云服务器网站配置
1. 创建网站目录并且设置权限
su root
mkdir /home/hexo
chown even:even -R /home/hexo
2. 安装Nginx
yum install -y nginx
systemctl start nginx.service
3. 修改Nginx配置文件
vim /etc/nginx/nginx.conf
38 server {
39 listen 80;
40 listen [::]:80;
41 server_name zhou125disorder.icu; #域名
42 root /home/hexo; #网站目录
4. 重启服务器
systemctl restart nginx.service
5. 建立git仓库
su root
cd /home/even
git init --bare blog.git
chown even:even -R blog.git
6. 同步网站根目录
vim blog.git/hooks/post-receive
#/bin/sh
git --work-tree=/home/hexo --git-dir=/home/even/blog.git checkout -f
7. 修改权限
chmod +x /home/even/blog.git/hooks/post-receive;
8. 在windows10本地hexo根目录修改_config.yml文件
deploy:
type: git
repository: even@121.4.48.188:/home/even/blog.git #用户名@服务器Ip:git仓库位置
branch: master
9. 在本机gitbash部署
hexo s
hexo clean
hexo g
hexo d
三. 常见报错
git-upload-pack: 未找到命令
bash: git-upload-pack: command not found
fatal: Could not read from remote repositorqy.
sudo ln -s /usr/local/git/bin/git-upload-pack /usr/bin/git-upload-pack
git-receive-pack: 未找到命令
bash: git-receive-pack: command not found
fatal: Could not read from remote repository.
sudo ln -s /usr/local/git/bin/git-receive-pack /usr/bin/git-receive-pack
无法远程连接获取
fatal: Could not read from remote repository.
重试或者 删掉本地 ssh 公钥重新上传至服务器
key 出错(基本都是这一步出错)
Host key verification failed.
ssh-keygen -R 你要访问的 IP 地址