Linux下SVN服务器搭建
已经在Radhat和Centos上搭过两次了,总结一下,每个人每次搭建是遇到的问题可能会不一样,最重要的还是要学会利用网络资源,多多学习
软件包
我们需要两个文件,httpd和subversion。httpd是web服务器,用来通过web访问subversion。它们的下载地址为:
http://httpd.apache.org/
http://subversion.apache.org/download/#supported-releases
最好不要让root用户参与到svn的权限管理和日常的运行和维护工作中来,但是有一些安装和配置操作还是需要root用户来完成的,因为有些操作只有root才能做。权限问题很重要。(如果权限不对,会让你郁闷很久)
安装
编译安装httpd:
# tar xvzf httpd-2.2.6.tar.gz
# cd httpd-2.2.6
# ./configure--enable-dav --enable-so --enable-mods-shared=all--prefix=/home/student/server/apache2
如果报错:Cannotuse an external APR with the bundled APR-util:
apache2.0.x与apache2.2.x在apr有很大区别,前者为依赖公用apr,后者依赖于自身的apr。一般前者也就是2.0.x的 编译基本上没有apr方面的问题。如果是后者也出现关于apr的问题,则将安装前的apr去除后,在编译apache2.2.x自身的apr,在srclib目录中。
因此根据提示解决此问题:
1、安装APR:
#cd/home/student/server/apache2/srclib/apr
#./configure--prefix=/home/student/server/apache2 /apr
#make &&make install
2、安装APR-util
#cd /home/student/server/apache2/srclib/apr-util
#./configure--prefix=/home/student/server/apache2/apr-util --with-apr=/home/student/server/apache2/apr
#make &&make install
3、安装apache,加入参数(--with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util)
#./configure--enable-dav --enable-so --enable-mods-shared=all --prefix=/home/student/server/apache2--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
OK,解决。
# make
# make install
(或者合并为一步#make && make install)
编辑配置文件httpd.conf
# vi /home/student/server/apache2/conf/httpd.conf
修改内容:
ServerName www.example.com:80 为
ServerName服务器的IP:80
安装完成并修改后,启动apache进程:/home/student/server/apache2/bin/apachectlstart(或者在/home/student/server/apache2/bin/下,用./httpd–k start),然后打开浏览器
http://localhost/,如果有测试页"It works!"出现,则证明已经安装成功。
在安装svn前要确保已经安装sqlite
1.源码安装步骤如下:
#wget http://www.sqlite.org/sqlite-3.5.6.tar.gz
#tar -xzvf sqlite-3.5.6.tar.gz
#cd sqlite-3.5.6
#./configure --prefix=/home/student/server/sqlite
#make && make install
编译安装Subversion
# tar xvzf subversion-1.4.5.tar.gz (或者tar -jxvfsubversion-1.4.0.tar.zb2)
# cd subversion-1.4.5
# ./configure --with-apxs=/home/student/server/apache2/bin/apxs--prefix=/home/student/server/subversion--with-apr=/home/student/server/apache2/apr --with-apr-ut=/home/student/server/apache2/apr-util --with-ssl --enable-maintainer-mode
# make clean && make && makeinstall
//创建库文件所在的目录
# mkdir/home/student/svn/his
//进入subversion的bin目录
# cd /home/student/server/subversion/bin
//创建"his"仓库
# ./svnadmin create /home/student/svn/his
//进入到数据仓库"his"目录
# cd /home/student/svn/his
//看看是不是多了些文件,如果是则说明Subversion安装成功了
# ls –l
//不让其他人有该目录的权限
# chmod 700 /home/student/svn/his
//**注意,直接这么chmod会导致svn客户端无法访问,需要修改apache配置文件httpd.conf文件:
User daemon //将daemon改为student,让apache进程以student的身份运行
Group daemon
//把上述内容改成:
User student
Group student
//如果apache以daemon方式运行则所有用户对资源库只有r的权限
修改Apache配置文件
# /home/student/server/apadche2/bin
# ./apachect1 stop //停止Apache进程
vi /home/student/server/apadche2/conf/httpd.conf
//在最下面添加 ,如果你的里面没有这两个模块的话
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
Location指示的目的是告诉Apache在特定的URL以及子URL下需要特殊的处理,如果是为Subversion准备的,
你希望可以通过告诉Apache特定URL是指向版本化的资源,从而把支持转交给DAV层,你可以告诉 Apache将
所有路径部分(URL中服务器名称和端口之后的部分)以/svn/开头的URL交由DAV服务提供者处理
<Location /svn>
DAV svn
SVNParentPath /home/student/svn
# our access control policy 权限配置文件
AuthzSVNAccessFile /home/student/svn/his/authz.conf
# only authenticated users may access the repository
Require valid-user
# how to authenticate a user
AuthType Basic
AuthName "Subversion repository created by yourname"
#用户配置文件
AuthUserFile /home/student/svn/his/authfile
</Location>
#htpasswd –c /home/student/svn/his/authfile test//用户名
#test//密码
//其中authfile是通过"htpasswd –c /home/student/svn/his/authfileusername password"来创建
//"Require valid-user"告诉apache在authfile中所有的用户都可以访问。如果没有它,则只能第一个用户可以访问新建库
#vi /home/student/svn/his/authz.conf //先创建一个文件,具体配置后面在说明
//启动apache服务
# /home/student/server/apache2/bin/apachectl start
//打开浏览器访问
http://localhost/svn/his/,如果有东西显示就说明成功。
权限管理(即authz.conf的配置)
1)增加用户
# htpasswd -c /home/student/svn/his/authfile user1
//第一次设置用户时使用-c表示新建一个用户文件。回车后输入用户密码,完成对用户的增加,添加完后在authfile中看到用户和加密的密码。
# htpasswd /home/student/svn/his/authfile 用户名(加入新的用户)
//如:"htpasswd /home/student/svn/his/authfile user2"
2)权限分配
# vi /home/student/svn/his/authz.conf //编辑添加下面内容
#群组设置
[groups]
Tester = test,user1 //这个表示某群组里的成员
#anonymous = guest
[test:/] //这表示,仓库test的根目录下的访问权限
@Tester = rw //test仓库Tseter组中用户具有读和写权限
* = r //test仓库中所有用户具有读的权限
//注意:在编辑authz.conf文件时,所有行都必须要顶头写,不能有缩行出现,否则会报错:"Access denied: 'user1' "。
//详细设置查阅http://www.subversion.org.cn/svnbook/1.4/svn.serverconfig.pathbasedauthz.html
重启apache进程
# /home/student/server/apache2/bin/apachectl restart
就可以通过http://localhost/svn/his这个URL来访问仓库了,当然,受权限的限制,必须是合法用户才能访问且具有相应的权限。
备忘:
1).在svn使用过程中牵扯到几种权限:文件系统的权限,linux系统权限,svn用户的权限,apache进程的权限。文件系统的权限,linux系统权限:这里相同的意思,就是平时大家使用linux时文件夹和文件的访问权限。在 svn建立仓库,文件夹,配置文件的时候用svnroot用户,并将仓库权限设置为700,不允许其他用户直接通过文件系统查看,只能由svnroot进行管理。apache进程的权限:因为所有跟仓库传输的操作都是通过apache进程进行的,所以即使你给svn用户设置了很大的权限,但是apache进程没有访问仓库或者相关文件的权限也没有用,apache进程的权限设置在 /home/student/server/apache2/conf/httpd.conf文件中配置,找到文件中的这两行:
User daemon # 将daemon改为student,让apache进程以student的身份运行
Group daemon
svn用户的权限:就是在authz.conf文件中设置的权限信息,是svn用来管理仓库访问权限的。
2).设置启动系统后,自启动Apache服务
编辑etc/rc.d/rc.local
# vi /etc/rc.d/rc.local
在最后加上一句: /home/student/server/apache2/bin/apachectl start