前面談到 Samba 伺服器的 MySQL 使用者認證,實際上我老早就寫過 Apache 針對 MySQL 的認證。不過以前只是測試而已,沒有實際使用。前文提到知識管理,實際上在公司內部我們運行著一個基於 pLog 的部落格系統。原先的系統沒有發布到互連網,後來為了能讓公司異地的各分公司也能使用該部落格系統,所以,決定發布到互連網。為了最小程度的降低對部落格系統的 Hack ,所以我決定採用外掛的 mod_auth_mysql 模組來實現使用者認證,從而降低公司內部系統暴露給非授權使用者的風險。
在這次安裝中,才發現原來 mod_auth_mysql 有好幾種版本,而且文檔幾乎都是殘缺不全的。本文下載的程式來自 sourceforge.net (sf.net)
http://modauthmysql.sourceforge.net/
目前的版本為 2.9.0 ,下載後,建立目錄 mod_auth_mysql ,然後進入該目錄解壓。(不要直接在 /usr/local/src 下解壓) ,根據 BUILD 檔案的指示,安裝步驟如下:
apxs -c -lmysqlclient -lm -lz mod_auth_mysql.c
apxs -i mod_auth_mysql.la
然後把下面這行加入 httpd.conf
LoadModule mysql_auth_module modules/mod_auth_mysql.so
實際上編譯和安裝並不困難,配置才是比較大的挑戰,特別是要已經現有的使用者表結合起來。我的 plog 資料庫的使用者表是 plog_users ,我設定的配置如下:
<IfModule mod_auth_mysql.c>
<Location />
AuthType Basic
# 串連資料庫的主機地址,一般用本地串連,所以為 localhost
AuthMySQLHost localhost
AuthMySQLPort nnnn
# 資料庫的名字
AuthMySQLDB plog
# 串連資料庫的使用者?
AuthMySQLUser plogdb_user
# 串連資料庫的口令
AuthMySQLPassword password
# none: not encrypted (plain text)
# crypt: UNIX crypt() encryption
# scrambled: MySQL PASSWORD encryption
# md5: MD5 hashing
# aes: Advanced Encryption Standard (AES) encryption
# sha1: Secure Hash Algorihm (SHA1)`
AuthMySQLPwEncryption md5
AuthMySQLEnable On
AuthMySQLUserTable plog_users
AuthMySQLNameField user
AuthMySQLPasswordField password
AuthMySQLGroupTable plog_users
AuthMySQLGroupField user_group
</Location>
</IfModule>