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

1、进入线上git裸仓库

git自动化部署+rsync文件同步_第1张图片

 

2、编辑post-receive

#!/bin/sh
unset GIT_DIR
cd /var/www/
git pull http://web:[email protected]: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 [email protected]::rhel4home /var/www/html

  

说明:

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

 

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

你可能感兴趣的:(git自动化部署+rsync文件同步)