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: