简体   繁体   中英

Session storage on memcached on cloud server

I am facing issue in session storage on memcache on both servers. I installed memcached on cloud servers

I have two servers "server 1" and "server 2" and two loadbalancers one is if for port 443 and another is for 80. I want to keep session in memcache on both servers so if one server goes down, the server 2 should show same session.

I installed memcache on both servers by following commands:

1) rpm -Uvh http://mirrors.kernel.org/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm

2) yum install memcached

3) vi /etc/sysconfig/memcached and added

PORT="11211"
USER="memcached"
MAXCONN="1024"
CACHESIZE="264"
OPTIONS="-l 127.0.0.1" // I tried here by putting server 1's ip on server 1 memcache config file and server 2's ip on server 2 memcache config file

4) /etc/init.d/memcached start
5) chkconfig --levels 235 memcached on
6) yum groupinstall "Development Tools"
7) yum install zlib-devel libmemcached-devel php-pear php-pecl-memcached php-pecl-memcache
8) pecl install -f memcached-1.0.0

After this memcache.ini and memcahed.ini were added to my server

I opened memcache.ini and changed below settings:

1) memcache.hash_strategy=consistent
2) memcache.session_redundancy=3
3) memcache.allow_failover=1

and in php.ini, I changed

1) session.save_handler = memcache
2) session.save_path = tcp://server1:11211,tcp://server2:11211

and restarted apache server

You can see all the configuration settings here: http://www.diehardfans.com/phpinfo.php

Now on site when I am trying to write/read session it shows error:

Warning: session_write_close() [function.session-write-close]: Failed to write session data (memcache). Please verify that the current setting of session.save_path is correct (tcp://server1:11211,tcp://server2:11211) in /mnt/cbsvolume1/sporters/library/Zend/Session.php on line 702

PS: 11211 port is open on cloud passage and we are using round robin algorithm on load balancer.

Please check and let us know if we are doing any mistake.

Thanks In Advance

Try

session.save_path = "tcp://server1:11211,tcp://server2:11211"

instead of

session.save_path = tcp://server1:11211,tcp://server2:11211

You would not be able to have memcache listening on IP address 127.0.0.1

If you do that, only connections from the local server could connect.

Since you are attempting to have a remote server connect, you would need to have memcache listening on an IP address that a remote machine could connect to.

You do not mention any IP addresses, but if we assume server1 has an IP of 192.168.1.100 then you would need to have memcache listening on that addresss and then configure server2 configured to use 192.168.1.100 as the address of the memcache server it uses so it could connect to the memcache service running on server1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM