svn資料庫認證方法

來源:互聯網
上載者:User
1 -- apache認證方法

平時上網訪問一些網站的某些資源時,瀏覽器彈出一個對話方塊,要求輸入使用者名稱和密碼來擷取對資源的訪問。這就是使用者認證的一種技術。如在瀏覽器中訪問SAE的SVN倉庫如下提示一般:

瀏覽器的使用者認證技術一般是基於“使用者名稱+密碼”的形式,服務端根據二者的對應關係控制著所有登入使用者的合法性,其目的是僅讓合法使用者以合法的許可權訪問服務端資源。
SVN通用搭建方式是以Apache作為網路伺服器,通過mod_dav_svn模組,操作SVN資料倉儲,為使用者提供版本服務。在這種搭建模式下使用者可直接採用Apache的認證系統,比如使用文字檔,或者MSQL、Oracle等資料庫,或者LDAP等等認證方法。對於大型SVN應用系統而言,搭建LDAP伺服器來系統管理使用者許可權,更為合理,這也是我推薦的認證架構。但對於小企業或者個人使用者來說,採用MySQL集中授權方式要簡單方便,本文用來記錄我對這種方式的摸索經曆。

2 -- mod_authz_mysql的安裝

下載mod_authz_mysql:
http://nchc.dl.sourceforge.net/project/modauthmysql/modauthmysql/3.0.0/mod_auth_mysql-3.0.0.tar.gz
使用如下命令進行編譯:

#如果MySQL安裝在可搜尋路徑下,用如下方法編譯$ /apache/bin/apxs -c -lmysqlclient -lm -lz mod_auth_mysql.c#如果MySQL安裝在其他路徑下,我們需要制定MySQL庫的路徑$ /apache/bin/apxs -c -I/mysql/include/mysql -L/mysql/lib/mysql -lmysqlclient -lm -lz mod_auth_mysql.c#命令列上可以同時指定多個庫路徑,假如按上述方法編譯提醒找不到zlib庫,可按如下方法編譯$ /apache/bin/apxs -c -I/mysql/include/mysql -L/mysql/lib/mysql -L/zlib/lib  -lmysqlclient -lm -lz mod_auth_mysql.c

但非常不幸的是,在安裝mod_authz_mysql3.0.0版本時,無論採用上述哪種方法,都會出現如下一堆亂七八糟的錯誤:

$ /apache/bin/apxs -c -lmysqlclient -lm -lz mod_auth_mysql.c/apr/build-1/libtool --silent --mode=compile gcc -prefer-pic   -DLINUX=2 -D_REENTRANT -D_GNU_SOURCE -g -O2 -pthread -I/apache/include  -I/apr/include/apr-1   -Iapr-util/include/apr-1   -c -o mod_auth_mysql.lo mod_auth_mysql.c && touch mod_auth_mysql.slomod_auth_mysql.c:269:19: error: mysql.h: No such file or directorymod_auth_mysql.c:379: error: expected specifier-qualifier-list before 'MYSQL'mod_auth_mysql.c:386: warning: excess elements in struct initializermod_auth_mysql.c:386: warning: (near initialization for 'connection').....此處省略十萬八千個字

網上給出的解決方案是要給mod_auth_mysql.c打個補丁,該補丁可在這裡下載到:

http://www.zoosau.de/wp-content/uploads/mod_auth_mysql-300-apache-22.patch

將該補丁檔案放置到mod_authz_mysql的目錄裡,執行如下打補丁命令:

$ patch < mod_auth_mysql-300-apache-22.patch 


打補丁之後,我們按原來的編譯命令重新編譯,這時一般都可以成功了。檢視下/apache/modules目錄下是否有mod_authz_mysql.so檔案,如果沒有,則手工從mod_authz_mysql的編譯路徑下拷貝過去即可。自此mod_authz_mysql編譯算是告一段落了,下面開始配置和使用之旅。

3 -- 在apache中配置使用mod_authz_mysql

首先,編輯apache的/apache/conf/httpd.conf設定檔加入mod_authz_mysql的載入命令:

# LoadModule foo_module modules/mod_foo.so#LoadModule dav_svn_module  modules/mod_dav_svn.so    LoadModule authz_svn_module modules/mod_authz_svn.soLoadModule mysql_auth_module modules/mod_auth_mysql.so


然後,建立mod_authz_mysql所用到的資料庫表:

CREATE DATABASE `db_svn`;CREATE TABLE `db_users` (    `user_name` char(30) NOT NULL,    `user_password` char(20) NOT NULL,    `user_group` char(10) DEFAULT NULL,    PRIMARY KEY (`user_name`)) ENGINE=InnoDB DEFAULT CHARSET=gbk;


最後,在SVN的Location佈建網域中加入mod_authz_mysql的參數資訊:

<ifmodule mod_auth_mysql.c>    <location repos>        DAV svn        SVNParentPath /data/svndata        AuthType Basic        AuthName "SAE User Auth for SVN"        Require valid-user        AuthBasicAuthoritative off        AuthMySQLAuthoritative On        AuthUserFile /dev/null        AuthMySQLHost 192.168.1.118        AuthMySQLPort 4044        AuthMySQLUser db_user        AuthMySQLPassword db_userpasswd        AuthMySQLDB db_svn        AuthMySQLUserTable db_users        AuthMySQLEnable On        AuthMySQLPwEncryption none                AuthzSVNAccessFile /data/svnadmin/useraccess    </location></ifmodule>

mod_authz_mysql接受的配置項說明

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.