搭建svn服务器

 

 

 

 

 

SVN Windows版本下载:https://www.open.collab.net/downloads/subversion/rc/

 CollabNetSubversion-server-1.6.0-2.win32.exe

本地已安装Apache服务器的话,不用选择第二项。

 

 

 SVN默认端口号是3609,指定资源路径F:\svn_repository 作为初始的资源库。这里不推荐设置为WIndows 服务,原因是WIndows 服务使用起来不好用,推荐通过手工的方式启动和控制SVN服务器,这样具有更大的灵活性。

最后选择SVN软件的安装路径,这里设置为D:\Program Files (x86)\CollabNet Subversion Server。

 

 点击Finish完成安装。

 

 配置Subversion 服务器

进入cmd命令窗口,执行

svnadmin create F:\svn_repository

其中svnadmin 为svn管理的命令,create表示创建资源库,F:\svn_repository表示的是资源库所在的文件夹路径。

 

创建资源库后,在F:\svn_repository 下会自动生成一些SVN所使用的文件目录结构。

 

 其中conf用于资源库的相关配置信息,可以通过修改这里的文件对SVN资源库配置相应的信息。其他的文件,尽量不要去修改。

注:可以通过 svnadmin help 命令来茶语相关的说明。

 

设置访问用户

只创建了资源库是不够的,还需要设置访问资源库的用户以及为其授权,这样才能保证SVN资源库的安全。SVN的安全又涉及两个方面,即用户的认证和用户的授权。

1 用户认证

用户的认证是创建用户并为其设置密码。F:\svn_repository\conf\password 文件增加两行。

### 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
harry = 123
joe = 456

增加了两个用户,并设置了各自的密码。

 

2 用户授权

每个用户所能使用的权限是不同的,比如 admin 是管理员,拥有最高的权限,可以读写文件,但user 只是个浏览用户,只能读文件,但不能修改文件。这就涉及到授权的问题。

SVN的授权信息默认保存在资源文件根目录的conf/authz 文件中。打开文件,

  

### This file is an example authorization file for svnserve.
### Its format is identical to that of mod_authz_svn authorization
### files.
### As shown below each section defines authorizations for the path and
### (optional) repository specified by the section name.
### The authorizations follow. An authorization 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 prefixing the rule with '~'. Rules can
### grant read ('r') access, read-write ('rw') access, or no access
### ('').

[aliases]
# joe = /C=XZ/ST=Dessert/L=Snake City/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

这里的意思是说,SVN不仅可以配置用户组,也可以针对不同的资源库路径配置访问权限等。

3 配置认证和授权文件

进设置了这些认证信息,并没有完成安全的配置,还需要修改的SVN的配置信息conf\svnserve.conf文件。

去掉# password-db = passwd这一行的"#"号,则表示,SVN启动服务后,将使用passwd这个文件作为认证信息。

 

启动Subversion服务

启动Subversion需要使用命令 svnserve,例如启动F:\svn_repository 的资源库的Subversion服务,则需要在命令行界面输入以下命令。

svnserve -d -r F:\svn_repository

其中,svnserve为SVN服务管理的命令,-d表示的是该服务是由守护线程方式启动的,而-r F:\svn_repository 表示的是要启动服务的资源库所在的根目录。

这样,SVN资源库的服务就启动了,只要不关闭这个命令行窗口,SVN的服务就一直存在。

 

安装Subversion客户端TortoiseSVN

TortoiseSVN-1.9.1.26747-x64.zip

浏览资源库

安装完之后,右键,在TortoiseSVN快捷菜单中选择 TortoiseSVN | Repo-browser 菜单项,将弹出输入资源库的地址对话框。

这里 “svn://” 为访问SVN服务器的协议,localhost 为服务器的地址。如果服务器在局域网中,也可以设置为局域网的IP地址或者域名。

另外,如果配置了Apache服务器,还可以通过“http://”来访问。

点击OK按钮,出现以下对话框,这里显示的是SVN资源库中的所有文件。

左侧是资源库中的所有文件,右侧是文佳佳和文件的详细信息。

 

在资源库中增加文件夹

在左侧的浏览窗口中右击,子啊弹出的快捷菜单中选择Create folder选项,在弹出的对话框中输入SVN服务器上新建的文件夹名trunk。

 

单击OK按钮,弹出一个输入提交日志的对话框,

 

使用harry 123管理创建,这样可以重复创建多个文件夹。

 

 

 导入文件到资源库(import)

下面有这样一个场景,用户harry在Eclipse中创建了一个名为FirstJava的Java项目,现在,他将与用户joe组成一个团队(Team),共同开发这个Java应用,那么该如何做呢?

整个过程要分为两个步骤:

(1)用户harry将java项目的代码导入(Import)到资源库中,与其他用户共享。

(2)用户joe将资源库中的Java项目代码迁出(chexkout)到自己的电脑中。

这样,用户harry和用户joe就可以一块开发这个Java项目了,首先看一下用户harry如何将代码导入到资源库。

(1)harry在自己的电脑上,打开FirstJava项目所在的文件目录,然后在FirstJava文件夹上右击,在弹出的快捷菜单中选择TortoiseSVN | Import命令。

(2)在踏出的对话框中输入资源库所要导入的文件目录svn://localhost/trunk/FirstJava

 

导入完成窗口

 

 导入资源后的资源库目录结构

 注:SVN服务器版本库有两种格式,一种为FSFS,一种为BDB把文件上传到SVN版本库后,上传的文件不再以文件原来的格式存储,而是被svn以它自定义的格式压缩成版本库数据,存放在版本库中。如果是FSFS格式,这些数据存放在版本库的db目录中,里面的revs和revprops分别存放着每次提交的差异数据和日志等信息 。

 

 从资源库中迁出(checkout)

被导入的资源库中的文件便成为了共享的文件,其他的用户就可以通过客户端获得这些共享文件了。下面joe将进行资源获取操作。

 

 

 

 

 

 

 

 svn://localhost/trunk/FirstJava

F:\test\FirstJava

 

 

 没有图标显示,

解决图标颜色问题:

接着。对这9个文件重命名即可:

下面就可以看到颜色了:

图标显示问题与TortoiseSVN相关,可参考 TortoiseSVN客户端图标覆盖问题 。http://blog.csdn.net/zzfenglin/article/details/51979569

 

 

 

 

 

 

 

