Centos7 搭建Git服务器 并同步代码
目的是 自己看得懂就好了
centos7.2 环境下
安装git
yum install git
useradd www 一般为网站web前端管理目录
生成www用户的私钥密钥
cd /home/www/.ssh
进入生产密钥的.ssh目录
创建 authorized_keys 文件 将 公钥 写入 authorized_keys
注意 .ssh/config 700 .ssh 700 authorized_keys 600 非常重要
配置网站脚本
addweb.sh
./addweb.sh www.luofq.com 127.0.0.1(测试站IP)
1 git 空仓库 www.luofq.com.git
2 通过ssh访问 IP 127.0.0.1 创建 更新测试站代码的文件
测试站中
创建 一个 git_pull_www.luofq.com_dev.sh 用于配合正式站钩子文件 进行更新
创建 www.luofq.com 文件夹用于存放测试站前端代码
创建 t.www.luofq.com.conf nginx 配置域名解析文件
后重启 nginx
3 创建 www.luofq.com.git/hooks 钩子文件 post-receive 777 此钩子文件用于同步测试站代码
格式为 ssh 127.0.0.1 '/home/wwwroot/git_pull_www.luofq.com_dev.sh'
git --work-tree=/www/wwwroot/www.luofq.com checkout -f
创建 www.luofq.com.conf nginx 配置域名解析文件
创建 git_pull_www.luofq.com_master.sh 用于更新正式站代码 (只能手动更新)
重启nginx
输出 git仓库地 址
1 按道理说 正式站测试站环境安装好后
域名也解析过去了
正式服务器 指向 addweb.sh www.luofq.com 127.0.0.1
自动创建git仓库
本地拉去git地址 创建dev分支 推送到线上
测试服自动拉去的dev分支代码
正式服 指向 git_pull_www.luofq.com_master.sh 后 也可以正常访问
想法很美好 也实现了 很美好
评论已关闭