将Hexo搭建到自己的服务器上
GitHub部署的教程网上多的很,我就不写了
第一部分:服务器端的操作
yum install -y nginx git
2.添加一个git用户
#添加用户
useradd git
#设置密码
passwd git
# 给git用户配置sudo权限
chmod 740 /etc/sudoers
#编辑sudoers配置文件
vim /etc/sudoers
# 找到root ALL=(ALL) ALL,在它下方加入一行 一般在文件文件最下方
git ALL=(ALL) ALL
chmod 400 /etc/sudoers
3.给git用户添加ssh密钥
su - git
mkdir -p ~/.ssh
touch ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorzied_keys
chmod 700 ~/.ssh
vim ~/.ssh/authorized_keys #将ssh密钥粘贴进去
[服务器上的 Git – 生成 SSH 公钥] —>>> 教程地址 <<<—
[获取密钥过程详解] —>>> 教程地址 <<<—
4.创建git仓库实现自动部署
创建git仓库并使用git-hooks实现自动部署
sudo mkdir -p /var/repo #新建目录,这是git仓库的位置
sudo mkdir -p /var/www/hexo
cd /var/repo #转到git仓库的文件夹
sudo git init --bare blog.git #创建一个名叫blog的仓库
sudo vim /var/repo/blog.git/hooks/post-update
post-update
的内如如下:
#!/bin/bash
git --work-tree=/var/www/hexo --git-dir=/var/repo/blog.git checkout -f
给post-update授权
cd /var/repo/blog.git/hooks/
sudo chown -R git:git /var/repo/
sudo chown -R git:git /var/www/hexo
sudo chmod +x post-update #赋予其可执行权限
5.配置nginx
cd /etc/nginx/conf.d/
vim blog.conf
blog.conf
的内如如下:
server {
listen 80 default_server;
listen [::] default_server;
server_name 127.0.0.1;#可以写自己的域名
root /var/www/hexo;
}
检查Nginx语法并重载nginx:
nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
nginx -s reload
6.修改git用户的默认shell环境
vim /etc/passwd
#修改最后一行
#将/bin/bash修改为/usr/bin/git-shell
git:x:1002:1002::/home/git:/usr/bin/git-shell
7.解析域名
到购买域名的供应商控制台,将域名解析到自己的服务器即可。
后面的写不下来,感兴趣的可以去看看
↓↓↓↓↓↓
链接
感谢分享,66666