centos 下安装svn服务器

安装所需软件安装所需软件安装所需软件安装所需软件 apr,apr-util,sqlite,neon,subversion  

1.下载软件下载软件下载软件下载软件  

wget http://labs.xiaonei.com/apache-mirror/apr/apr-1.3.7.tar.gz

wget http://labs.xiaonei.com/apache-mirror/apr/apr-util-1.3.8.tar.gz

wget http://www.sqlite.org/sqlite-amalgamation-3.6.16.tar.gz

wget  http://www.webdav.org/neon/neon-0.28.4.tar.gz

wget http://subversion.tigris.org/downloads/subversion-1.6.3.tar.bz2 

2.安装apr

tar zxvf apr-1.3.7.tar.gz

cd apr-1.3.7

./configure -prefix=/usr/local/apr

make

make install

cat /etc/ld.so.conf

echo /usr/local/apr/lib >> /etc/ld.so.conf  

3.安装apr-util

tar zxvf apr-util-1.3.8.tar.gz

cd apr-util-.1.3.8

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/

make

make install

echo /usr/local/apr-util/lib >> /etc/ld.so.conf

ldconfig -v  

4.安装sqlite

tar zxvf sqlite-amalgamation-3.6.16.tar.gz

cd sqlite-3.6.16/

configure --prefix=/usr/local/sqlite

make

make install

tar -zxvf sqlite-amalgamation-3.6.22.tar.gz

cd subversion-1.6.12

mkdir sqlite-amalgamation

cp ../sqlite-3.6.22/sqlite3.c ./sqlite-amalgamation/  

5.安装neon

不需要支持http协议可以略掉安装 

tar zxvf neon-0.28.4.tar.gz

cd neon-0.28.4

./configure --prefix=/usr/local/neon --enable-shared

make

make install

方式二:解压后重命名为neon,移动至subversion编译目录 但subversion编译时好像找不到neon 报错如下  

configure: checking neon library  An appropriate version of neon could not be found, so libsvn_ra_neon will not be built.  If you want to build libsvn_ra_neon, please either install neon 0.28.4 on this system  or  get neon 0.28.4 from:     http://www.webdav.org/neon/neon-0.28.4.tar.gz unpack the archive using tar/gunzip and rename the resulting directory from ./neon-0.28.4/ to ./neon/   no suitable neon found

6、安装apache

tar zxvf httpd-2.2.9.tar.gz

cd httpd-2.2.9

./configure --prefix=/usr/local/apache2.2.9 --enable-dav --enable-so --enable-maintainer-mode --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr/bin/apr-util

#--prefix表示把apache安装在指定目录  

make  

make install  

7.安装subversion

tar -jxvf subversion-1.6.3.tar.bz2

cd subversion-1.6.3

./configure --prefix=/usr/local/svn --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-sqlite=/usr/local/sqlite --with-neon=/usr/local/neon make

make install  

7.检查测试

安装后应该有三个模块  

/usr/local/svn/bin/svn --version

svn,版本 1.6.3 (r38063)    

编译于 Jul 30 2009,14:31:41

版权所有 (C) 2000-2009 CollabNet。

Subversion 是开放源代码软件,请参阅 http://subversion.tigris.org/ 站点。

此产品包含由 CollabNet(http://www.Collab.Net/) 开发的软件。  

可使用以下的版本库访问模块:   * ra_neon : 通过 WebDAV 协议使用 neon 访问版本库的模块。  

- 处理“http”方案 * ra_svn : 使用 svn 网络协议访问版本库的模块。  

- 使用 Cyrus SASL 认证  

- 处理“svn”方案 * ra_local : 访问本地磁盘的版本库模块。  

- 处理“file”方案  

 

二、在apache中配置SVN      

vi /usr/local/apache2.2.9/conf/httpd.conf      

① 如果你看到如下两句,说明安装是成功的      

LoadModule dav_svn_module    modules/mod_dav_svn.so      

LoadModule authz_svn_module  modules/mod_authz_svn.so      

{ 如果有下面一句就用#注释掉      

#LoadModule foo_module modules/mod_foo.so }            

② 定义apache访问svn配置:      

<Location /svn>              

DAV svn      

#      SVNPath /usr/local/svndata              

SVNParentPath /usr/local/svndata   #库所在的目录              

AuthzSVNAccessFile /usr/local/svn /conf/authz.conf              

AuthType Basic              

AuthName "Subversion repository"              

AuthUserFile /usr/local/svn /conf/passwd.conf              

Require valid-user      

</Location>  

四、配置svn      

①建立svn版本库目录      

mkdir -p /usr/local/svndata/repos #可以多建版本库目录      

②建立svn版本库      

svnadmin create /usr/local/svndata/repos      

mkdir -p /usr/local/svndata/repos #可以多建版本库      

③建立本地访问控制文件      

/usr/local/apache2.2.9/bin/htpasswd -c /usr/local/svn/conf/passwd.conf username      

然后输入密码即可,默认是MD5加密的 

/usr/local/apache2.2.9/bin/htpasswd /usr/local/svn/conf/passwd.conf username1 #追加用户      

④建立本地项目控制文件      

touch /usr/local/svn/conf/authz.conf  

本例authz.conf内容为:      

[groups]      

#<groupname1>=<username1>,<username2>      

admin=username      

#[<versionLib>:projectName/directory]      

#@<groupsname>=<authorities>      

#<username>=<authorities>      

[/]      

@admin = rw      #指定用户组成员可以读写根目录所有应用      

[repos:/abc/aaa]      

username1= rw      #指定用户username1可以读写:/abc/aaa目录的文件

 

至此,整个安装过程完成了!

五、测测试连接      

① 启动apache      

/usr/local/apache2.2.9/bin/apachectl start      

② 打开浏览器,输入http://192.168.1.107/svn/repos #本例服务器ip是192.168.1.107      

使用刚才创建的权限用户名与密码登录即可访问      

注意:在你上传文件的时候可能会有如下权限不足的提示      

Permission denied      

svn: Commit failed (details follow):      

svn: Can't create directory '/usr/local/svndata/repos/db/transactions/0-1.txn': Permission denied      

这是因为apache在线程用户没有权限访问svn的仓库,两者分别属于不同的用户者      

本例apache属于daemon拥有者,而svn仓库属于svn拥有者      

解决方法:      

chown -R daemon /usr/local/svndata/repos      

chmod -R 755 /usr/local/svndata/repos          

重启下apache:        

/usr/local/apache2.2.9/bin/apachectl stop        

/usr/local/apache2.2.9/bin/apachectl start

启动

[root@localhost bin]# ./apachectl start /usr/bin/svnserve -d -r /myproject/project  

查看svn进程是否已经启动,ps -ef|grep svn 然后输入 kill 进程号 杀死该进程,之后到/usr/local/svn/bin目录下输入命令:

./svnserve -d -r /usr/local/svndata/repos 就可以启动了 

4.使用eclipse的svn插件时输入的地址为:svn:IP即可访问该资源库    

四、客户机访问

客户机的访问方法舆服务器的运行方式有直接关系

window客户机:

1) 服务器以http方式运行

安装完TortoiseSVN-1.1.1-UNICODE_svn-1.1.1.msi后,在你想工作的目录下点击右键,执行checkout,按上图输入即可。

2) 服务器以svnserve方式运行

同上的区别只是URL of repository变为 svn://svn服务器ip/home/mysvn 或者 svn+ssh://svn服务器ip/home/mysvn (注意不是//svn服务器ip//svn/repository)

linux客户机:

1) 服务器以http方式运行

执行 #svn checkout http: //svn服务器ip/svn/repository

2) 服务器以svnserve方式运行

执行 #svn checkout svn://svn服务器ip/home/mysvn 或者 #svn checkout svn+ssh://svn服务器ip/home/mysvn  

五、客户认证机制  

这舆服务器的运行方式有关,服务器以svnserve方式运行 默认下客户可以以匿名方式通过svn://方式任意访问档案库,为了限制其权限,比如只允许读操作,可以通过修改档案库conf子目录中的svnseve.conf文件来实现。

#vi /home/mysvn/conf/svnseve.conf 修改[general]字段下内容为:

anon-access = read

如果设为anon-access = none,则匿名用户不可以通过svn://方式访问档案库

