摘要:本文主要向大家介绍了关于httpd 2.x,mod_auth_MySQL数据库模块的安装配置以及对aes加密的支持,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助。
本文主要向大家介绍了关于httpd 2.x,mod_auth_MySQL数据库模块的安装配置以及对aes加密的支持,通过具体的内容向大家展现,希望对大家学习MySQL数据库有所帮助。
基于开发者文档的安装步骤
注:在笔者的CentOS7测试环境下并不支持aes加密
首先从模块提供的官方站点下载mod_auth_mysql-3.0.0.tar.gz,并下载对应的补丁mod_auth_mysql_3.0.0_patch_apache2.4.diff,解压缩之后,将补丁拷贝到解压目录下面,运行如下命令进行打补丁:
$ patch -p1 < mod_auth_mysql_3.0.0_patch_apache2.4.diff
确保安装了mariadb-libs和mariadb-devel包,并且安装有development Tools包组,如果没有,请自行安装。其目的是为了解决编译安装可能遇到的头文件依赖以及库依赖问题。
利用httpd-tools包中带的apxs工具进行编译:
$ apxs -c -L/usr/lib/mysql -I/usr/include/mysql -lmysqlclient -lm -lz mod_auth_mysql.c
编译完之后,会生成mod_auth_mysql.la文件,再利用如下命令将该模块安装到httpd里面:
$ apxs -i mod_auth_mysql.la
安装完成之后,在/etc/httpd/conf.modules.d目录下面添加一个配置文件,这里为10-mysql.conf,添加如下内容:
LoadModule mysql_auth_module modules/mod_auth_mysql.so
初步添加如下配置信息到/etc/httpd/conf.d/virtualhost.conf里面,配合mysql数据库,即可进行认证:
ServerName www3.stuX.com
LogFormat "%h %u %t \"%r\" %>s \"%{Referer}i\" \"%{User-Agent}i\"" custom3
CustomLog /web/vhosts/www3/access_log custom3
ErrorLogFormat "[%t] [%l] [pid %P] %F: %E: [client %a] %M"
ErrorLog /web/vhosts/www3/error_log
LogLevel info
SetHandler server-status
AuthType Basic
AuthBasicAuthoritative Off
AuthName "auth login"
AuthUserFile /dev/null
AuthMySQLHost 192.168.5.121
AuthMySQLPort 3306
AuthMySQLUser root
AuthMySQLPassword 123456
AuthMySQLDB http_auth
AuthMySQLUserTable mysql_auth
AuthMySQLNameField user_name
AuthMySQLPasswordField user_passwd
AuthMySQLEnable on
AuthMySQLPwEncryption md5
Require valid-user
上述内容当中,关于AuthMySQL的指令,可以从编译安装包中的CONFIGURE文件中查询到。上文所用到的参数的解释如下所示:
指令 解释
AuthMySQLHost mysql的IP地址
AuthMySQLPort mysql的连接端口
AuthMySQLUser mysql的连接用户
AuthMySQLPassword mysql的登录密码
AuthMySQLDB 登录的数据库名称
AuthMySQLUserTable 需要进行用户查询的数据表
AuthMySQLNamedField httpd验证的用户名字段
AuthMySQLPasswordField httpd验证的密码字段
AuthMySQLEnable 开启认证
AuthMySQLPwEncryption 密码加密形式为MD5
配置完毕,重启之后,即可进行认证。
关于mod_auth_mysql.so对于AES加密支持
在该模块的CONFIGURE文档中,提及了两条指令,分别是AuthMySQLPwEncryption以及AuthMySQLSaltField。前者可以在其指令后面添加加密算法,在文档中,该指令的介绍如下所示:
AuthMySQLPwEncryption none | crypt | scrambled | md5 | aes | sha1
The encryption type used for the passwords in AuthMySQLPasswordField:
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)
WARNING: When using aes encryption, the password field MUST be a BLOB type
(i.e. TINYBLOB). MySQL will strip trailing x’20’ characters (blanks), EVEN
IF THE COLUMN TYPE IS BINARY!
AuthMySQLSaltField <> | | mysql_column_name
Contains information on the salt field to be used for crypt and aes
encryption methods. It can contain one of the following:
<>: password itself is the salt field (use with crypt() only)
: “string” as the salt field
mysql_column_name: the salt is take from the mysql_column_name field in the
same row as the password
This field is required for aes encryption, optional for crypt encryption.
It is ignored for all other encryption types.
可以看到,文档中提及到了支持aes加密算法,并且配合AuthMySQLSaltField指令,指明盐字段。不过,在笔者的CentOS7环境上面,如果使用了aes加密,会使得配置了认证的目标页面失效,如下所示:
curl -u admin:admin //www3.stuX.com/status
This server could not verify that you
are authorized to access the document
requested. Either you supplied the wrong
credentials (e.g., bad password), or your
browser doesn‘t understand how to supply
the credentials required.
在httpd的错误日志中,可以看到如下一条:
[error] [pid 9958] mod_auth_mysql.c(1188): [client 192.168.5.180:55586] mysql invalid encryption method as
初步断定,在编译的时候可能没有把aes算法编译进去。依据网上的两篇资料:
Works plain text, AES or SHA-1 fails
mod_auth_mysql with AES encryption (on Fedora 14 x64)
解决方案是在编译的时候添加上-DAES,该选项在文档中并未明文提及到,相关的源代码部分内容如下:
......
......
#if _AES /* Only needed if AES encryption desired */
#include
Server Version: Apache/2.4.6 (CentOS) OpenSSL/1.0.1e-fips PHP/5.4.16
Server MPM: prefork
Server Built: Nov 19 2015 21:43:13
Current Time: Thursday, 08-Jun-2017 16:06:30 CST
Restart Time: Thursday, 08-Jun-2017 16:04:36 CST
Parent Server Config. Generation: 1
Parent Server MPM Generation: 0
Server uptime: 1 minute 53 seconds
Server load: 0.01 0.02 0.05
Total accesses: 1 - Total Traffic: 3 kB
CPU Usage: u0 s0 cu0 cs0
.00885 requests/sec - 27 B/second - 3072 B/request
1 requests currently being processed, 4 idle workers
_W___........................................................... ................................................................ ................................................................ ................................................................ 其他 笔者并未测试动态编译libmysqld.so的可用性,不过笔者认为动态编译仍然是可行的,不过需要将动态库纳入ldconfig管理范畴即可。 诸如此类的第三方模块多半由开发者在Fedora平台上面测试,而头文件依赖和库依赖的不一致性,总会导致各种问题,因此有些时候,需要使用者对其进行一定程度的“量体裁衣”,不能盲目迷信文档。
本文由职坐标整理并发布,希望对同学们学习MySQL有所帮助,更多内容请关注职坐标数据库MySQL数据库频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号