CentOS 6.2/6.3安装SVN(编译方式安装Apache+Subversion)

03.19.2013 by jiezhou - 0 Comment, Posted in linux

通过编译方式安装subversion
需要安装的软件包(均为当前的稳定版):

httpd-2.2.24 (apache)
apr-1.4.6/apr-util-1.4.1 (已包含在httpd包中)
subversion-1.7.6
sqlite-3.7.16
neon-0.29.6

前提

如果之前没有安装过编译环境,请执行以下命令:

yum groupinstall "Development tools"

1. 下载

wget http://mirror.bjtu.edu.cn/apache/httpd/httpd-2.2.24.tar.gz
wget http://sqlite.org/2013/sqlite-autoconf-3071600.tar.gz
wget http://www.webdav.org/neon/neon-0.29.6.tar.gz
wget http://mirror.bjtu.edu.cn/apache/subversion/subversion-1.7.8.tar.gz

2. 安装apr 及 apr-util

安装apr,需要先解压httpd

tar zxvf httpd-2.2.24.tar.gz
cd httpd-2.2.24/srclib/apr
./configure --prefix=/usr/local/apr
make
make install

安装apr-util

cd ../apr-util
./configure --with-apr=/usr/local/apr --prefix=/usr/local/apr-util
make
make install

3. 安装apache

cd ../../
./configure --prefix=/usr/local/apache --enable-dav \
--enable-so --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
make
make install

4. 安装sqlite

cd ../
tar zxvf sqlite-autoconf-3071600.tar.gz
cd sqlite-autoconf-3071600
./configure --prefix=/usr/local/sqlite
make
make install

5. 安装neno

cd ../
tar zxvf neon-0.29.6.tar.gz
cd neon-0.29.6
./configure
make
make install

6. 安装subversion

cd ../
tar zxvf subversion-1.7.8.tar.gz
cd subversion-1.7.8
./configure --prefix=/usr/local/subversion \
--with-apxs=/usr/local/apache/bin/apxs \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--with-sqlite=/usr/local/sqlite
make
make install

将可执行文件链接到path目录,方便执行命令

ln -s /usr/local/subversion/bin/svn /usr/bin/
ln -s /usr/local/subversion/bin/svnadmin /usr/bin/

至此,安装完毕,还需进行如下配置。

7.配置

添加用户

groupadd apache
useradd -s /sbin/nologin -M -g apache apache
mkdir -p /data/svn
chown -R apache:apache /data/svn

修改apache配置,打开配置文件

cd /usr/local/apache/conf
#修改运行的user和group
sed -i -e "s/User daemon/User apache/" -e "s/Group daemon/Group apache/" httpd.conf
#在末尾包含svn配置
echo "Include conf/subversion.conf" >> httpd.conf

新建subversion.conf

vim subversion.conf

内容如下:

LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module   modules/mod_authz_svn.so
<Location /svn>
	DAV svn
	SVNListParentPath on  
	SVNParentPath /data/svn

	# SSLRequireSSL
	AuthType Basic
	AuthName "Subversion repository"
	AuthUserFile /etc/subversion/passwd.conf
	AuthzSVNAccessFile /etc/subversion/authz.conf  
	Require valid-user
</Location>

创建一个SVN项目

svnadmin create /data/svn/test
chown -R apache:apache /data/svn/test

创建svn账号,账号为test 密码为 123456

/usr/local/apache/bin/htpasswd -bc /etc/subversion/passwd.conf test 123456

添加另外一个账号时,请省略c参数,如下

/usr/local/apache/bin/htpasswd -b /etc/subversion/passwd.conf test2 123456

配置权限

vim /etc/subversion/authz.conf

内容参考如下

[groups]
Admin = test

[/]
@Admin=r
*=

[test:/]
@Admin=rw
test2=r

以上表示test是属于名为Admin的管理组,管理组可以读取所有项目,以及读写test项目,但test2对test项目只有只读权限。
最后,编写一个apache启动脚本

vim /etc/init.d/httpd

内容如下:

#!/bin/sh
# Startup script for the Apache Web Server
# chkconfig: 345 85 15
# Description: Startup script for Apache webserver.

ARGV="$@"
APACHECTL='/usr/local/apache/bin/apachectl'
ULIMIT_MAX_FILES="ulimit -S -n `ulimit -H -n`"

# Set the maximum number of file descriptors allowed per child process.
if [ "x$ULIMIT_MAX_FILES" != "x" ] ; then
    $ULIMIT_MAX_FILES
fi

ERROR=0
if [ "x$ARGV" = "x" ] ; then 
    ARGV="-h"
fi

case $ARGV in
start|stop|restart)
    echo "${ARGV}ing httpd..."
    $APACHECTL $ARGV
    ;;
*)
    echo "httpd: ${ARGV}"
    $APACHECTL $ARGV
esac

ERROR=$?
 
exit $ERROR

设置脚本可执行并自动启动

chmod +x /etc/init.d/httpd
chkconfig --level 345 httpd on
/etc/init.d/httpd start

至此,全部安装完毕,你可以输入地址http://xxx.xx/svn 来访问你的svn仓库了。
有任务问题,欢迎留言~