阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

启用MemCached的SASL认证

99次阅读
没有评论

共计 1983 个字符,预计需要花费 5 分钟才能阅读完成。

MemCached 从 1.4.3 版本开始,能支持 SASL 认证。比较适合多个应用共用一个 MemCached 集群,需要在编译时,加上–enable-sasl 选项。

启动 memcached 时,增加 - S 的选项


./configure –prefix=%{datadir}  –enable-sasl

/usr/local/bin/memcached -S -d -u nobody

SASL 认证也可以有很多种认证机制,比如 pam,shadow,ldap 等

下面配置成使用 shadow 方式去认证


# 修改 /etc/sysconfig/saslauthd 文件

MECH=shadow

# 设置用户的 SASL 认证密码

saslpasswd2 -c -a memcached memuser

# 最终生成的 DB 文件在 /etc/ 下

-rw-r—– 1 root root 12288 Mar  6 11:52 /etc/sasldb2

# 可以查看当前的 SASL 用户

sasldblistusers2

 

下面配置成通过 pam-mysql 使用 mysql 数据库的方式去认证


# 首先安装 pam-mysql

wget “http://prdownloads.sourceforge.net/pam-mysql/pam_mysql-0.7RC1.tar.gz”

./configure –with-mysql=/opt/apps_install/mysql-5.5.17

make & make install

# 增加一个软链接

ln -s /lib/security/pam_mysql.so /lib64/security/pam_mysql.so

# 修改 saslauthd 配置

MECH=pam

# 编辑 pam.d 的 memcached 配置

auth sufficient pam_mysql.so  user=sasl passwd=saslpwd host=xxx db=dbname table=t_app_info usercolumn=appid passwdcolumn=secret crypt=0 sqllog=1 verbose=1

account required pam_mysql.so user=sasl passwd=saslpwd host=xxx db=dbname table=t_app_info usercolumn=appid passwdcolumn=secret crypt=0 sqllog=1 verbose=1

# 新增加 memcached 的配置文件 /etc/sasl2/memcached.conf

pwcheck_method: saslauthd

# 重启 saslauthd

/etc/init.d/saslauthd restart

# 测试 saslauthd 认证已经成功

/usr/sbin/testsaslauthd -s /etc/pam.d/memcached -u 10000 -p pwd

0: OK “Success.”

 

memcached 的 java client,如 spymemcached 和 xmemcached 都已经支持 SASL 认证了


#xmemcached 认证示例

MemcachedClientBuilder builder = new XMemcachedClientBuilder(AddrUtil.getAddresses(“10.x.xx.xx:11211”));

builder.addAuthInfo(AddrUtil.getOneAddress(“10.x.xx.xx:11211”), AuthInfo.plain(“10000”, “pwd”));

builder.setCommandFactory(new BinaryCommandFactory());

client=builder.build();

String v = client.get(“test2”);

python 版本的 pylibmc 也支持 SASL 认证

Memcached 安装及启动脚本 http://www.linuxidc.com/Linux/2013-07/87641.htm

PHP 中使用 Memcached 的性能问题 http://www.linuxidc.com/Linux/2013-06/85883.htm

Ubuntu 下安装 Memcached 及命令解释 http://www.linuxidc.com/Linux/2013-06/85832.htm

Memcached 的安装和应用 http://www.linuxidc.com/Linux/2013-08/89165.htm

使用 Nginx+Memcached 的小图片存储方案 http://www.linuxidc.com/Linux/2013-11/92390.htm

Memcached 使用入门 http://www.linuxidc.com/Linux/2011-12/49516p2.htm

正文完
星哥说事-微信公众号
post-qrcode
 
星锅
版权声明:本站原创文章,由 星锅 2022-01-20发表,共计1983字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中