使用svn加rsync进行远程web的更新

  1. 实验架构图如下:

2.实验环境需求(3台主机即可,1台服务器安装svn加rsync,1台web服务器,1台客户端机器)

node2   192.168.21.233    centos 6.6  x64    svn(subversion) + rsync

node5   192.168.21.222    centos 6.6 x64     LAMP(Linux+Apache+MySQL+php)

各软件的作用:svn用来做版本控制的,因为在公司内部上线一个项目时,在多人开发的情况下,都会经过多人修改,此时项目源码的管理就变得非常重要了,在RHEL系列下有这样一款软件svn(subversion)

Subversion is a concurrent version control system which enables one or more users to collaborate in developing and maintaining a hierarchy of files and directories while keeping a history of all changes.  Subversion only stores the differences between versions,instead of every complete file.  Subversion is intended to be a compelling replacement for CVS.

Subversion是一个并发版本控制系统,使一个或多个用户协作开发和维护一个文件和目录的层次结构,同时保持所有更改的历史。Subversion存储版本之间的差异,而不是每一个完整的文件。Subversion确定为强迫替换CVS。

百度百科对CVS的解释:CVS(Concurrent Versions System)版本控制系统是一种GNU软件包,主要用于在多人开发环境下源码的维护。

rsync是用来将编写好的源码同步到远程的web服务器上。

软件包都通过yum方式来安装   yum install package_name

[[email protected] ~]# rpm -q httpd
httpd-2.2.15-39.el6.centos.x86_64
[[email protected] ~]# rpm -q mysql-server
mysql-server-5.1.73-3.el6_5.x86_64
[[email protected] ~]# rpm -q php
php-5.3.3-40.el6_6.x86_64

[[email protected] ~]# rpm -q subversion
subversion-1.6.11-12.el6_6.x86_64
[[email protected] ~]# rpm -q rsync
rsync-3.0.6-12.el6.x86_64

3.配置环境

[[email protected] ~]# rpm -ql subversion
...
/etc/rc.d/init.d/svnserve  服务启动脚本
...
/usr/bin/svn   会常用到的命令
/usr/bin/svnadmin
...

/usr/share/man/man5/svnserve.conf.5.gz  配置文件手册

....

客户端访问服务器时有三种方式:svnserve访问、svnserve和ssh访问、Apache间接访问,这里以svnserve方式来讲解。

svnadmin - Subversion repository administration too  subversion的版本管理工具l    
SYNOPSIS    命令格式
       svnadmin command /path/to/repos [options] [args]
。。。。。。
       Run ‘svnadmin help’ to access the built-in tool documentation.  通过svnadmin查看工具的使用
       
NAME
       svn - Subversion command line client tool     subversion的命令行客户端工具
SYNOPSIS   命令格式
       svn command [options] [args]       
。。。。。
             Run ‘svn help’ to access the built-in tool documentation.   查看命令的文档

[[email protected] ~]# svnadmin help
general usage: svnadmin SUBCOMMAND REPOS_PATH  [ARGS & OPTIONS ...]
Type ‘svnadmin help <subcommand>‘ for help on a specific subcommand.
Type ‘svnadmin --version‘ to see the program version and FS modules.

Available subcommands:     svnadmin help  subcommand查看子命令的使用,比如:svnadmin help create
   crashtest
   create   创建一个新的版本库
   deltify
   dump
   help (?, h)
   。。。

[[email protected] ~]# mkdir /svn/project
[[email protected] ~]# svnadmin create /svn/project   创建一个新的版本库
[[email protected] ~]# ls -l /svn/project
total 24
drwxr-xr-x 2 root root 4096 May 15 08:39 conf
drwxr-sr-x 6 root root 4096 May 15 08:39 db
-r--r--r-- 1 root root    2 May 15 08:39 format
drwxr-xr-x 2 root root 4096 May 15 08:39 hooks
drwxr-xr-x 2 root root 4096 May 15 08:39 locks
-rw-r--r-- 1 root root  229 May 15 08:39 README.txt
[[email protected] ~]# ls /usr/local/nginx-1.4.7/auto/
cc          feature       headers  install  modules  os       summary
define      have          include  lib      nohave   sources  types
endianness  have_headers  init     make     options  stubs    unix
[[email protected] ~]# du -sh /usr/local/nginx-1.4.7/auto/
436K    /usr/local/nginx-1.4.7/auto/
导入源码到版本库中,这里使用nginx的部分源码来举例,使用import子命令
-m [--message] ARG       : specify log message ARG    相当于说明性的子串
[[email protected] ~]# svn import /usr/local/nginx-1.4.7/auto/ file:///svn/project/ -m "Initialization of a project"
Adding         /usr/local/nginx-1.4.7/auto/nohave
Adding         /usr/local/nginx-1.4.7/auto/os
Adding         /usr/local/nginx-1.4.7/auto/os/linux
Adding         /usr/local/nginx-1.4.7/auto/os/win32
.......
Adding         /usr/local/nginx-1.4.7/auto/make
Adding         /usr/local/nginx-1.4.7/auto/have_headers

