centos6.5下svn的安装与配置,以及WEB目录同步
系统环境说明如下:
操作系统: Centos6.5 x86-64
SVN: subversion-1.8.11
1、检查是否安装了低版本的SVN
rpm -qa | grep subversion
如果已安装SVN,则会返回版本信息,如:subversion-1.6.11-9.el6_4.i686
卸载旧版本SVN
yum remove subversion
2、安装SVN
yum –y install subversion
3、检查安装是否成功
svnserve –version
返回值:
svnserve, version 1.8.11
compiledJul 23 2013, 21:32:09 on i686-pc-linux-gnu
Copyright (C) 2013 The Apache SoftwareFoundation.
This software consists of contributionsmade by many people;
see the NOTICE file for more information.
Subversion is open source software, see http://subversion.apache.org/
The following repository back-end (FS)modules are available:
* fs_fs : Module for working with a plainfile (FSFS) repository.
Cyrus SASL authentication is available.
4、代码库创建
mkdir -p /opt/svn/repositories
svnadmin create /opt/svn/repositories
执行上面的命令后,自动建立repositories库,查看/opt/svn/repositories 文件夹发现包含了conf,db,format,hooks,locks, README.txt等文件,说明一个SVN库建立完成。
5、配置代码库
进入上面生成的文件夹conf下,进行配置
cd /opt/svn/repositories/conf
5.1用户密码passwd配置
vi passwd
passwd文件的内容如下:
### This file is an example password filefor svnserve.
### Its format is similar to that ofsvnserve.conf. As shown in the
### example below it contains one sectionlabelled [users].
### The name and password for each userfollow, one account per line.
[users]
# harry = harryssecret
# sally = sallyssecret
test = 123456789 ##新增用户的用户名和密码
5.2权限控制authz配置
vi authz
目的是设置哪些用户可以访问哪些目录,authz文件的内容如下:
### This file is an example authorizationfile for svnserve.
### Its format is identical to that ofmod_authz_svn authorization
### files.
### As shown below each section definesauthorizations for the path and
### (optional) repository specified by thesection name.
### The authorizations follow. Anauthorization line can refer to:
### – a single user,
### – a group of users defined in a special [groups] section,
### – an alias defined in a special [aliases] section,
### – all authenticated users, using the ‘$authenticated’ token,
### – only anonymous users, using the ‘$anonymous’ token,
### – anyone, using the ‘*’ wildcard.
###
### A match can be inverted by prefixingthe rule with ‘~’. Rules can
### grant read (‘r’) access, read-write(‘rw’) access, or no access
### (”).
[aliases]
# joe = /C=XZ/ST=Dessert/L=SnakeCity/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average
[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe =harry,sally,&joe
# [/foo/bar]
# harry = rw
# &joe = r
# * =
# [repository:/baz/fuz]
# @harry_and_sally = rw
# * = r
[/]
test = rw
设置[/]代表根目录下所有的资源
5.3服务svnserve.conf配置
vi svnserve.conf
svnserve.conf文件的内容如下:
[general]
#匿名访问的权限,可以是read,write,none,默认为read
anon-access=none
#使授权用户有写权限
auth-access=write
#密码数据库的路径
password-db=passwd
#访问控制文件
authz-db=authz
#认证命名空间,subversion会在认证提示里显示,并且作为凭证缓存的关键字
realm=/opt/svn/repositories
启动svn服务
svnserve -d -r /opt/svn/repositories
6、查看SVN进程
ps -ef|grep svn|grep -v grep
返回
root 20850 1 0 Jul24 ? 00:00:00 svnserve -d -r/opt/svn/repositories
7、查看SVN监听的端口
netstat -ln |grep 3690
8、停止启动SVN
killall svnserve #停止
svnserve -d -r /opt/svn/repositories #启动
9、安装svn客户端
目前最流行的svn客户端非TortoiseSVN莫属
下载安装
http://sourceforge.net/projects/tortoisesvn/files/latest/download?source=dlp
客户端连接地址:svn://公网或内网的IP地址,有时候需要添加端口号
用户名/密码:test/123456789 ##要和之前设置的用户名和密码匹配
注意:
默认端口为3690,如果该端口被占用,或者需要修改端口,使用下面语句
svnserve -d -r /opt/svn/repositories–listen-port 3691
设置钩子
我们知道要把svn的内容更新到web目录需要手动的svn up,但是今天笔者教你自动更新web目录的方法,我们要在svn版本库中配置钩子来实现,就是创建一个post-commit的配置文件,对其进行简单的配置,简简单单的四步就可以实现Linux下SVN自动更新web目录配置。
第一步:建立你的web程序目录
mkdir /var/www/html/test
进入/var/www/html/test目录。
svn checkout svn://121.14.177.178:843/svntest 不重命名文件夹,直接在当前目录下检出
svn checkout svn://121.14.177.178:843/svntest test 检出文件并且重命名文件夹
第二步:在项目库的 hooks/ 目录下新建 post-commit 文件 【钩子脚本】
添加脚本内容如下:
#!/bin/sh
SVN=/usr/bin/svn #这里配置的是svn安装bin目录下的svn文件
WEB=/var/www/html/test #要更新的目录
$SVN update $WEB –username xxx –password xxx (此版本是linux下,windows下是.bat,写法少有不同)
其中SVN=右边改成 svn 命令位置
WEB=右边改成你实际的web目录
第三步:让post-commit有执行的权限 chmod 777 post-commit
第四步:这里就已经完成了,第四步就是测试了。
说明:
#!/bin/sh 说明是执行shell命令
export LANG=zh_CN.GBK 是为了解决svn post commit 中文乱码,设置本地化编码,因为我的系统为GBK编码,SVN默认是UTF-8编码,如果不设置将会出现错误,而执行不成功,错误标识为svn: Can’t convert string from native encoding to ‘UTF-8’
/usr/bin/svn update –username lxy –password 123456 /var/www/myproject 执行更新操作
如果提示:post-commit hook failed (exit code 255) with no output赋予post-commit文件可执行权限
如果您的默认编码就是UTF-8的,要上传中文文件,先将文件另存为UTF-8格式在提交
发表评论