环境:CentOS-7-x86_64-1611 + subversion-1.9.5
一、源码安装:
1、安装ldap:
wget ftp://gd.tuwien.ac.at/infosys/network/OpenLDAP/openldap-release/openldap-2.4.44.tgz
tar -zxv -f openldap-2.4.44.tgz
cd openldap-2.4.44/
./configure --prefix=/usr/local/ldap --disable-slapd
#--disable-slapd === 不需要ldap服务器 只需要lib include
make
make install
2、安装APR:
wget http://apache.fayea.com//apr/apr-1.5.2.tar.bz2
tar -jxv -f apr-1.5.2.tar.bz2
cd apr-1.5.2/
./configure --prefix=/usr/local/apr
make
make install
3、安装APR-util:
wget http://apache.fayea.com//apr/apr-util-1.5.4.tar.bz2
tar -jxv -f apr-util-1.5.4.tar.bz2
cd apr-util-1.5.4/
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config --with-ldap=ldap --with-ldap-include=/usr/local/ldap/include --with-ldap-lib=/usr/local/ldap/lib
#apr-util需要带上ldap功能
make
make install
4、安装pcre:
wget https://ftp.pcre.org/pub/pcre/pcre-8.40.tar.bz2
tar -jxv -f pcre-8.40.tar.bz2
cd pcre-8.40/
./configure --prefix=/usr/local/pcre
make
make install
5、安装apache:
wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.25.tar.bz2
tar -jxv -f httpd-2.4.25.tar.bz2
cd httpd-2.4.25/
./configure --prefix=/usr/local/httpd \
--with-apr=/usr/local/apr/bin/apr-1-config \
--with-apr-util=/usr/local/apr-util/bin/apu-1-config \
--with-pcre=/usr/local/pcre/bin/pcre-config \
--enable-module=mod_auth_basic \
--enable-module=mod_authnz_ldap \
--enable-module=mod_dav \
--enable-module=mod_dav_fs \
--enable-module=mod_dav_lock \
--enable-module=mod_authn_file \
--enable-module=mod_authz_user \
--enable-ldap \
--enable-authnz-ldap \
--enable-module=mod_ldap
make
make install
开启防火墙80 端口:
firewall-cmd --permanent --zone=public --add-port=80/tcp
firewall-cmd --reload
将httpd加入服务:
cp /usr/local/httpd/bin/apachectl /etc/init.d/httpd
6、安装sqlite:
wget http://www.sqlite.org/2017/sqlite-autoconf-3160200.tar.gz
tar -zxv -f sqlite-autoconf-3160200.tar.gz
cd sqlite-autoconf-3160200/
./configure --prefix=/usr/local/sqlite
make
make install
7、安装zlib:
wget http://www.zlib.net/zlib-1.2.11.tar.gz
tar -zxv -f zlib-1.2.11.tar.gz
cd zlib-1.2.11/
./configure --prefix=/usr/local/zlib
make
make install
8、安装serf:
8.1、安装scons ==> serf:
安装 serf 需要用 scons 安装:
wget http://prdownloads.sourceforge.net/scons/scons-2.5.1-1.noarch.rpm
rpm -ivh scons-2.5.1-1.noarch.rpm
8.2、安装 openssl-devel ==> serf:
如果在serf安装时 如果报错:
compilation terminated.
scons: *** [buckets/ssl_buckets.o] Error 1
scons: building terminated because of errors.
yum install openssl-devel
8.3、安装 serf:
旧版本svn 是用 neon (--with-neon=/usr/local/neon) 而新版本(1.8开始)是使用serf来支持http访问
wget https://www.apache.org/dist/serf/serf-1.3.9.tar.bz2
tar -jxv -f serf-1.3.9.tar.bz2
cd serf-1.3.9/
scons PREFIX=/usr/local/serf APR=/usr/local/apr/bin/apr-1-config APU=/usr/local/apr-util/bin/apu-1-config
scons install
9、安装svn:
wget http://mirrors.cnnic.cn/apache/subversion/subversion-1.9.5.tar.bz2
tar -jxv -f subversion-1.9.5.tar.bz2
cd subversion-1.9.5/
./configure --prefix=/usr/local/subversion \
--with-apr=/usr/local/apr/bin/apr-1-config \
--with-apr-util=/usr/local/apr-util/bin/apu-1-config \
--with-apxs=/usr/local/httpd/bin/apxs \
--with-sqlite=/usr/local/sqlite \
--with-zlib=/usr/local/zlib \
--with-serf=/usr/local/serf
make
make install
10、如果使用./svn命令出现错误:
svn: error while loading shared libraries: libserf-1.so.1: cannot open shared object file: No such file or directory
解决:把serf安装后的 libserf-1.so.1.3.0 复制到svn的安装目录下的lib目录(直接复制libserf-1.so 会出现 链接已断的错误属性 没有用)
/usr/local/subversion/bin/svn --version
cp /usr/local/serf/lib/libserf-1.so.1.3.0 /usr/local/subversion/lib/libserf-1.so.1
11、将svn目录下的几个模块复制到apache下,支持ladp功能:
cp /usr/local/subversion/libexec/mod_authz_svn.so /usr/local/httpd/modules/mod_authz_svn.so
cp /usr/local/subversion/libexec/mod_dav_svn.so /usr/local/httpd/modules/mod_dav_svn.so
二:httpd.conf配置:
1、匿名登录:
#开启模块
LoadModule dav_module modules/mod_dav.so
LoadModule dav_svn_module modules/mod_dav_svn.so
#url访问路径,可以不等于 实际的根目录 (指定的路径不要和www的冲突 不然可能会是301报错)
<Location /svn>
DAV svn
#仓库的根目录(增加/删除仓库的时候 不需要重启apache服务)
SVNParentPath /svn
</Location>
2、账号密码验证(明文):
Basic -- htpasswd 基本认证
Digest -- htdigest 基本认证的改进
创建密码文件:
-c 创建文件(第一次需要,后面几个用户就不需要了)
-m md5
/usr/local/httpd/bin/htpasswd -c -m /etc/svn-auth.htpasswd username1
/usr/local/httpd/bin/htpasswd -m /etc/svn-auth.htpasswd username2
/usr/local/httpd/bin/htdigest -c /etc/svn-auth.htdigest "AuthName" username1
/usr/local/httpd/bin/htdigest /etc/svn-auth.htdigest "AuthName" username2
#开启模块#下面三个顺序是必须的
LoadModule dav_module modules/mod_dav.so
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule auth_digest_module modules/mod_auth_digest.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_user_module moduels/mod_authz_user.so
<Location /svn>
DAV svn
SVNParentPath /svn
#这一行必须要!
Require valid-user
AuthType Basic
AuthName "SVN-basic"
#AuthType Digest
#AuthName "SVN-digest"
AuthBasicProvider file
#账号密码文件
AuthUserFile /svn/svn-auth.htpasswd
#权限文件
AuthzSVNAccessFile /svn/svntest.conf
</Location>
3、ldap登陆:
#开启模块#下面三个顺序是必须的
LoadModule dav_module modules/mod_dav.so
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_user_module moduels/mod_authz_user.so
<Location /svn>
DAV svn
SVNParentPath /svnt
Require valid-user
AuthType Basic
AuthName "SVN-ldap"
AuthBasicProvider ldap
# AuthzLDAPAuthoritative 属性在2.4版本中已经取消: http://httpd.apache.org/docs/2.4/upgrading.html#run-time
# AuthzLDAPAuthoritative off
AuthLDAPURL "ldap://192.168.1.1/ou=People,dc=abc,dc=net"
AuthLDAPBindDN "cn=admin,dc=abc,dc=net"
AuthLDAPBindPassword "abcd"
# AuthzSVNAccessFile /svnt/svntest.conf
</Location>
4、AD域登陆:
#开启模块#下面三个顺序是必须的
LoadModule dav_module modules/mod_dav.so
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
LoadModule ldap_module modules/mod_ldap.so
LoadModule authnz_ldap_module modules/mod_authnz_ldap.so
LoadModule auth_basic_module modules/mod_auth_basic.so
LoadModule authn_file_module modules/mod_authn_file.so
LoadModule authz_user_module moduels/mod_authz_user.so
<Location /svn>
DAV svn
SVNParentPath /svnt
Require valid-user
AuthType Basic
AuthName "SVN-ad"
AuthBasicProvider ldap
AuthLDAPURL "ldap://192.168.1.2/dc=abc,dc=com?samaccountName?sub?(objectClass=*)"
AuthLDAPBindDN "administrator"
AuthLDAPBindPassword "abcd"
# AuthzSVNAccessFile /svnt/az.conf
</Location>
三:az.conf 权限控制:
#设置组
[groups]
group1=username1
[/]
#组
@group1=rw
#用户
username2=rw
#这里就是svn下的目录名
[repos_name:/]
@group1=rw
username2=rw