Redis - 连接到远程服务器 [英] Redis - Connect to Remote Server

查看:716
本文介绍了Redis - 连接到远程服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚使用 http://redis.io/topics/quickstart在我的Ubuntu 10.10服务器。我将服务作为dameon运行(因此可以通过init.d运行)

I've just install Redis succesfully using the instructions on the Quick Start guide on http://redis.io/topics/quickstart on my Ubuntu 10.10 server. I'm running the service as dameon (so it can be run by init.d)

服务器是具有内部和外部IP的Rackspace群集的一部分。主机在端口6379(Redis的标准)上运行

The server is part of Rackspace Cluster with Internal and External IPs. The host is running on port 6379 (standard for Redis)

我在iptables中添加了一行,允许从端口6379进入连接,如下所示:

I've added a row in the iptables to allow incoming connections from port 6379 as shown below:

 ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:6379 

在我的另一台服务器上的PHP代码中,我试图连接到新的Redis服务器:

In my PHP code on another server, I'm trying to connect to the new Redis server here:

$this->load->helper("iredis");

$hostname = "IP ADDRESS HERE";

$redis = new iRedis(array('hostname' => $hostname, 'port' => 6379));

一旦我这样做 - 我总是得到连接拒绝。在我的redis.conf文件中,我有本地绑定命令注释掉,所以它应该监听多于localhost IP。我可以连接到本地机器上的数据库,而不是在另一台服务器上。

Once I do this - I always get a connection refused. In my redis.conf file, I have the local bind command commented out, so it should be listening on more than the localhost IP. I can connect to the database on the local machine just not on another server. I've tried the external and internal IPs with no luck.

有没有任何建议让这个工作?

Any suggestions on getting this to work?

推荐答案

首先我检查一下,确认它正在侦听你希望的IP地址:

First I'd check to verify it is listening on the IPs you expect it to be:

netstat -nlpt | grep 6379

根据启动/停止的方式,您可能没有真正重新启动实例有。 netstat会告诉你是否正在听你认为它在哪里。如果没有,请重新启动它,并确保它重新启动。
如果它重新启动,仍然没有听到你的期望,请检查你的配置文件只是为了确保。

Depending on how you start/stop you may not have actually restarted the instance when you thought you had. The netstat will tell you if it is listening where you think it is. If not, restart it and be sure it restarts. If it restarts and still is not listening where you expect, check your config file just to be sure.

建立后,它正在侦听你期望它,从应该有访问的远程节点尝试:

After establishing it is listening where you expect it to, from a remote node which should have access try:

redis-cli -h REMOTE.HOST ping

您也可以尝试从本地主机,但使用您期望它侦听的IP,而不是主机名或本地主机。你应该看到它在这两种情况下的响应。

You could also try that from the local host but use the IP you expect it to be listening on instead of a hostname or localhost. You should see it PONG in response in both cases.

如果没有,您的防火墙阻止了您。这将是本地IPTables或可能是节点之间的防火墙。您可以向IPtables配置添加日志语句以记录6379上的连接,以查看正在发生的情况。另外,尝试他从本地和非本地到相同的IP重新ping应该是说明性的。如果它是本地响应但不是远程响应,我会倾向于一个干预防火墙,这取决于您的节点IP表规则的复杂性。

If not, your firewall(s) is/are blocking you. This would be either the local IPTables or possibly a firewall in between the nodes. You could add a logging statement to your IPtables configuration to log connections over 6379 to see what is happening. Also, trying he redis ping from local and non-local to the same IP should be illustrative. If it responds locally but not remotely, I'd lean toward an intervening firewall depending on the complexity of your on-node IP Tables rules.

这篇关于Redis - 连接到远程服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