Committed revision 1.
[[email protected] ~]# svn list file:///svn/project/  列出版本库中有哪些文件
cc/
define
endianness
feature
have
have_headers
headers
include
init
install
lib/
make
modules
nohave
options
os/
sources
stubs
summary
types/
unix
[[email protected] ~]# ls /svn/project/conf/
authz  passwd  svnserve.conf
客户端在访问版本库服务器时,服务器会根据版本库目录下conf/svnserve.conf文件中的定义对用户进行访问控制
[[email protected] ~]# vim /svn/project/conf/svnserve.conf 查看man svnserve.conf有配置文件的详细说明
。。。。  做如下修改
[general]
### These options control access to the repository for unauthenticated
### and authenticated users.  Valid values are "write", "read",
### and "none".  The sample settings below are the defaults.
anon-access = none #设置匿名账号访问权限,这里为none无权限
auth-access = write #经过认证的账户可写
### The password-db option controls the location of the password
### database file.  Unless you specify a path starting with a /,
### the file‘s location is relative to the directory containing
### this configuration file.
### If SASL is enabled (see below), this file will NOT be used.
### Uncomment the line below to use the default password file.
password-db = passwd #账号名称与密码的存放文件名
### The authz-db option controls the location of the authorization
### rules for path-based access control.  Unless you specify a path
### starting with a /, the file‘s location is relative to the the
### directory containing this file.  If you don‘t specify an
### authz-db, no path-based access control is done.
### Uncomment the line below to use the default authorization file.
authz-db = authz #基于路径访问的控制文件名,可以对文件或目录设置权限
### This option specifies the authentication realm of the repository.
### If two repositories have the same authentication realm, they should
### have the same password database, and vice versa.  The default realm
### is repository‘s uuid.
realm = My First Repository  #设置版本库域,如果两个版本库的认证域相同,他们将使用相同的密码数据
[[email protected] ~]# vim /svn/project/conf/passwd    下面给了两个用户

### This file is an example password file for svnserve.
### Its format is similar to that of svnserve.conf. As shown in the
### example below it contains one section labelled [users].
### The name and password for each user follow, one account per line.

