[关闭]
@52fhy 2015-11-28T12:48:44.000000Z 字数 4884 阅读 469

CentOS下的SVN服务器搭建

Linux


1 yum安装svn

yum方式安装比较简单。重点是配置。默认安装会包含客户端。

  1. yum install -y subversion

等待一会儿,显示下边的内容:

  1. #省略部分内容
  2. Total 982 kB/s | 2.5 MB 00:02
  3. Running rpm_check_debug
  4. Running Transaction Test
  5. Transaction Test Succeeded
  6. Running Transaction
  7. Installing : perl-URI-1.40-2.el6.noarch 1/7
  8. Installing : libproxy-bin-0.3.0-10.el6.i686 2/7
  9. Installing : libproxy-python-0.3.0-10.el6.i686 3/7
  10. Installing : libproxy-0.3.0-10.el6.i686 4/7
  11. Installing : pakchois-0.4-3.2.el6.i686 5/7
  12. Installing : neon-0.29.3-3.el6_4.i686 6/7
  13. Installing : subversion-1.6.11-15.el6_7.i686 7/7
  14. Installed:
  15. subversion.i686 0:1.6.11-15.el6_7
  16. Dependency Installed:
  17. libproxy.i686 0:0.3.0-10.el6 libproxy-bin.i686 0:0.3.0-10.el6 libproxy-python.i686 0:0.3.0-10.el6 neon.i686 0:0.29.3-3.el6_4
  18. pakchois.i686 0:0.4-3.2.el6 perl-URI.noarch 0:1.40-2.el6
  19. Complete!

2 验证是否安装完成

  1. svnserve --version

这是我的显示内容:

  1. svnserve,版本 1.6.11 (r934486)
  2. 编译于 Aug 17 201508:21:51
  3. 版权所有 (C) 2000-2009 CollabNet
  4. Subversion 是开放源代码软件,请参阅 http://subversion.tigris.org/ 站点。
  5. 此产品包含由 CollabNet(http://www.Collab.Net/) 开发的软件。
  6. 下列版本库后端(FS) 模块可用:
  7. * fs_base : 模块只能操作BDB版本库。
  8. * fs_fs : 模块与文本文件(FSFS)版本库一起工作。
  9. Cyrus SASL 认证可用。

3 创建svn版本库

  1. mkdir /data/svn #我这里把版本库放在了data目录下的svn文件夹,方便管理
  2. svnadmin create /data/svn/repo
  3. #我这里将svn作为所有版本库的目录,并创建了一个名为repo的版本库。创建其它版本库与此类似。

4 配置当前的版本库

创建版本库后,在当前版本库目录中会生成下面的文件,其中我们关心的是配置文件。

  1. [root@localhost ~]cd /data/svn/repo/
  2. [root@localhost repo]# ls
  3. conf db format hooks locks README.txt
  4. [root@localhost repo]# cd conf
  5. [root@localhost conf]# ls -a
  6. . .. authz passwd svnserve.conf
  7. 说明:
  8. 1svnserve.conf svn服务综合配置文件。
  9. 2passwd 用户名口令文件。
  10. 3authz 权限配置文件。

4.1 修改passwd文件

  1. ### This file is an example password file for svnserve.
  2. ### Its format is similar to that of svnserve.conf. As shown in the
  3. ### example below it contains one section labelled [users].
  4. ### The name and password for each user follow, one account per line.
  5. [users]
  6. # harry = harryssecret
  7. # sally = sallyssecret
  8. user1 = passwd1
  9. user2=passwd2
  10. #其中对应的是 用户名=密码 ,其中等号两边的空格不是必须的。

4.2 修改authz文件

  1. [aliases]
  2. # joe = /C=XZ/ST=Dessert/L=Snake City/O=Snake Oil, Ltd./OU=Research Institute/CN=Joe Average
  3. #这里实现了别名的定义
  4. [groups]
  5. # harry_and_sally = harry,sally
  6. # harry_sally_and_joe = harry,sally,&joe
  7. #将上面创建的分成两个组,组键名、键值自定义:
  8. team0=user1
  9. team1=user2
  10. # [/foo/bar]
  11. # harry = rw
  12. # &joe = r #上面的别名定义在这里实现 &在这里理解为指针就很容易了
  13. # * =
  14. # [repository:/baz/fuz]
  15. # @harry_and_sally = rw
  16. # * = r
  17. [repo:/]
  18. @team0=r
  19. @team1=rw
  20. # 第一个小组只有读取的权限,第二个小组有读写的权限
  21. # 单个版本库的权限配置在这个文件中实现

4.3 修改svnserve.conf

  1. vim svnserve.conf
  1. [general]
  2. ### These options control access to the repository for unauthenticated
  3. ### and authenticated users. Valid values are "write", "read",
  4. ### and "none". The sample settings below are the defaults.
  5. anon-access = none #没有登录的用户不能访问
  6. auth-access = write #登录的用户可以写入
  7. ### The password-db option controls the location of the password
  8. ### database file. Unless you specify a path starting with a /,
  9. ### the file's location is relative to the directory containing
  10. ### this configuration file.
  11. ### If SASL is enabled (see below), this file will NOT be used.
  12. ### Uncomment the line below to use the default password file.
  13. password-db = passwd #密码文件为当前目录下的passwd,建议多个版本库的话统一配置在某个公共目录里,如/svn/conf/passwd
  14. ### The authz-db option controls the location of the authorization
  15. ### rules for path-based access control. Unless you specify a path
  16. ### starting with a /, the file's location is relative to the the
  17. ### directory containing this file. If you don't specify an
  18. ### authz-db, no path-based access control is done.
  19. ### Uncomment the line below to use the default authorization file.
  20. authz-db = authz #验证文件为当前目录下的authz,建议多个版本库的话统一配置在某个公共目录里,如/svn/conf/authz

5 停止和启动svn

5.1 启动svn

  1. svnserve -d -r /data/svn/

5.2 关闭svn

  1. ps -aux |grep svn
  2. kill -9 进程id

6 导入工程

  1. $ mkdir MyProject
  2. $ mkdir MyProject/trunk
  3. $ mkdir MyProject/branches
  4. $ mkdir MyProject/tags
  5. svn import MyProject svn://192.168.12.2/repo/MyProject -m "first import project"

7 导出工程

  1. svn co svn://192.168.12.3/repo/MyProject

8 SVN自启动

8.1 svn服务自启动脚本

把脚本放在/etc/init.d/下

  1. vi /etc/rc.d/init.d/svn

svn脚本内容:

  1. #!/bin/bash
  2. # chkconfig: - 85 15
  3. # description: svn server
  4. SVN_HOME=/data/svn
  5. if [ ! -f "/usr/bin/svnserve" ]
  6. then
  7. echo "svnserver startup: cannot start"
  8. exit
  9. fi
  10. case "$1" in
  11. start)
  12. echo "Starting svnserve…"
  13. /usr/bin/svnserve -d --listen-port 3690 -r $SVN_HOME
  14. echo "Finished!"
  15. ;;
  16. stop)
  17. echo "Stoping svnserve…"
  18. killall svnserve
  19. echo "Finished!"
  20. ;;
  21. restart)
  22. $0 stop
  23. $0 start
  24. ;;
  25. *)
  26. echo "Usage: svn { start | stop | restart } "
  27. exit 1
  28. esac

