April 30th, 2007 by thatday
Posted in 谈谈技术 |
部署公司的SVN服务器(系统是FC5)
—————————-
1,下载相关源码
wget http://subversion.tigris.org/downloads/subversion-1.4.3.tar.bz2
wget http://subversion.tigris.org/downloads/subversion-deps-1.4.3.tar.bz2
wget http://apache.hkmirror.org/httpd/httpd-2.2.4.tar.bz2
2,编译apache2
apr和apr-util包含在Apache httpd的发行源代码中,并且在绝大多数情况下使用都不会出现问题。当然,如果apr或apr-util的1.0或1.1版本已经安装在系统中了,则必 须将apr/apr-util升级到1.2版本,或者将httpd单独分开编译。要使用发行源代码中自带的apr/apr-util源代码进行安装,必须 手动完成:
yum remove apr apr-util
cd srclib/apr
./configure –prefix=/www/apr-httpd
make && make install
cd ../apr-util/
./configure –prefix=/www/apr-util-httpd –with-apr=/www/apr-httpd
make && make install
cd ../../
./configure –prefix=/www/apache –enable-dav –enable-so –enable-nonportable-atomics –enable-ssl –with-ssl=/usr –enable-mods-shared=all –with-
apr=/www/apr-httpd –with-apr-util=/www/apr-util-httpd
make && make install
3,编译subversion
yum install autoconf libtool
//export CPPFLAGS=-I/www/apache/include
//cp -R ../httpd-2.2.4/srclib/apr* .
./configure –prefix=/www/subversion –with-apxs=/www/apache/bin/apxs –with-apr=/www/apr-httpd –with-apr-util=/www/apr-util-httpd
make && make install
4,导入源代码
mkdir -p /www/svnroot/repository
cd /www/svnroot
/www/subversion/bin/svnadmin create repository/test
mkdir -p import/{trunk,branches,tags}
/www/subversion/bin/svn import /www/svnroot/import -m “Init repository”
Adding /www/svnroot/import/trunk
Adding /www/svnroot/import/branches
Adding /www/svnroot/import/tags
Committed revision 1.
5,配置apache
vi /www/apache/conf/httpd.conf
User apache
Group apache
chown -R apache:apache /www/svnroot
修改该目录权限(不要在这里使用-R参数,apache用户需要对test下的文件有读写权限)
chmod 700 /www/svnroot
chmod 700 /www/svnroot/repository
6,生成身份认证文件
/www/apache/bin/htpasswd -m -c /www/svnroot/repository/pwdfile webtop
New password: webtop
Re-type new password: webtop
Adding password for user webtop
/www/apache/bin/htpasswd -m /www/svnroot/repository/pwdfile kevin
chown apache:apache /www/svnroot/repository/pwdfile
chmod 700 /www/svnroot/repository/pwdfile
7.创建授权文件
授权文件用于确定每个用户对特定目录的操作权限,格式可参考版本库下的conf/authz(conf目录下的authz文件用于svnserve的授权,与我们所使用的
mod_authz_svn的授权文件具有相同的格式)。因而我们可以直接把conf下的authz复制到我们想要的/home/svnroot/repository目录下,然后加以修改。
这里我么以给test项目分配权限说明subversion的授权机制,项目的目录结构如下图所示:
Repository
|—test
| |—trunk
| |—branches
| |—tags
|
|—other projects…
其中,trunk表示主干,branches则为项目的分支,tags存放某个版本的快照。习惯上来说,大多数开发人的本地拷贝都来自truck目录,所以每个开发人员都
应有trunk目录的读写权限,这样他们才能正常的进行日常的开发;而分支目录一般在,如某些开发人员需要大幅修改代码以增加新功能,或者代码进入较
为稳定的阶段,开始bug去处工作等情况下使用,尽管这意味着这些代码总是有固定的一个或几个开发人员维护,但是基于“源代码共同拥有”的原则,我们
还是可以将其设置为所有用户具有读写权限;tags目录则一般用于某个版本的发布,比如当项目到达版本1834时,release1已经完成,那么就可以将它复制
到tags目录,作为一个快照存放,取一个好记得多的名字,比如release1(似乎应该只让某些人有写入权限,这样可以防止快照被破坏,可是即使被破坏了
又怎么样呢,不要忘了我们在使用一个版本管理软件J)。
建立两个用户组g_pm和g_dev,分别代表项目管理组和开人人员小组
vi /www/svnroot/repository/test/conf/authz
[groups]
g_pm = webtop //某群组里的成员
g_dev = kevin
[test:/] //仓库test的根目录的访问权限
@g_pm = r //g_pm组用户具有读和写权限,’@’开头的表示群组设置
@g_dev = r //g_dev用户具有读写权限
[test:/trunk] //仓库test的trunk目录的访问权限
@g_pm = rw //g_pm组用户具有读和写权限,’@’开头的表示群组设置
@g_dev = rw //g_dev用户具有读写权限
[test:/branches] //仓库test的branches目录下的访问权限
@g_pm = rw //g_pm组用户具有读和写权限,’@’开头的表示群组设置
@g_dev = rw //g_dev用户具有读写权限
[test:/tags] //仓库test的tags目录下的访问权限
@g_pm = rw //g_pm组用户具有读和写权限,’@’开头的表示群组设置
@g_dev = rw //g_dev用户具有读写权限
8.修改Apache配置文件
vi /www/apache/conf/httpd.conf
确保以下两行已被subversion正确添加,这样apache才能正确加载module。
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
Version Control with Subversion 1.4以及很多howto上提到的
LoadModule dav_module modules/mod_dav.so
我们已经在编译httpd时链接进了核心中,不需要作为共享对象加载。
<Location /svn>
DAV svn
SVNParentPath /www/svnroot/repository/ //svn父目录
AuthType Basic //客户端认证机制
AuthName “Subversion Repository” //认证域名称
AuthUserFile /www/svnroot/repository/pwdfile //身份认证文件
AuthzSVNAccessFile /www/svnroot/repository/authz //权限配置文件
Satisfy Any //先尝试匿名访问
Require valid-user //仅通过验证的用户可访问版本库
</Location>
其中/svn表示一个url的模式,匹配形如http://host/svn的url;SVNParentPath 指定的目录下的所有项目都被subversion 认为是合法的版本库;
AuthzSVNAccessFile为授权文件 ;AuthType 则制定了客户端身份认证机制,Basic表示http基本认证机制;AuthUserFile就是先前创建的密码文件;Satisfy
Any 和Require valid-user告诉apache所有用户先使用匿名方式访问版本库,只有当访问控制策略要求一个真实的用户名时,apache才会对客户端进行身份验
证,这是使用得最多的一种授权方式。
重启apache httpd,打开浏览器访问http://localhost/svn/test/这个URL便可访问版本库了,当然,受权限的限制,必须是合法用户才能访问且具有相应的权
限的目录。
/www/apache/bin/apachectl restart
Windows下,用TortoiseSVN客户端访问。
You can leave a response, or trackback from your own site.
You can follow any responses to this entry through the RSS 2.0 feed.
PCplayer.cn says:
April 30th, 2007 at 10:12 pm第一个顶你:)
我在linux上编译时,不有单独编译apr和apr-util,编译apache时它自动认了
yunhui says:
May 5th, 2007 at 6:20 amI’m usting FC1. Your file is very valuable.thanks.
yunhui says:
June 2nd, 2007 at 4:46 pmwhen I browse http://ip/svn/test and login by given the user name and password(webtop/password), The browser’s response tell me I haven’t enough privledge.
Do I need add a linux user and group same as the user,group defined in svn authz file?
thatday says:
June 5th, 2007 at 2:28 pm实在不好意思,文档里面的
/www/subversion/bin/svnadmin create repository/test 应该改成
/www/subversion/bin/svnadmin create –fs-type fsfs repository/test
如果没有 –fs-type fsfs 就会出现你所说的权限问题。另外,svn的用户和linux系统用户没有关系,是两回事。yunhui says:
June 23rd, 2007 at 2:33 pmI solved the priviledge problmen by chown of the repos path. That is,.
# svnadmin create /www/svnroot/repos/test
# chown -R apache:apache /www/svnroot/repos/test
After create the repository, use svn add( repository is accessed by apache).