安装git
在Centos系统上安装git
检测是否安装成功
1 2
| $ git --version git version 1.8.3.1
|
添加git用户
添加公钥
1 2 3 4 5 6 7 8
| su git cd ~ mkdir .ssh chmod 777 .ssh cd .ssh touch authorized_keys chmod 644 authorized_keys vim authorized_keys
|
将公钥id_rsa.pub复制进去
禁止git用户使用ssh登陆
修改
1
| git:x:1000:1000::/home/git:/bin/sh
|
为
1
| git:x:1000:1000::/home/git:/usr/bin/git-shell
|
配置git仓库
1 2
| mkdir /var/repo cd /var/repo
|
初始化git仓库
1
| git init --bare blog.git
|
赋予git用户权限
1
| chown -R git:git blog.git
|
通过git hook将仓库的内容共享到*/data/www/zhanghanlun*目录,
在hook目录下添加post-receive文件
1
| vim /var/repo/blog.git/hooks/post-receive
|
添加如下内容
1 2
| #!/bin/sh git --work-tree=/data/www/zhanghanlun --git-dir=/var/repo/blog.git checkout -f
|
赋予可执行权限
创建/data/www/zhanghanlun并改变该文件夹的用户为git
1 2 3
| mkdir /data/www/zhanghanlun cd /data/www chown -R git:git zhanghanlun
|
配置nginx
nginx配置文件如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
| server { listen 80; listen 443 ssl http2; server_name www.zhanghanlun.com; index index.php index.html index.htm default.php default.htm default.html; root /www/wwwroot/www.zhanghanlun.com; if ($server_port !~ 443){ rewrite ^(/.*)$ https://$host$1 permanent; } ssl_certificate /www/server/panel/vhost/cert/www.zhanghanlun.com/fullchain.pem; ssl_certificate_key /www/server/panel/vhost/cert/www.zhanghanlun.com/privkey.pem; ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_prefer_server_ciphers on; ssl_session_cache shared:SSL:10m; ssl_session_timeout 10m; error_page 497 https://$host$request_uri;
include enable-php-56.conf; include /www/server/panel/vhost/rewrite/www.zhanghanlun.com.conf; location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md) { return 404; } location ~ \.well-known{ allow all; } location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$ { expires 30d; error_log off; access_log /dev/null; } location ~ .*\.(js|css)?$ { expires 12h; error_log off; access_log /dev/null; } access_log /www/wwwlogs/www.zhanghanlun.com.log; error_log /www/wwwlogs/www.zhanghanlun.com.error.log; }
|
修改hexo配置文件
修改_config.yml
1 2 3 4
| deploy: type: git repo: git@IP:/var/repo/blog.git branch: master
|