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

查看:69
本文介绍了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 文件中,我注释掉了本地绑定命令,因此它应该侦听的不仅仅是本地主机 IP.我可以连接到本地机器上的数据库,而不能连接到另一台服务器上.我试过外部和内部 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,而不是主机名或本地主机.在这两种情况下,您都应该看到 PONG 作为响应.

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 应该是说明性的.如果它在本地而不是远程响应,我会倾向于根据您的节点上 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天全站免登陆