memcached安裝及開啟SASL驗證
memcached安裝及開啟SASL驗證
安裝memcached
可以yum安裝,但版本較低
yum -y install wget libevent-devel gcc gcc-c++ make cyrus-sasl-devel cyrus-sasl-plain
wget http://memcached.org/files/memcached-1.6.8.tar.gz
tar xf memcached-1.6.8.tar.gz && cd memcached-1.6.8
./configure --prefix=/usr/local/memcached --enable-sasl
make && make install
ln -sf /usr/local/memcached/bin/memcached /usr/bin/memcached
cp scripts/memcached.sysconfig /etc/sysconfig/memcached
cp scripts/memcached.service /etc/systemd/system/
# 預設使用者是nobody
id nobody
systemctl daemon-reload
systemctl enable memcached
systemctl start memcached
systemctl status memcached
開啟SASL及安全設定
SASL開啟後,只有二進位制模式可以使用,telnet無法使用
mkdir /etc/sasl2
cat > /etc/sasl2/memcached.conf << EOF
mech_list: plain
log_level: 5
sasldb_path: /etc/sasl2/memcached-sasldb2
EOF
saslpasswd2 -a memcached -c -f /etc/sasl2/memcached-sasldb2 cacheuser
chown nobody:nobody /etc/sasl2/memcached-sasldb2
# 僅監聽本機迴環IP,開啟SASL
sed -i 's/OPTIONS=""/OPTIONS="-l 127.0.0.1 -S"/' /etc/sysconfig/memcached
# 修改PORT為隨機埠,並iptables中開啟
sed -i 's/PORT="11211"/PORT="32112"/' /etc/sysconfig/memcached
systemctl restart memcached
systemctl status memcached
#區域網使用需要iptables白名單限制
#iptables -A INPUT -p tcp --dport 11211 !-s 192.168.1.1 -j DROP
安裝libmemcached
php和python等語言使用memcached需要安裝這個庫
可以yum安裝,這裡不使用yum安裝
wget https://launchpad.net/libmemcached/1.0/1.0.18/+download/libmemcached-1.0.18.tar.gz
tar xf libmemcached-1.0.18.tar.gz && cd libmemcached-1.0.18
./configure --prefix=/usr/local/libmemcached --with-memcached
make && make install
安裝php擴充套件
memcache擴充套件因為很多問題很少人使用,memcached擴充套件比較不錯,而且支援SASL
php5需要使用2.2.0版本,php7以上可以使用3.x版本
wget http://pecl.php.net/get/memcached-3.1.5.tgz
tar xf memcached-3.1.5.tgz && cd memcached-3.1.5
/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config --enable-memcached --with-libmemcached-dir=/usr/local/libmemcached
make && make install
cat >/usr/local/php/conf.d/005-memcached.ini<<EOF
extension = memcached.so
memcached.use_sasl =1
EOF
/etc/init.d/php-fpm restart
php使用:
$m = new \Memcached();
$m->addServer('127.0.0.1', 11211);
$m->setOption(Memcached::OPT_BINARY_PROTOCOL, true);
$m->setSaslAuthData('cacheuser', 'cacheuserpass');
$m->add('ip', '192.168.1.2', 86400);
var_dump($m->get('ip'));
另外,memcached還支援CAS樂觀鎖
安裝python擴充套件
yum install python-setuptools
easy_install -i https://pypi.tuna.tsinghua.edu.cn/simple pip
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple python-binary-memcached
簡單測試:
Python 2.7.5 (default, Apr 2 2020, 13:16:51)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import bmemcached
>>> bm = bmemcached.Client(('127.0.0.1:11211',),'cacheuser','cacheuser')
>>> bm.set('key1','value1')
True
>>> bm.get('key1')
'value1'
>>>
最後,雖然有獲取所有鍵的方法,但各個客戶端都沒有支援,所以一定要記得key
參考:https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-memcached-on-centos-7
相關文章
- kafka SASL/PLAIN 身份驗證KafkaAI
- kafka SASL認證介紹及自定義SASL PLAIN認證功能KafkaAI
- 安裝 Memcached
- Windows下安裝 和使用Memcached,附memcached-win64-1.4.4-14安裝包Windows
- Memcached安裝與使用例項
- elasticsearch叢集安裝+安全驗證+kibana安裝Elasticsearch
- xx開啟了朋友驗證
- 驗證碼原理及驗證
- Kafka 的安裝及啟動Kafka
- Centos7編譯安裝Memcached教程。CentOS編譯
- 【趙渝強老師】安裝部署Memcached
- docker安裝nextcloud私人網盤,開啟https配置證書DockerCloudHTTP
- Ubuntu 18.04系統編譯安裝Memcached教程。Ubuntu編譯
- Ubuntu 20.04系統編譯安裝Memcached教程。Ubuntu編譯
- 下載安裝webstrom及啟用Web
- Windows系統安裝及啟用Windows
- Supervisor安裝、配置、開啟啟動
- oracle 開啟複雜密碼驗證Oracle密碼
- Debian11系統編譯安裝Memcached教程。編譯
- Centos8 stream系統編譯安裝Memcached教程。CentOS編譯
- Centos安裝PHP7及配置php-fpm開機啟動CentOSPHP
- 安裝node及vue專案的啟動Vue
- 第12篇 window上驗證mysql是否安裝成功MySql
- 【clickhouse專欄】單機版的安裝與驗證
- FastDFS安裝及使用(開山篇)AST
- Yapi——2安裝並開啟YapiAPI
- centos7下安裝php+memcached簡單記錄CentOSPHP
- 阿里雲Linux下安裝libevent+Memcached伺服器端阿里Linux伺服器
- docker安裝及解除安裝Docker
- Docker 驗證 Centos7.2 離線安裝 Docker 環境DockerCentOS
- centos(linux): rpm -V 驗證rpm包安裝程式的安全CentOSLinux
- 安裝ORACLE資料庫,安裝驗證程式所需的初始設定失敗,無法進入安裝程式Oracle資料庫
- php開發memcachedPHP
- kratos安裝及依賴安裝
- macOS Sierra系統下PHP5.6安裝memcached擴充套件MacPHP套件
- Linux下Nginx安裝並開啟SSLLinuxNginx
- 自用驗證類封裝封裝
- 寶塔安裝ssl證書apache打不開Apache