简体   繁体   English

会话存储在云服务器上的内存缓存中

[英]Session storage on memcached on cloud server

I am facing issue in session storage on memcache on both servers. 我在两台服务器的Memcache上的会话存储中都遇到问题。 I installed memcached on cloud servers 我在云服务器上安装了memcached

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. 我有两个服务器“服务器1”和“服务器2”,两个负载均衡器,其中一个用于端口443,另一个用于80。我想在两个服务器上的内存中保留会话,因此,如果一个服务器出现故障,服务器2应该显示同一会话。

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 1)rpm -Uvh http://mirrors.kernel.org/fedora-epel/6/x86_64/epel-release-6-8.noarch.rpm

2) yum install memcached 2)yum安装memcached

3) vi /etc/sysconfig/memcached and added 3)vi / etc / sysconfig / memcached并添加

PORT="11211" PORT =“ 11211”
USER="memcached" USER =“ memcached”
MAXCONN="1024" MAXCONN =“ 1024”
CACHESIZE="264" 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 OPTIONS =“-l 127.0.0.1” //我在这里尝试通过将服务器1的IP放在服务器1的Memcache配置文件上,将服务器2的IP放在服务器2的Memcache配置文件上

4) /etc/init.d/memcached start 4)/etc/init.d/memcached启动
5) chkconfig --levels 235 memcached on 5)chkconfig --levels 235 memcached on
6) yum groupinstall "Development Tools" 6)yum groupinstall“开发工具”
7) yum install zlib-devel libmemcached-devel php-pear php-pecl-memcached php-pecl-memcache 7)yum安装zlib-devel libmemcached-devel php-pear php-pecl-memcached php-pecl-memcache
8) pecl install -f memcached-1.0.0 8)pecl安装-f memcached-1.0.0

After this memcache.ini and memcahed.ini were added to my server 之后,将memcache.ini和memcahed.ini添加到我的服务器中

I opened memcache.ini and changed below settings: 我打开了memcache.ini并更改了以下设置:

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

and in php.ini, I changed 在php.ini中,我更改了

1) session.save_handler = memcache 1)session.save_handler =内存缓存
2) session.save_path = tcp://server1:11211,tcp://server2:11211 2)session.save_path = tcp://服务器1:11211,tcp://服务器2:11211

and restarted apache server 并重新启动Apache服务器

You can see all the configuration settings here: http://www.diehardfans.com/phpinfo.php 您可以在此处查看所有配置设置: 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). 警告:session_write_close()[function.session-write-close]:无法写入会话数据(内存缓存)。 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 请在第702行的/mnt/cbsvolume1/sporters/library/Zend/Session.php中,验证session.save_path的当前设置正确(tcp:// server1:11211,tcp:// server2:11211)

PS: 11211 port is open on cloud passage and we are using round robin algorithm on load balancer. PS:11211端口在云通道中开放,我们在负载均衡器上使用了循环算法。

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 您将无法让Memcache侦听IP地址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. 由于您尝试连接远程服务器,因此需要使Memcache侦听远程计算机可以连接到的IP地址。

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 您没有提及任何IP地址,但是如果我们假设server1的IP地址为192.168.1.100,则需要让内存缓存监听该地址,然后将server2配置为使用192.168.1.100作为其使用的内存缓存服务器的地址因此它可以连接到在server1上运行的memcache服务

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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