[users]
# harry = harryssecret
# sally = sallyssecret
keepalived = keepalived  #用户名 = 密码
haproxy = haproxy
[[email protected] ~]# vim /svn/project/conf/authz
。。。   添加如下内容
[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe
operator = keepalived,haproxy   #指定一个operator组包括了刚才的两个用户

[/]                  #设置版本库的根路径
@operator = rw       #指定组对版本库的访问权限为读写
* = r                 #其他用户的权限,权限可以设置为 只读 ‘r‘  读写‘rw‘  无‘‘
。。。
[[email protected] ~]# ls /svn/project/
conf  db  format  hooks  locks  README.txt
[[email protected] ~]# ls /svn/project/hooks/
post-commit.tmpl          post-unlock.tmpl  pre-revprop-change.tmpl
post-lock.tmpl            pre-commit.tmpl   pre-unlock.tmpl
post-revprop-change.tmpl  pre-lock.tmpl     start-commit.tmpl
在hooks目录下,可以提供一个post-commit的可执行的shell脚本,每当结束对版本库的编辑时,执行commit一下
,即会调用对应版本库中hooks目录下commit脚本执行,这里因为结合rsync来做同步,刚好可以使用到,等会后
面提供脚本的使用内容。

启动svnserve服务
可以用svnserve命令来启动,使用-d选项说明以守护进程方式运行svnserve,-r PATH 为版本库指定一个虚拟
路径,默认svn会将服务器上所有的版本库都共享给用户,使用-r仅发布个别版本给用户,svnserve -d -r /svn/project也可以使用service start svnserve启动svnserve,svnserve默认是监听在tcp的3690端口

客户端访问

svn命令

[[email protected] ~]# svn help
usage: svn <subcommand> [options] [args]
。。。
Available subcommands:   这里()括号中的可以说是简写
   add             #添加文件
   blame (praise, annotate, ann)
   cat             #查看文件的内容
   changelist (cl)   #查看改变的列表
   checkout (co)     #从服务器版本库中复制一份副本到本地
   cleanup
   commit (ci)    #将本地工作副本修改后的内容发布到版本中
   copy (cp)
   delete (del, remove, rm)    #删除文件、目录
   diff (di)             #对比两个版本之间的差别
   export
   help (?, h)
   import    #导入一个源码库到版本库中
   info
   list (ls)    #列出版本库中的文件
   lock
   log
   merge
   mergeinfo
   mkdir

其他的子命令使用到都可以查看帮助手册的,svn help  subcommand

[[email protected] ~]# svn checkout file:///svn/project nginx_source
A    nginx_source/nohave
A    nginx_source/os
A    nginx_source/os/linux
A    nginx_source/os/win32
A    nginx_source/os/darwin
A    nginx_source/os/conf
A    nginx_source/os/freebsd
A    nginx_source/os/solaris
A    nginx_source/unix
。。。
[[email protected] ~]# vim /svn/project/hooks/post-commit    这里通过post-commit脚本

#!/bin/bash
REPOS="$1"    #版本库的绝对路径
REV="$2"      #对应更新到的版本号

DIR="/root/nginx_source"
export LC_ALL=en_US.UTF-8
export LANG=zh_CN.UTF-8
CURDATE=`/bin/date`
#用来记录日志
echo "Code Deployed by at $CURDATE,$REPOS,$REV" >> /root/nginx_change.log
#当版本库发生改变时,把更新写入到副本当中
/usr/bin/svn update $DIR --username keepalived --password keepalived --no-auth-cache 2>1 /root/nginx_update.log
#使用rsync同步项目到web服务器上
/usr/bin/rsync -r -e ssh --stats --progress $DIR [email protected]:/var/www/html

这里rsync同步时需要输入远程主机的密码,所以我们可以通过密钥来进行认证,

[[email protected] ~]#ssh-keygen -t rsa -P ‘‘

[[email protected] ~]#ssh-copy-id -i .ssh/id_rsa.pub [email protected]

在windows上面操作时,需要安装一个软件TortoiseSVN,这里提供一个下载路径是英文版的http://pan.baidu.com/s/1ntoU1jN  ,下载后安装,安装好后,在桌面上右击时选择(SVN检出或者SVN Checkout)

接下来就可以打开文件进行操作了,我们修改cc目录下的gcc文件,在第5行添加了(hello    Eventyone)和第33行添加了(Hello world!),在cc目录下的owc文件中第10行到第15行的内容

# maximize speed
CFLAGS="$CFLAGS -ot"
# reorder instructions for best pipeline usage
CFLAGS="$CFLAGS -op"
# inline intrinsic functions
CFLAGS="$CFLAGS -oi"     都删除了

而后在project文件夹上右击,选择SVN Commit。。。进行commit操作

[[email protected] ~]# svn cat file:///svn/project/cc/gcc | head -5   发现已经更新了

# Copyright (C) Igor Sysoev
# Copyright (C) Nginx, Inc.

hello    Eventyone
[[email protected] ~]# svn cat file:///svn/project/cc/gcc | head -35 | tail -5    两个文件都更新成功
. auto/feature

Hello world£?
CC_TEST_FLAGS=

[[email protected] ~]# ls /var/www/html/   这里远程也已经把文件同步过来了
nginx_source
[[email protected] ~]# ls /var/www/html/nginx_source/
cc          feature       headers  install  modules  os       summary
define      have          include  lib      nohave   sources  types
endianness  have_headers  init     make     options  stubs    unix

下面通过新增几个文件,查看一下效果,在project目录下新建了两个.txt的文件zabbixtxt、openstack.txt,并在openstack.txt文件添加了如下内容:

Migrating to the cloud

Hello,Openstack

ok,现在进行commit操作

[[email protected] ~]# svn list file:///svn/project
cc/
define
endianness
feature
have
have_headers
headers
include
init
install
lib/
make
modules
nohave
openstatck.txt.txt
options
os/
sources
stubs
summary
types/
unix
zabbix.txt.txt
[[email protected] ~]# svn cat file:///svn/project/openstatck.txt.txt
Migrating to the cloud

Hello£?Openstack[[email protected] ~]# 

[[email protected] ~]# ls /var/www/html/nginx_source/
cc          feature       headers  install  modules             options  stubs    unix
define      have          include  lib      nohave              os       summary  zabbix.txt.txt
endianness  have_headers  init     make     openstatck.txt.txt  sources  types
[[email protected] ~]# cat /var/www/html/nginx_source/openstatck.txt.txt 
Migrating to the cloud

Hello£?Openstack[[email protected] ~]#    发现一切都ok,就介绍到此

有兴趣可以自己好好研究研究,有什么错误系统大家可以指正,谢谢阅读

时间: 2024-08-13 19:36:55

使用svn加rsync进行远程web的更新的相关文章

SVN中基于Maven的Web项目更新到本地过程详解

环境 MyEclipse:10.7 Maven:3.1.1 概述 最近在做项目的时候,MyEclipse下载SVN上面基于Maven的Web项目总是出现很多问题,有时候搞了很半天,Maven项目还是出现叉号,最后总结了方法步骤,终于可以将出现的问题解决,在此,将重现从SVN上将基于Maven的Web项目变成本地MyEclipse中项目的过程,问题也在其中进行解决. 问题补充 在使用Myeclipse的部署Web项目的时候,在点击部署按钮的时候,没有任何反应,在此提供两种解决方法,问题如图1所示:

svn 结合rsync 的代码发布系统

由开发提交到测试环境,经测试,在由运维统一上线.试验需求一台测试服务器,一台线上(生产环境)服务器.测试服务器上跑svn是开发用于代码管理,而线上跑的svn是运维用来代码上线的.结合rsync保持测试端的代码与 svn的线上控制端(线上svn,在测试服务器上的一个workcopy)的代码保持一致.开发结合运维,并由运维周期性的提交代码,如果有问题,回滚,保证线上正常!! svn服务器上chackout 一个workcopy 在用户端:(注意防火墙) [[email protected] ~]#

Rsync(远程同步): inux中Rsync命令的实际示例

rsync的 ( 远程同步 )为在Linux / Unix系统局部 拷贝和同步文件和目录远程以及一个最常用的命令. 随着rsync命令的帮助,您可以复制并在目录中远程和本地同步数据,在磁盘和网络,进行数据备份和两台Linux机器之间的镜像. Rsync本地和远程文件同步 本文介绍rsync命令的10个基本和高级的用法在基于Linux的机器远程和本地传输文件. 你并不需要以root用户运行rsync命令. Rsync命令的一些优点和功能 它有效地将文件复制到远程系统或从远程系统同步. 支持复制链接

第三章 rsync通过远程ssh实现数据备份

第三章 rsync通过远程ssh实现数据备份 通过远程shell访问,实现数据同步备份 拉--即将远程服务器上的数据同步到本地服务器上. 推--即将本地服务器上的数据同步到远程服务器上. 语法格式: 拉操作==>     rsync   选项    用户名@备份源服务器IP地址:备份源目录    目标目录 推操作==>     rsync   选项    备份源目录    用户名@目标服务器IP地址:目标目录 环境: 本地服务器为:DataServer.  IP地址为:192.168.88.8

Microsoft Visual Studio 2008 未能正确加载包“Visual Web Developer HTML Source Editor Package” | “Visual Studio HTM Editor Package”

在安装Microsoft Visual Studio 2008 后,如果Visual Studio 2008的语言版本与系统不一致时,比如:在Windows 7 English System 安装Visual Studio 2008 简体中文时,启动Visual Studio 2008就会报错. 报错信息: ---------------------------Microsoft Visual Studio---------------------------包加载失败 未能正确加载包“Visu

通过脚本判断远程Web服务器状态码是否正常

通过脚本判断远程Web服务器状态码是否正常 说明: (1)生产环境常见的HTTP状态码列表,请查看我的博文:http://wutengfei.blog.51cto.com/10942117/1934645 (2)实验中远程nginx服务器IP地址:192.168.100.114 本地客户端IP地址:192.168.100.118 脚本如下 方法1:if #!/bin/bash httpcode=`curl -I -s 192.168.100.114|head -1|cut -d " "

MVC中未能加载程序集System.Web.Http/System.Web.Http.WebHost

需要检查项目的Microsoft.AspNet.WebApi版本是否最新,System.Web.Http 这个命名空间需要更新WebApi版本. 报错:未能加载程序集 System.Web.Http/System.Web.Http.WebHost NuGet>程序包管理器控制台:没有的话,需要安装:Install-Package Microsoft.AspNet.WebApi有的话,需要更新:Update-Package Microsoft.AspNet.WebApi -reinstall原因:

SVN加载项目失败

我们在开发项目的时候,总是会遇到SVN加载项目失败的问题: 一.产生问题的原因: 这个时候,我们知道出现这个问题就是因为这个项目中出现了冲突,当开发人员A和开发人员B从版本库同时检出文档1.txt,而A和B同时修改了1.txt的同一地方,后提交的一方会在拷贝副本中产生冲突.两个工作拷贝,A拷贝中文件1.txt内容为 dfqerq 123dfwre B拷贝中文件1.txt内容为 dfqerq 123erwrq 在B版本提交之前版本库上的1.txt(base版本)内容为 dfqerq B拷贝先提交版

Linux下SVN部署/安全及权限配置,实现web同步更新

转自:http://www.cnblogs.com/me115/archive/2013/04/07/3002058.html 本文包含以下内容: SVN服务器安装 SVN权限管理 SVN使用SASL加密 SVN上传时同步其它目录 需求 在WEB线上版本管理的基础上,能够在代码上传之后,立刻通过WEB访问,查看修改效果:同时,保证数据的安全性: SVN安装 SVN服务器有2种运行方式:独立服务器和借助apache运行. svnserve和apache相比是轻量级的,也比较简单,svnserve包