思路:svn服务器钩子触发rsync同步脚本,同步web服务器上的rsync定义的模块。
=============================WEB服务器(RSYNC)=========================== 第一步:安装rsync yum -y install rsync 第二步:配置 #默认无该文件 #vim /etc/rsyncd.conf uid=root gid=root use chroot=no max connections=200 timeout=600 pid file=/var/run/rsyncd.pid lock file=/var/run/rsync.lock log file=/var/log/rsyncd.log [a.test.cn] path=/data/web/a.test.cn/ #exclude=conf/*.php comment = this ia a.test.cn read only=false list=false hosts allow=172.31.0.12 hosts deny=* auth users=test secrets file=/shell/rsync-passwd/rsync.passwd 注:use chroot=no 时,同步后DES的文件主或组如果有,则显示名,即使ID不一样; use chroot=yes时,如果两台机器同名的ID不同,则服务端只会显示SRC的ID,造成权限问题。 编辑rsync的用户认证配置文件 # cat /shell/rsync-passwd/rsync.passwd test:test123 #chmod 600 /shell/rsync-passwd/rsync.passwd 第三步:启动rsync服务 /usr/bin/rsync --daemon echo "/usr/bin/rsync --daemon" >>/etc/rc.local 第四步:客户端测试(172.31.0.12上) # cat /shell/rsync-passwd/rsync.passwd test:test123 #chmod 600 /shell/rsync-passwd/rsync.passwd rsync -vzrtopgl --progress --delete --exclude=.svn /data/web/a.test.cn/ test@172.31.0.15::a.test.cn --password-file=/shell/rsync-passwd/rsync.passwd 或 RSYNC_PASSWORD=test123 rsync -vzrtopgl --progress --delete --exclude=.svn /data/web/a.test.cn/ test@172.31.0.15::a.test.cn (完成) 注:修改配置文件和用户密码不需要重启服务
==============================SVN服务器================================= 第一步:安装subversion tar zxvf subversion-1.7.4.tar.gz cd subversion-1.7.4 #下载apr,并执行buildconf生成需要的文件 svn co http://svn.apache.org/repos/asf/apr/apr/branches/1.3.x apr ./apr/buildconf #下载apr-util,并执行buildconf生成需要的文件 svn co http://svn.apache.org/repos/asf/apr/apr-util/branches/1.3.x apr-util ./apr-util/buildconf #下载sqlite3.c,解压后放到subversion解压的源码目录中,只确保有sqlite3.c即可。 # ll sqlite-amalgamation/ total 5004 -rw-r--r-- 1 root root 5121966 Dec 17 11:34 sqlite3.c ./configure --prefix=/usr/local/svn make && make install 第二步:创建svn库、配置好权限 1、创建库 mkdir /data/svndata /usr/local/svn/bin/svnadmin create /data/svndata/a.test.cn /usr/local/svn/bin/svnadmin create /data/svndata/b.test.cn /usr/local/svn/bin/svnadmin create /data/svndata/c.test.cn 2、配置密码和权限文件 mkdir /data/svnpasswd #cat /data/svnpasswd/passwd [users] aaa=aaapwd bbb=bbbpwd ccc=cccpwd xxx=xxxpwd yyy=yyypwd zzz=zzzpwd #cat /data/svnpasswd/authz [groups] a.test.cn = aaa b.test.cn = bbb c.test.cn = ccc other = xxx,yyy,zzz [a.test.cn:/] @a.test.cn=r w xxx=r *= [b.test.cn:/] @b.test.cn=rw yyy=r *= [c.test.cn:/] @c.test.cn=rw @other=r *= 3、配置所有svn库使用上面的用户和权限来集中管理权限。 修改所有库中的conf/svnserve.conf为以下内容 [general] anon-access = none auth-access = write password-db = /data/svnpasswd/passwd authz-db = /data/svnpasswd/authz # realm = My First Repository # force-username-case = none [sasl] # use-sasl = true # min-encryption = 0 # max-encryption = 256 4、启动服务 /usr/local/svn/bin/svnserve -d --listen-port 4399 -r /data/svndata echo "/usr/local/svn/bin/svnserve -d --listen-port 4399 -r /data/svndata" >>/etc/rc.local 5、配置钩子文件(第个库根据需要单独的配置)原理:每次commit,触发post-commit脚本。确保有执行权限。 拷贝模板文件为post-commit chmod 700 post-commit [root@centos-6 ~]# cat /data/svndata/ a.test.cn/hooks/post-commit #!/bin/sh #下面这个变量实际上是svn库的绝对路径,未使用。 #REPOS="$1" #下面这个变量实际上是每次commit后的版本,未使用。 #REV="$2" export LANG=en_US.UTF-8 /usr/local/svn/bin/svn up /data/web/a.test.cn if [ $? -eq 0 ] then chown -R root.dev /data/web/a.test.cn /bin/bash /shell/rsync-script/a.test.cn.sh > /dev/null 2>&1 fi 6、配置钩子文件触发的脚本 [root@centos-6 ~]# cat /shell/rsync-script/a.test.cn.sh #/bin/bash IP="172.31.0.15" Auth_module="a.test.cn" Localdir="/data/web/a.test.cn/" Auth_user="test" Passwd_file="/shell/rsync-passwd/rsync.passwd" Exc=" --exclude=.svn" rsync -vzrtopgl --progress --delete ${Exc} ${Localdir} $Auth_user@${IP}::${Auth_module} --password-file=${Passwd_file} 访问rsync密码文件,权限必须为600,root.root [root@centos-6 ~]# cat /shell/rsync-passwd/rsync.passwd test123 7、测试 客户端在a.test.cn库中提交文件,查看是否实时同步到rsync服务器定义的web目录中。 (完成) 注:添加库、修改权限、密码等不需要重启服务。
转载于:https://blog.51cto.com/sndapk/1360384