简体   繁体   中英

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. One PHP server + one remote MySql DB server, both are working fine. 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.

Now I have a one memcache server with public ip:129.xxx and private ip:10.xxx ,

1-p 11211

2.-m 2048

3.-c 1024

4.-l 127.0.0.1

memcached server successfully installed and cached the test data on localhost. But I want to use this on other remote web server,

So I have changed in memcached.conf file -l 127.0.0.1 to THIS memcached server private IP -l 10.xxx .

Now when I check on memcached server and type ps aux | grep memcached ps aux | grep memcached it shows:

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 it shows that all things about memcached server and it is running.

For testing purposes I made a file test.php and save on PHP server and try to connect.

<?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.

The same code is running and caching data successfully on memcached server but not working in remote PHP server.

When I try telnet 10.xxx 11211 it is connecting successfully, sudo iptables -L outputs that INPUT policy ACCEPT anywhere.

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 . i have to install memcached php module in web server in order to connect to remotely memcached instance . by typing

apt-get install php5-memcached

and change in php.ini by adding

extension = memcached.so ,

than php web server start connected to remotely memcached server . if you want to use memcached for session's than open php.ini file and add

session.save_handler = memcache session.save_path = 'tcp://10.xxx:11211' and finally, restart server .

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