rsync 推送

两遍服务器都安装好rsync后  如果做推送服务 被推送的服务器的 配置文件 注意事项

1服务端(192.168.1.241)配置的密匙文件 格式为【运行环境】

 用户名:密码

root:123456

2 客户端(192.168.1.240)配置的密码文件[git代码托管]

密码

123456

 客户端测试推送到服务器端

 rsync -vzrtopg --delete --progress --password-file=/etc/rsyncd/rsyncd.secrets /var/opt/gitlab/git-data/gitlab-satellites/ranmufei/linksame/ root@192.168.1.241::linksame

环境服务器上面有两个 模块

(1) linksame

 (2)  apps

 inotufy 及时监控git代码修改 并推送到 服务器

/usr/local/inotify/rsync.sh 

#!/bin/sh
srcdir=/var/opt/gitlab/git-data/gitlab-satellites/ranmufei/linksame/ #源服务器地址
dstdir=linksame #241 目标服务器
rsyncuser=root #目标服务器用户名
rsyncpassdir=/etc/rsyncd/rsyncd.secrets #目标服务器密码
dstip="192.168.1.241" #目标服务器ip
for ip in $dstip
do
rsync -avH --port=873 --progress --delete $srcdir $rsyncuser@$ip::$dstdir --password-file=$rsyncpassdir
done
/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,modify,delete,create,attrib,move $srcdir | while read file
do
for ip in $dstip
do
rsync -avH --port=873 --progress --delete $srcdir $rsyncuser@$ip::$dstdir --password-file=$rsyncpassdir
echo " ${file} was rsynced" >> /tmp/rsync.log 2>&1
done
done

启动

   #nohup /bin/bash /root/rsync.sh &

   
开机自启动

   #echo "nohup /bin/bash /root/rsync.sh &" >> /etc/rc.local

 监听本机多个文件夹下的文件单独创建监听文件 加入开机启动即可

#!/bin/sh
srcdir=/var/opt/gitlab/git-data/gitlab-satellites/ranmufei/linksame/ #源服务器地址
srcdir2=/var/opt/gitlab/git-data/gitlab-satellites/ranmufei/apps/ #源服务器地址
dstdir=linksame #241 目标服务器
dstdir2=apps #241 目标服务器
rsyncuser=root #目标服务器用户名
rsyncpassdir=/etc/rsyncd/rsyncd.secrets #目标服务器密码
dstip="192.168.1.241" #目标服务器ip

##################linksame###############
rsync -avH --port=873 --progress --delete $srcdir $rsyncuser@$dstip::$dstdir --password-file=$rsyncpassdir


/usr/local/inotify/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e close_write,modify,delete,create,attrib,move $srcdir | while read file
do

rsync -avH --port=873 --progress --delete $srcdir $rsyncuser@$dstip::$dstdir --password-file=$rsyncpassdir
echo " ${file} was rsynced" >> /tmp/rsync.log 2>&1

done

 一键安装包 服务器端 并没有安装git命令  如果要在服务器上面使用git 请单独安装 git

yum install -y git

参考

  http://www.osyunwei.com/archives/7435.html

原文地址:https://www.cnblogs.com/freefei/p/3979348.html