Enable SASL authentication for MemCached

Source: Internet
Author: User
Tags crypt

Enable SASL authentication for MemCached

MemCached starts from version 1.4.3 and supports SASL authentication. It is suitable for multiple applications to share a MemCached cluster. The-enable-sasl option must be added during compilation.

Add the-S option when starting memcached.

"
./Configure-prefix =%{ datadir}-enable-sasl

/Usr/local/bin/memcached-S-d-u nobody
"
SASL authentication can also have many authentication mechanisms, such as pam, shadow, and ldap.

The following configuration uses the shadow Method for authentication.

"
# Modify the/etc/sysconfig/saslauthd File

MECH = shadow

# Set Your SASL authentication Password

Saslpasswd2-c-a memcached memuser

# The final DB file is under/etc /.

-Rw-r -- 1 root 12288 Mar 6 11: 52/etc/sasldb2

# View the current SASL user

Sasldblistusers2
"
 

The following configuration is used for authentication through pam-mysql using the mysql database.

"
# First install pam-mysql

Wget http://prdownloads.sourceforge.net/pam-mysql/pam_mysql-0.7RC1.tar.gz"

./Configure-with-mysql =/opt/pai_install/mysql-5.5.17

Make & make install

# Add a soft link

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

# Modify saslauthd Configuration

MECH = pam

# Edit the memcached configuration of pam. d

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

# Add the memcached configuration file/etc/sasl2/memcached. conf.

Pwcheck_method: saslauthd

# Restart saslauthd

/Etc/init. d/saslauthd restart

# Saslauthd certification is successfully tested

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

0: OK "Success ."
"
 

Java clients of memcached, such as spymemcached and xmemcached, support SASL authentication.

"
# Xmemcached authentication example

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 version pylibmc also supports SASL authentication

Memcached installation and startup script

Performance problems of using Memcached in PHP

Install Memcached in Ubuntu and its command explanation

Install and apply Memcached

Use Nginx + Memcached's small image storage solution

Getting started with Memcached

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.