Ubuntu下搭建SVN服务器
1 安装ssh服务
# sudo apt-get install openssh-server
# ssh localhost
2 安装并配置apache
2.1 安装apr-1.3.9.tar.gz
# tar zxvf apr-1.3.9.tar.gz
# cd apr-1.3.9
# ./configure
# make
# make install
2.2 安装apr-util-1.3.9.tar.gz
# tar zxvf apr-util-1.3.9.tar.gz
# cd apr-util-1.3.9
# ./configure --with-apr=/usr/local/apr
# make
# make install
2.3 安装apache
# tar zxvf httpd-2.2.14.tar.gz
# ./configure --prefix=/opt/apache --enable-dav --enable-so --enable-maintainer-mode --enable-rewrite --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr/bin/apu-1-config
# make
# make install
2.4 查看Apache是否安装成功
启动Apache服务:
# /opt/apache/bin/apachectl start
用浏览器查看http://localhost/,得到It works!
说明apache已经配置成功了。
3 安装并配置Subversion
3.1 安装neon-0.29.3.tar.gz
首先安装
# apt-get install libxml2 libxml2-dev expat
否则会出现“configure: error: no XML parser was found: expat or libxml 2.x required”的错误
# tar zxvf neon-0.29.3.tar.gz
# cd neon-0.29.3
# ./configure --prefix=/usr/local/neon
此时需修改Makefile文件:
配置neon-0.29.3/src/Makefile,将CFLAGS = -g -O2 改成 CFLAGS = -fPIC -g -O2
# make
# make install
==============================
安装此步neon至关重要,否则会提示如下错误:
could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [subversion/libsvn_ra_dav/libsvn_ra_dav-1.la] Error 1
==============================
3.2 安装Subversion
# tar zxvf subversion-1.5.0.tar.gz
# tar zxvf subversion-deps-1.5.0.tar.gz
# cd subversion-1.5.0
# rm -rf apr
# rm -rf apr-util
# ./configure --with-apxs=/opt/apache/bin/apxs --prefix=/opt/svn-1.5.0 --with-apr=/usr/local/apr/bin/apr-1-config --with-apr-util=/usr/local/apr/bin/apu-1-config --with-neon=/usr/local/neon --with-ssl --enable-maintainer-mode
# make
# make install
==============================
注:
1) 由于subversion-deps包里的APR是0.9.x的,因此编译svn时要删除从deps里解压出来的apr, apr-util,改而使用apache 2.2里提供的;
2) ./configure的时候必须加上–with-neon=/usr/local/neon,否则会提示错误(安装neon的时候强调过);
3) 查看Apache的配置文件:/opt/apache/conf/httpd.conf
看到下面两个模块说明安装成功
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
==============================
3.3 查看SVN是否安装成功
# /opt/svn-1.5.0/bin/svnserve --version
会看到相关版本信息!
3.4 修改Apache的配置文件
3.4.1 添加<Location></Location>内容
/opt/apache/conf/httpd.conf
<Location /svn>
DAV svn
SVNListParentPath on
SVNParentPath /data/repository
AuthType Basic
AuthName "Subversion repository"
AuthUserFile /data/passwd
AuthzSVNAccessFile /data/authz
Require valid-user
</Location>
//重启apache
# /opt/apache/bin/apachectl restart
3.4.2 修改用户及组信息
新建用户:apache
# groupadd apache
# useradd apache -g apache
# passwd apache
// 在 /opt/apache/conf/httpd.conf 文件中配置,找到文件中的这两行:
User daemon
Group daemon
// 将daemon改为apache,组也做相应更改,让apache进程以apache的身份运行
// 改完后是这个样子
User apache
Group apache
//重启apache
# /opt/apache/bin/apachectl restart
4 SVN创建仓库与管理
4.1 创建版本库
//创建库文件所在的目录
# mkdir /data/repository
//创建仓库"test"
# /opt/svn-1.5.0/bin/svnadmin create /data/repository/test
//查看svn是否安装成功
# /opt/svn-1.5.0/bin/svnadmin --version
//不让其他人有该目录的权限
# chmod 700 /data/repository
4.2 创建passwd文件和auth文件
4.2.1 增加用户
# /opt/apache/bin/htpasswd -c /data/passwd 用户名(我的是svnuser)
注意://第一次设置用户时使用 -c表示新建一个用户文件。回车后输入用户密码,完成对用户的增加。
# /opt/apache/bin/htpasswd /data/passwd 用户名(加入新的用户,就不用-c了)
4.2.2 权限分配
# vi /data/auth
[groups]
admin = useradmin
devteamcs = svnuser
[/]
@admin = rw
* = r
[test:/]
@devteamcs = rw
按”esc”输入:wq回车保存就可以了
4.3 关闭防火墙
//关闭防火墙否则有可能看不到页面
# cd /etc/init.d
# ./iptables stop
//重启apache
# /opt/apache/bin/apachectl restart
访问http://localhost/svn/test ,现在需要身份验证,且通过验证后应该可以看到信息
4.4 仓库授权
将仓库目录权限修改所属权,让apache组用户登录,给与最多权限。
#chown -R apache.apache /data/repository
经过验证,此处最好将repos的权限设置为700
#chmod 770 /data/repository
#chmod -R g+w /data/repository
4.5 启动SVN服务器端
(如果只使用Http访问,则不需要启动SVN,启动Apache就可以了)
/opt/svn-1.5.0/bin/svnserve -d -r /data/repository/
ps -ef |grep svnserve
==============================
错误
[root@server local]# svn
svn: warning: cannot set LC_CTYPE locale
svn: warning: environment variable LANG is en_US.UTF-8
svn: warning: please check that your locale name is correct
Type 'svn help' for usage.
解决方案
echo "export LC_ALL=C" >> /etc/profile
export LC_ALL=C