简体   繁体   English

如何在Ubuntu上连接单独的Memcache服务器并从其他服务器使用?

[英]How to connect separate memcache server on Ubuntu and Use from other server?

I have LAMP based PHP & MySql web application hosted on digitalocean separate servers in Singapore region. 我在新加坡地区的Digitalocean单独服务器上托管了基于LAMP的PHP和MySql Web应用程序。 One PHP server + one remote MySql DB server, both are working fine. 一台PHP服务器+一台远程MySql DB服务器,都可以正常工作。 Because the app has to read more than the write, I wanted to add one memcache server. 因为该应用程序必须读取的内容要比写入的更多,所以我想添加一台内存缓存服务器。

What I've tried so far: - Use these steps from this tutorial on a 2gb droplet. 到目前为止,我已经尝试过:-在2gb的小滴上使用本教程中的这些步骤。

Now I have a one memcache server with public ip:129.xxx and private ip:10.xxx , 现在,我有一台具有公共ip:129.xxx和私有ip:10.xxx内存缓存服务器,

1-p 11211 1-p 11211

2.-m 2048 2.米2048

3.-c 1024 3.-c 1024

4.-l 127.0.0.1 4.-l 127.0.0.1

memcached server successfully installed and cached the test data on localhost. memcached服务器已成功安装测试数据并将其缓存在本地主机上。 But I want to use this on other remote web server, 但是我想在其他远​​程Web服务器上使用它,

So I have changed in memcached.conf file -l 127.0.0.1 to THIS memcached server private IP -l 10.xxx . 因此,我将memcached.conf文件-l 127.0.0.1更改为此memcached服务器专用IP -l 10.xxx

Now when I check on memcached server and type ps aux | grep memcached 现在,当我检查memcached服务器并键入ps aux | grep memcached ps aux | grep memcached it shows: ps aux | grep memcached显示:

tcp        0      0 10.x.x.x:11211      *:*     LISTEN     3742/memcached

When I check stats echo "stats settings" | nc 10.xxx 11211 当我检查统计信息时, echo "stats settings" | nc 10.xxx 11211 echo "stats settings" | nc 10.xxx 11211 it shows that all things about memcached server and it is running. echo "stats settings" | nc 10.xxx 11211它显示有关memcached服务器的所有信息,并且它正在运行。

For testing purposes I made a file test.php and save on PHP server and try to connect. 为了进行测试,我制作了一个文件test.php并保存在PHP服务器上并尝试连接。

<?php
  $mc = new Memcached();
  $mc->addServer("**10.x.x.x**", 11211);
  $result = $mc->get("test_key");
  if($result) {
    echo $result;
  } else {
    echo "No data on Cache. Please refresh.";
    $mc->set("test_key", "test data from Cache!") or die ("Failed to save data at Memcached server");
  }
?>

But it is always showing an HTTP ERROR 500 error page, a"page isn't working error on PHP server, 192.xxx is currently unable to handle this request but my other PHP and MySql app running on same server. 但是它始终显示HTTP ERROR 500错误页面,PHP服务器上的“页面无法正常工作”错误, 192.xxx is currently unable to handle this request但是我的其他PHP和MySql应用程序在同一服务器上运行。

The same code is running and caching data successfully on memcached server but not working in remote PHP server. 相同的代码正在memcached服务器上运行并成功缓存数据,但在远程PHP服务器上无法正常工作。

When I try telnet 10.xxx 11211 it is connecting successfully, sudo iptables -L outputs that INPUT policy ACCEPT anywhere. 当我尝试telnet 10.xxx 11211成功连接时, sudo iptables -L在任何地方输出该INPUT策略ACCEPT。

I've tried a lot of googling but it is not helping me with anything. 我已经尝试了很多谷歌搜索,但没有任何帮助。

After checking web server error logs , that shows Class 'Memcached' not found . 检查Web服务器错误日志后,显示Class 'Memcached' not found i have to install memcached php module in web server in order to connect to remotely memcached instance . 我必须在Web服务器中安装memcached php模块才能连接到远程memcached实例。 by typing 通过键入

apt-get install php5-memcached

and change in php.ini by adding 并通过添加更改php.ini

extension = memcached.so , extension = memcached.so

than php web server start connected to remotely memcached server . 比php Web服务器开始连接到远程memcached服务器。 if you want to use memcached for session's than open php.ini file and add 如果要对会话使用memcached,请打开php.ini文件并添加

session.save_handler = memcache session.save_path = 'tcp://10.xxx:11211' and finally, restart server . session.save_handler = memcache session.save_path = 'tcp://10.xxx:11211' ,最后重启服务器。

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

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