这里请注意,不要删除# chkconfig: - 85 15和# description: svn server,不然无法使用chkconfig加入服务,会提示service svn does not support chkconfig.
然后执行

  1. chmod 755 /etc/init.d/svn
  2. chkconfig --add svn
  3. chkconfig svn on

最后查看下chkconfig --list|grep svn

可以看到svn已经加入到服务中,并已经在2345中为on.

8.2 shell脚本启动
这第2中自启动脚本,是根据下面情况才使用的

  1. svnserve -d --listen-port 3690 -r /svnroot/repos/
  2. svnserve -d --listen-port 3691 -r /svnroot/repo/

svn默认启动端口是3690,这里有两个svn库,所以当出现这样的情况时,上面的服务脚本只会启动一个svn库.所以就需要使用shell脚本来实现启动两个svn库.

  1. vi /root/svn.sh

svn.sh脚本内容:

  1. #!/bin/bash
  2. svnserve -d --listen-port 3690 -r /svnroot/repos/
  3. svnserve -d --listen-port 3691 -r /svnroot/repo/

然后添加可执行权限

  1. chmod 700 /root/svn.shchmod ug+x /root/svn.sh

添加到自动运行

  1. vi /etc/rc.local

在最后添加一行内容

  1. /root/svn.sh

然后重启服务器,使用ps aux|grep来查看svn是否启动

9 总结

特点:
一个版本库对应一个配置;
仅能使用svn://协议访问。

参考:
1、CentOS下的SVN服务器搭建过程以及分析
http://www.centoscn.com/CentosServer/ftp/2014/0306/2505.html
2、(总结)CentOS Linux搭建SVN Server配置详解
http://www.ha97.com/4467.html

添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注