git自动化部署+rsync文件同步

1、进入线上git裸仓库

 

2、编辑post-receive

#!/bin/sh
unset GIT_DIR
cd /var/www/
git pull http://web:xxxxxxx@120.31.131.xxx:8099/root/withdraw_api.git

3、使用rsync
①、服务器端 A (192.168.48.128)

yum -y install rsync # 安装rsync同步服务
echo "root:root" > /etc/rsyncd.secrets #账号密码
chmod 600 /etc/rsyncd.secrets #这一步不可缺少,不然会报错。

  

# 编辑配置文件 /etc/rsyncd.conf

pid file = /var/run/rsyncd.pid 
port = 873
address = 192.168.48.128 # 绑定本机ip
uid = root 
#gid = root 
use chroot = yes 
read only = yes 
#limit access to private LANs
#hosts allow=192.168.1.0/255.255.255.0 10.0.1.0/255.255.255.0 
#hosts deny=*
max connections = 5 
#motd file = /etc/rsyncd.motd
#This will give you a separate log file
#log file = /var/log/rsync.log
#This will log every file transferred - up to 85,000+ per user, per sync
#transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
#模块名 配置同步的文件目录
[rhel4home] 
path = /var/www/html/ 
list=yes 
ignore errors 
auth users = root
secrets file = /etc/rsyncd.secrets 
comment = This is RHEL 4 data 
#exclude = easylife/ samba/ #排除要同步的目录

 

#添加端口放行
/sbin/iptables -I INPUT -p tcp --dport 873 -j ACCEPT

②、客户端 B(192.168.48.129)

yum -y install rsync # 安装rsync同步服务
# 客户端密码 /etc/rsyncd.secrets(仅保留明文密码就行)
root
rsync -auv --password-file=/etc/rsyncd.secrets root@192.168.48.128::rhel4home /var/www/html

  

说明:

客户端git推送文件到线上master裸仓库会触发git钩子并执行定义好的脚本同步拉取最新代码到项目部署目录
rsync作用是多台服务器同步一套代码

 

转载于:https://www.cnblogs.com/zc123/p/9133785.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值