CentOS7 原始碼安裝svn1.9.5及httpd配置(ldap驗證/ad域驗證)

weixin_34402408發表於2017-02-07

環境: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

相關文章