一、安装Subversion
#yum install subversion
二,基本的SVN服务器配置
1,新建一个目录用于存储SVN所有文件
# mkdir /home/svn
2,新建一个版本仓库
# svnadmin create /home/svn/project
3,初始化版本仓库中的目录
# mkdir project project/server project/client project/test (建立临时目录)
# svn import project/ file:///home/svn/project -m “初始化SVN目录”
# rm -rf project (删除临时建立的目录)
4,添加用户
要添加SVN用户非常简单,只需在/home/svn/project/conf/passwd文件添加一个形如“username=password”的条目就可以了。为了测试,我添加了如下内容:
[users]
# harry = harryssecret
# sally = sallyssecret
pm = pm_pw
server_group = server_pw
client_group = client_pw
test_group = test_pw
5,修改用户访问策略
/home/svn/project/conf/authz记录用户的访问策略,以下是参考:
[groups]
project_p = pm
project_s = server1,server2,server3
project_c = client1,client2,client3
project_t = test1,test1,test1
[project:/]
@project_p = rw
* =
[project:/server]
@project_p = rw
@project_s = rw
* =
[project:/client]
@project_p = rw
@project_c = rw
* =
[project:/doc]
@project_p = rw
@project_s = r
@project_c = r
@project_t = r
* =
说明:以上信息表示,只有project_p用户组有根目录的读写权。r表示对该目录有读权限,w表示对该目录有写权限,rw表示对该目录有读写权限。最后一行的* =表示,除了上面设置了权限的用户组之外,其他任何人都被禁止访问本目录。这个很重要,一定要加上!
6,修改svnserve.conf文件,让用户和策略配置升效.
svnserve.conf内容如下:
[general]
anon-access = none
auth-access = write
password-db = /home/svn/project/conf/passwd
authz-db = /home/svn/project/conf/authz
7,启动服务器
# svnserve -d -r /home/svn
注意:如果修改了svn配置,需要重启svn服务,步骤如下:
注意:配置项所有的行都必须顶格,否则报错。
# ps -aux|grep svnserve
# kill -9 ID号
# svnserve -d -r /home/svn
8,测试服务器
# svn co svn://192.168.60.10/project
Authentication realm: <svn://192.168.60.10:3690> 92731041-2dae-4c23-97fd-9e1ed7f0d18d
Password for ‘root‘:
Authentication realm: <svn://192.168.60.10:3690> 92731041-2dae-4c23-97fd-9e1ed7f0d18d
Username: server_group
Password for ‘server_group‘:
svn: Authorization failed ( server_group没用根目录的访问权 )
# svn co svn://192.168.60.10/project
Authentication realm: <svn://192.168.60.10:3690> 92731041-2dae-4c23-97fd-9e1ed7f0d18d
Password for ‘root’:
Authentication realm: <svn://192.168.60.10:3690> 92731041-2dae-4c23-97fd-9e1ed7f0d18d
Username: pm
Password for ‘pm’:
A project/test
A project/server
A project/client
Checked out revision 1. ( 测试提取成功 )
# cd project/server
# vim main.c
# svn add main.c
# svn commit main.c -m “测试一下我的C程序,看什么看,不行啊??”
Adding main.c
Transmitting file data .
Committed revision 2. ( 测试提交成功 )
三.自动同步
现在是关键的一步,我们需要使我门的测试服务器127.0.0.1进行同步更新:
在/home/svn/project/hooks/目录下建立post-commit文件
#cd /home/svn/project/hooks #vi post-commit 内容如下: #!/bin/sh #设定环境变量,如果没有设定可能会出现update报错 export LANG=zh_CN.GBK #设定语言,根据系统语言设置,如果是UTF-8 就设置为 LANG=zh_CN.UTF-8 SVN_PATH=/usr/bin/svn WEB_PATH=/home/wwwroot/testsvn $SVN_PATH update svn://127.0.0.1/project $WEB_PATH --username 用户名 --password 密码 --no-auth-cache
保存退出
给post-commit 执行权限:
chmod -R 755 post-commit
原文地址:https://www.cnblogs.com/liujie-php/p/10122511.html