memcached session会话共享

1 安装依赖包
yum install libevent livevent-devel nc -y

2 yum 安装memcached
yum install -y memcached

3 启动memecached
memcached -m 16m -p 11211 -d -u root -c 8192


4 web端
cd /server/tools/
wget -q http://pecl.php.net/get/memcache-2.2.7.tgz
tar xf memcache-2.2.7.tgz
cd memcache-2.2.7
/application/php/bin/phpize
./configure --enable-memcache --with-php-config=/application/php/bin/php-config --with-zlib-dir
make
make install
echo "extension=memcache.so" >> /application/php/lib/php.ini
/application/php/sbin/php-fpm -t
pkill php
/application/php/sbin/php-fpm -t
/application/php/sbin/php-fpm
/application/php/bin/php -m|grep memcache

5 测试
vim /application/nginx/html/blog/mc.php
<?php
$memcache = new Memcache;
$memcache->connect('172.16.1.51', 11211) or die ("Could not connect");
$memcache->set('key20171117', 'hello,world');
$get_value = $memcache->get('key20171117');
echo $get_value;
?>

6 session 回话保持
sed -i 's#session.save_handler = files#session.save_handler = memcache#;$a session.save_path = "tcp://172.16.1.51:11211"' /application/php/lib/php.ini

测试:

echo '<?php phpinfo(); ?>'                    >/application/nginx/html/blog/test_info.php

7 修改dedecms管理界面无法登陆
sed -i 's#$sessSavePath = DEDEDATA."/sessions_{$enkey}";#$sessSavePath = "tcp://172.16.1.51:11211";#g' /application/nginx/html/www/include/common.inc.php
sed -i 's#$sessSavePath = DEDEDATA."/sessions_{$enkey}";#$sessSavePath = "tcp://172.16.1.51:11211";#g' /application/nginx/html/www/include/vdimgck.php

原文地址:https://www.cnblogs.com/koushuige/p/9306229.html