下面将在centos中进行SVN服务器环境的搭建。(参考:https://help.aliyun.com/document_detail/52864.html)

完整依赖安装:https://zhidao.baidu.com/question/556347129706975492.html

完整安装:http://www.linuxidc.com/Linux/2012-12/75992.htm

 

yum install subversion

 

Total 2.3 MB/s | 2.3 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-3.el7.x86_64 1/6
Installing : apr-util-1.5.2-6.el7.x86_64 2/6
Installing : pakchois-0.4-10.el7.x86_64 3/6
Installing : neon-0.30.0-3.el7.x86_64 4/6
Installing : subversion-libs-1.7.14-10.el7.x86_64 5/6
Installing : subversion-1.7.14-10.el7.x86_64 6/6
Verifying : neon-0.30.0-3.el7.x86_64 1/6
Verifying : apr-1.4.8-3.el7.x86_64 2/6
Verifying : subversion-1.7.14-10.el7.x86_64 3/6
Verifying : apr-util-1.5.2-6.el7.x86_64 4/6
Verifying : pakchois-0.4-10.el7.x86_64 5/6
Verifying : subversion-libs-1.7.14-10.el7.x86_64 6/6

Installed:
subversion.x86_64 0:1.7.14-10.el7

Dependency Installed:
apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7 neon.x86_64 0:0.30.0-3.el7 pakchois.x86_64 0:0.4-10.el7 subversion-libs.x86_64 0:1.7.14-10.el7

Complete!

 配置目录:/etc/httpd/conf/httpd.conf

 

 

svnserve --version
mkdir /var/svn

 

cd /var/svn
svnadmin create /var/svn/svnrepos
cd svnrepos会看到自动生成的版本库文件:
conf db format hooks locks README.txt

 

 

 

 

阿帕奇服务器的安装

 

手动安装(繁琐)

 http://jingyan.baidu.com/article/7e4409533d7f0f2fc0e2ef91.html

wget http://mirror.bit.edu.cn/apache//httpd/httpd-2.2.34.tar.gz

 

(自动安装)

http://jingyan.baidu.com/article/c14654138f12920bfcfc4c01.html

 

(1)登录到阿里云服务器上,在控制终端输入以下命令:

yum install httpd httpd-devel 

(2)然后开始下载安装,下载过程会提示以下信息,只需要输入y即可继续安装。

(3)当出现complete!字样时即表示安装完成,如下图所示。

(4)然后我们设置成开机自启动,命令如下:

chkconfig --levels 235 httpd on

(5)配置完毕,启动 Apache:

systemctl start httpd

 (6)此时已经可以访问你的服务器,l输入ip地址,不出意外的话,能够看到 “Testing 123.." 的测试页面。

(7)如果其他机器访问这台服务无法显示这个页面,而直接在这台服务器上可以访问的话,可能是 CentOS 自带的防火墙禁止了。只需要进入防火墙,将 “WWW” 对应的 “80” 端口打开即可。

注意事项:

默认根目录是 /var/www/html
配置文件 /etc/httpd/conf/httpd.conf
其他配置存储在 /etc/httpd/conf.d/ 目录

注:使用 --prefix 可指定安装目录。

 默认html目录为空,根据/etc/httpd/conf.d/welcome.conf中的配置,跳转到Alias /.noindex.html /usr/share/httpd/noindex/index.html 页面。

 

 

阿帕奇+SVN =》 http 方式访问 SVN 服务器(参考:https://www.ibm.com/developerworks/cn/java/j-lo-apache-subversion/ )

 

 

 

第一步:实现http://ip/repo_name 访问SVN

这里thhp访问是代表通过apche访问,因此不会进行svn验证

<Location /svnrepos>
DAV svn
SVNPath /var/svn/svnrepos
</Location>

 

点进去看看

 第二步:添加用户登录验证基本功能

 /etc/httpd/modules

systemctl restart httpd.service

service httpd restart

systemctl start httpd

killall httpd

killall svnserve

svnserve -d -r /var/svn/svnrepos

 

chcon -R -h -t httpd_sys_content_t /var/svn/

chown -R apache:apache /var/svn/repo1 

解决  could not begin a transaction

 

svnserve -d -r /mnt/westos --listen-port 3691

解决 svnserve: E000098: Can't bind server socket: Address already in use

导入文件到svnrepos

svn import -m "New import" myproj http://svn.red-bean.com/repos/trunk/misc/myproj

 

<Location /svnrepos>
DAV svn
SVNPath /var/svn/svnrepos
AuthType Basic
AuthName "svn repos"
AuthUserFile /var/svn/svnrepos/conf/passwd
Require valid-user
</Location>

 

密码是对,就是无法登录。

制作密码验证文件:http://lansgg.blog.51cto.com/5675165/1602593

 也就是说,apache的验证需要加密。

 

 第三步:用 mod_authz_svn 进行目录访问控制

上一步仅仅只是拥有了用户的基本验证功能,比较单一,这里采用用户验证策略,比较综合灵活。AuthzSVNAccessFile 指向的是 authz 的策略文件,详细的权限控制可以在这个策略文件中指定。

httpd.conf的location中需要添加一行:

AuthzSVNAccessFile /etc/svn/accesspolicy
 
 

第四步:添加https访问功能

这里就不适用Apache来处理SSL问题了,直接使用Nginx代理就好。

 参考:http://www.linuxidc.com/Linux/2014-02/96985.htm

 

http://www.cnblogs.com/fuqiang88/p/4727257.html

 

 

可视化:可以安装 Trac   or  Viewvc[http://www.viewvc.org/]

 

posted @ 2017-03-26 15:54  当归远志  阅读(2450)  评论(1编辑  收藏  举报