CentOS部署svn服务器

作为一个企业级别的代码管理工具,svn应该是很多人都用过的,在此介绍独立服务器版本svn的部署环境
如果是局域网环境,在配好yum本地数据源后,就可以直接使用yum方式安装

安装

1
yum -y install subversion

检查&&帮助

1
2
svnserve --version
svn --help

配置

  1. 创建版本模板库

    1
    2
    mkdir -p /opt/svnroot/SvnBlank
    svnadmin create /opt/svnroot/SvnBlank/
  2. 模板库文件配置

    1
    2
    3
    4
    5
    6
    7
    8
    vim /opt/svnroot/SvnBlank/conf/svnserve.conf
    #匿名用户无操作权限,授权用户可读写,项目账号使用各自项目文件,账号口令文件统一使用模板文件
    anon-access = none
    auth-access = write
    #在这里模板项目使用自己的用户配置文件,这对项目的权限控制比较方便
    authz-db = authz
    #/各个项目的用户账号密码信息统一使用一份
    password-db = /opt/svnroot/SvnBlank/conf/passwd
  3. 账号设置

    1
    2
    3
    4
    5
    6
    vim /opt/svnroot/SvnBlank/conf/passwd
    #用户名=密码
    [users]
    huangchentao=123456
    admin=admin
    test=test

权限设置

1
2
3
4
5
6
7
8
9
10
11
12
vim /opt/svnroot/SvnBlank/conf/authz
#首先分组,祖名=成员1,成员2...
#分目录权限 admin组对根目录有读写权限,trunk目录test组只有读的权限
[groups]
group_root=admin,huangchentao
group_test=test
[/]
@group_root=rw
[/trunk]
@group_test=r

运行

1
2
3
4
5
svnserve -d -r /opt/svnroot/
#启动多个,使用另一端口
svnserve -d -r /opt/svnroot/ --listen-port 3391
#开机自动运行
在/etc/rc.d/rc.local 添加 “/usr/bin/svnserve -d -r svn版本库目录”

停止

1
2
ps -ef | grep svnserver
kill -9 process-id

查看使用端口

1
netstat -anp | grep svnserve

钩子自动更新

说明,在开发时经常需要提交代码,如果使用钩子自动更新的话,只要有人提交后就能自动更新到服务器上,非常方便哦。

首先必须对代码目录checkout

1
2
3
4
5
6
7
8
[root@localhost ~]# cd /var/www
[root@localhost www]# svn checkout svn://192.168.1.100/project01
Authentication realm: 21d46c22-96a8-465b-9d0b-58a1e04abdfd
Password for 'root':
Authentication realm: 21d46c22-96a8-465b-9d0b-58a1e04abdfd
Username: test1
Password for 'test1':
Checked out revision 0.

这样在 /var/www/ 中会生成一个目录 project01,我们可以把这个目录设置成站点来访问。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
进入版本库hooks目录
将post-commit.tmpl 模板复制一份 取名post-commit
在末尾加上
svn up /home/svn/project01/ –username test1 –password 123456
并赋予执行权限。
[root@localhost ~]# cd /home/svn/project01/hooks/
[root@localhost hooks]# ls
post-commit.tmpl post-revprop-change.tmpl pre-commit.tmpl pre-revprop-change.tmpl start-commit.tmpl
post-lock.tmpl post-unlock.tmpl pre-lock.tmpl pre-unlock.tmpl
[root@localhost hooks]# cp post-commit.tmpl post-commit
[root@localhost hooks]# vim post-commit
REPOS="$1"
REV="$2"
svn up /home/svn/project01/ --username test1 --password 123456
[root@localhost hooks]# chmod +x post-commit

这样当用户提交文件的第时候,svn将会自动执行更新,使代码同步。

文章目录
  1. 1. 安装
  2. 2. 检查&&帮助
  3. 3. 配置
  4. 4. 权限设置
  5. 5. 运行
  6. 6. 停止
  7. 7. 查看使用端口
  8. 8. 钩子自动更新
,