为了实现用户认证,我们一般采用svn+ssh://访问机制。

首先在svnseve.conf文件设置anon-access = none禁止匿名用户通过svn://方式访问档案库

在其后加入auth-access = write一行

auth-access 是限制有援权的使用者(使用svn+ssh:// 来登入) 的存取权限,我们设为是可以读写。

当用户通过svn+ssh://访问时,服务器会自动启动ssh认证机制,要求用户输入密码,对于window用户来说还需要安装第三方软件openssh,才可以采用这种机制  

服务器以http方式运行

比如我们想给 Sally 与 Harry 送交存取档案库的权限. 首先, 我们必须把它们加入到密码档案.

# ### 第一次: 以 -c 建立档案

# htpasswd -c /etc/svn-auth-file harry

New password: *****

Re-type new password: *****

Adding password for user harry

# htpasswd /etc/svn-auth-file sally

New password: *******

Re-type new password: *******

Adding password for user sally

# 接着,在/usr/local/apache2/conf/httpd.conf的加入:

<Location /svn/repository >

DAV svn

SVNPath /home/mycvs

AuthType Basic

AuthName "Subversion repository"

AuthUserFile /etc/svn-auth-file

Require valid-user

</Location>

重新启动 Apache后,如果有人要访问SVN服务器,系统会要求他输入用户名和密码。 只有输入Sally 或Harry的用户名和相应的密码,才可以对档案库进行修改和访问  

添加用户

打开/conf/目录,打开svnserve.conf找到一下两句:

# [general] # password-db = passwd

去之每行开头的#,其中第二行是指定身份验证的文件名,即passwd文件

同样打开passwd文件,将  

 

# [users] # harry = harryssecret

# sally = sallyssecret

这几行的开头#字符去掉,这是设置用户,一行一个,存储格式为“用户名 = 密码”,如可插入一行:admin = admin888,即为系统添加一个用户名为admin,密码为admin888的用户  

4. 在svn使用过程中牵扯到几种权限:文件系统的权限,linux系统权限,svn用户的权限,apache进程的权限。  

文件系统的权限,linux系统权限:这里相同的意思,就是平时大家使用linux时文件夹和文件的访问权限。在 svn建立仓库,文件夹,配置文件的时候用svnroot用户,并将仓库权限设置为700,不允许其他用户直接通过 文件系统查看,只能由svnroot进行管理。  

apache进程的权限:因为所有跟仓库传输的操作都是通过apache进程进行的,所以即使你给svn用户设置了 很大的权限,但是apache进程没有访问仓库或者相关文件的权限也没有用,apache进程的权限设置在 /usr/local/apache2/conf/httpd.conf 文件中配置,找到文件中的这两行:

User daemon

# 将daemon改为svnroot,让apache进程以svnroot的身份运行  

Group daemon    

svn用户的权限:就是在repository/authz.conf文件中设置的权限信息,是svn用来管理仓库访问权限的。  

5. svn服务器设置有两种方式:http 和 svnserve。

这里介绍的是http方法  

6. 在/etc/profile的结尾设置一些svn启动时要做的工作

# start apache server for svn  

/usr/sbin/apachectl start  

export SVN_EDITOR=vi    

7. APR libraries

安装 SVN 的时候最好指定 --with-apr= 和 --with-apr-util= 参数到 Apache 安装的根目录  (ServerRoot)下,而不是使用缺省的 SVN 安装包中自带的 apr 。否则如果你安装的 Apache  版本不同有可能导致 APR 库不匹配,出现类似: Can't set position pointer in file '/svn/test/db/revs/1': Invalid argument 的错误。

Updated 2006-04-20 16:30

-- 比如说如果你安装的是apache 2.2.0版本,就需要在编译安装svn的时候指定  --with-apxs和--with-apr参数到你的apache2.2.0安装目录下:

./configure --divfix=${subversionInstallFolder} /  

--with-apxs=${apacheInstallFolder}/bin/apxs /  

--with-apr=${apacheInstallFolder} /  

--with-apr-util=${apacheInstallFolder} /  

--with-ssl /  

--with-zlib /  

--enable-maintainer-mode 

posted @ 2012-09-19 10:35  luoxiake  阅读(141)  评论(0)    收藏  举报