Laravel Homestead Redis 端口转发

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31224482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 11:52:30  来源:igfitidea点击:

Laravel Homestead Redis Port Forwarding

phplaravelredisvagranthomestead

提问by Rafael Beckel

I'm having some trouble here trying to remotely connect to my local Homestead Redis server. I'm using both commandline (redis-cli) and RDM.

我在尝试远程连接到本地 Homestead Redis 服务器时遇到了一些麻烦。我同时使用命令行 (redis-cli) 和RDM

I'm able to connect with Postgresql with PgAdmin in this box, but Redis returns with:

我可以在此框中使用 PgAdmin 连接 Postgresql,但 Redis 返回:

Could not connect to Redis at 127.0.0.1:63790: Connection refused

无法在 127.0.0.1:63790 连接到 Redis:连接被拒绝

My Redis config file "bind" directive is commented, so it should accept connections from all sources. I also tried to stop Redis and start it again, manually pointing to the config file, but without success.

我的 Redis 配置文件“绑定”指令已被注释,因此它应该接受来自所有来源的连接。我也尝试停止Redis并重新启动它,手动指向配置文件,但没有成功。

In my Homestead.yaml config file, Redis port was not forwarded by default. According to Homestead's Documentation, I can set port forwarding like this:

在我的 Homestead.yaml 配置文件中,Redis 端口默认不转发。根据 Homestead 的文档,我可以像这样设置端口转发:

ports:
    - send: 63790
      to: 6379
      protocol: udp

Well, I also tried that and restarted the server, but it didn't work.

嗯,我也尝试过并重新启动服务器,但它没有用。

Am I missing something?

我错过了什么吗?

回答by Shiro

For Homestead 0.4 above. Due to redis security setting, it bind only for 127.0.0.1

对于 Homestead 0.4 以上。由于redis安全设置,只绑定127.0.0.1

In this case, you need to bind extra IP address.

在这种情况下,您需要绑定额外的 IP 地址。

  1. SSH to you server.
  1. SSH 到您的服务器。

$sudo vi /etc/redis/redis.conf

$sudo vi /etc/redis/redis.conf

Scroll to the line bind 127.0.0.1add extra IP address 192.168.10.10, it will look like this

滚动到bind 127.0.0.1添加额外 IP 地址 192.168.10.10 的行,它看起来像这样

bind 127.0.0.1 192.168.10.10

bind 127.0.0.1 192.168.10.10

save and exit.

保存并退出。

  1. Restart redis server and exit your server.
  1. 重新启动 redis 服务器并退出您的服务器。

$sudo /etc/init.d/redis-server restart

$sudo /etc/init.d/redis-server restart

That's all, you should be able connect to your Homestead redis from your host.

就是这样,你应该能够从你的主机连接到你的 Homestead redis。

回答by WLN

SSH to the machine and open /etc/redis/redis.conf.

SSH 到机器并打开/etc/redis/redis.conf.

Find line which starts with binddirective, comment it out and save the file. Then restart redis-server with sudo /etc/init.d/redis-server restart.

查找以bind指令开头的行,将其注释掉并保存文件。然后重新启动 redis-server sudo /etc/init.d/redis-server restart

Thanks to that Redis will listen for all connections from all available interfaces. You don't need any extra port forwarding.

多亏了 Redis 将侦听来自所有可用接口的所有连接。您不需要任何额外的端口转发。

回答by peterm

Remove ports settings from your Homestead.yamlyou won't need it.

删除您Homestead.yaml不需要的端口设置。

Now by default redis in homestead vm is listening on its normal port, 6379.

现在默认情况下,homestead vm 中的 redis 正在侦听其正常端口 6379。

You can ssh into your vm and check it:

您可以通过 ssh 进入您的虚拟机并检查它:

vagrant@homestead:~$ ps -aux | grep redis
redis      996  0.1  0.4  35232  8752 ?        Ssl  01:53   0:00 /usr/bin/redis-server *:6379

To connect to the vm's redis instance from your local machine you need to use an IP address that is specified in your Homestead.yaml. By default it is 192.168.10.10:

要从本地计算机连接到 vm 的 redis 实例,您需要使用在Homestead.yaml. 默认情况下它是192.168.10.10

redis-cli -h 192.168.10.10

If you have domain name set up in your local /etc/hostsfor your app you can use it instead:

如果您在本地/etc/hosts为您的应用程序设置了域名,则可以改用它:

redis-cli -h homestead.app

回答by Mhar Daniel

  1. SSH to your server.

    $sudo vi /etc/redis/redis.conf

  1. SSH 到您的服务器。

    $sudo vi /etc/redis/redis.conf

Scroll to the line bind 127.0.0.1 and change to 0.0.0.0, it will look like this

滚动到该行bind 127.0.0.1 and change to 0.0.0.0,它看起来像这样

bind 0.0.0.0

save and exit.

保存并退出。

  1. Restart redis server and exit your server.

    $sudo service redis-server restart

  1. 重新启动 redis 服务器并退出您的服务器。

    $sudo service redis-server 重启

That's all, you should be able connect to your Homestead redis from your host.

就是这样,你应该能够从你的主机连接到你的 Homestead redis。

redis-cli -h 192.168.10.10