在没有插件的情况下,Heroku上的Redis可能吗? [英] Is redis on Heroku possible without an addon?

查看:141
本文介绍了在没有插件的情况下,Heroku上的Redis可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究如何将Heroku用于使用Redis的PHP应用程序。我已经看到了redis的各种插件。例如,使用Redis To Go,您可以在PHP代码中使用环境变量$ _ENV ['REDISTOGO_URL']作为Redis服务器的URL。



大多数这些附加物有自己的定价方案,我想避免。对于heroku的工作方式我有点困惑。有没有一种方法可以在没有插件的情况下将Redis安装在我自己的Dynos上?

例如,有一台工作服务器充当服务器,另一台充当客户端?如果可能,我该如何去做:


  1. 在Dyno上安装和运行redis服务器?这与安装在任何其他unix盒子上的
    是否一样?我可以只是ssh并安装任何我想要的?

  2. 让一个Dyno通过TCP连接到带有IP /端口的
    另一个?工作人员dynos是否有自己的
    可引用IP地址或可以使用的命名URLS?我能以某种方式从PHP动态获取它们吗?

redis客户端的php代码假设有一个可以连接到的主机和端口,但没有想法是什么?

$ $ p $ $ $ $ $ $ redis = new Predis\\Client(array(
scheme=> ;tcp,
host=> $ host,//我如何获得dyno的主机/端口?
port=> $ port));


解决方案

在dyno上运行redis是一个有趣的想法。您可能需要创建一个redis buildpack ,以便您的dynos可以下载并运行redis。由于redis除了工作的GCC编译器和libc之外没有其他依赖项,所以这在技术上应该是可行的。 / p>

但是,您可能遇到以下问题:


  1. Heroku dynos没有静态IP地址


    dynos没有静态IP地址..你永远不能通过IP直接访问dyno




    即使您在测试仪上设置并运行Redis,我也不知道如何找到该dyno实例并向其发送redis请求。这意味着您的Redis服务器可能必须与您的Web服务器/主应用程序运行在同一台测试仪上。



    表示如果您尝试通过创建更多Web dynos来扩展您的应用程序,您还将创建更多本地redis实例。数据不会在它们之间共享。这不会让我成为一个特别可扩展的设计,但是如果您的应用程序足够小,只需要一个网页动态文件,就可以运行。

  2. Heroku dynos有一个临时文件系统


    nofollow noreferrer>任何其他dyno中的进程都不会看到写入的文件,任何写入的文件在dyno停止或重新启动时将被丢弃
    < blockquote>

    默认情况下,Redis将其RDB文件和AOF日志写入磁盘。您需要定期将它们备份到某处,以便在重新启动dyno后可以获取并恢复。请参阅有关Redis持久性的文档


  3. Heroku dynos经常重启


    Dynos至少每天循环一次,或者当测功机检测到底层硬件出现故障时



    每次dyno启动并恢复数据时,您需要能够启动您的redis服务器。


  4. < Heroku dynos有512MB内存


    每个dyno分配512MB的内存以在中运行


    如果您的Redis服务器与您的Web服务器运行在相同的测试仪上,减去您的主应用程序所需的内存。您需要多少Redis内存?

    以下是一些试图估算和跟踪Redis内存使用情况的问题:


    • Redis:数据库大小与内存比?

    • 分析Redis内存使用情况






    • 总体来说:我建议阅读 12个应用程序应用程序,以更多地了解有关heroku的预期应用程序模型。$ ​​b
      $ b

      简短版本是,dynos旨在成为独立的工作人员,可以很容易地创建和丢弃以满足需求,并且dynos可以访问各种资源来读取或写入数据并提供您的应用程序。 redis实例是资源的一个例子。正如你从上面的项目中看到的那样,通过使用redis附加组件,你可以得到一些保证是静态的,稳定的和可访问的。

      阅读材料:


      1. http://www.12factor.net/ - 特别是流程服务

      2. Heroku流程模型

      3. Heroku Blog - 流程模型


      I'm looking into using Heroku for a PHP app that uses Redis. I've seen the various addons for redis. With Redis To Go, for example, you can use an environment variable $_ENV['REDISTOGO_URL'] in your PHP code, as the URL of the Redis Server.

      Most of these add ons have their own pricing schemes which I'd like to avoid. I'm a little confused about how heroku works. Is there a way that I can just install Redis on my own Dynos without the addons?

      Like for example, have one worker dyno that acts as a server, and another that acts as a client? If possible, how would I go about:

      1. Installing and running the redis server on a Dyno? Is this just the same as installing on any other unix box? Can I just ssh to it and install whatever i want?

      2. Have one Dyno connect to another with an IP/port via TCP? Do the worker dynos have their own reference-able IP addresses or named URLS that I can use? Can I get them dynamically from PHP somehow?

      The php code for a redis client assumes there is a host and port that you can connect to, but have no idea what it would be?

      $redis = new Predis\Client(array(
              "scheme" => "tcp",
              "host" => $host, //how do i get the host/port of a dyno? 
              "port" => $port));
      

      解决方案

      Running redis on a dyno is an interesting idea. You will probably need to create a redis buildpack so your dynos can download and run redis. As "redis has no dependencies other than a working GCC compiler and libc" this should be technically possible.

      However, here are some problems you may run into:

      1. Heroku dynos don't have a static IP address

        "dynos don’t have static IP addresses .. you can never access a dyno directly by IP"

        Even if you set up and run Redis on a dyno I am not aware of a way to locate that dyno instance and send it redis requests. This means your Redis server will probably have to run on the same dyno as your web server/main application.

        This also means that if you attempt to scale your app by creating more web dynos you will also be creating more local redis instances. Data will not be shared between them. This does not strike me as a particularly scalable design, but if your app is small enough to only require one web dyno it may work.

      2. Heroku dynos have an ephemeral filesystem

        "no files that are written are visible to processes in any other dyno and any files written will be discarded the moment the dyno is stopped or restarted"

        By default Redis writes its RDB file and AOF log to disk. You'll need to regularly back these up somewhere so you can fetch and restore after your dyno restarts. See the documentation on Redis persistence.

      3. Heroku dynos are rebooted often

        "Dynos are cycled at least once per day, or whenever the dyno manifold detects a fault in the underlying hardware"

        You'll need to be able to start your redis server each time the dyno starts and restore the data.

      4. Heroku dynos have 512MB of RAM

        "Each dyno is allocated 512MB of memory to operate within"

        If your Redis server is running on the same dyno as your web server, subtract the RAM needed for your main app. How much Redis memory do you need?

        Here are some questions attempting to estimate and track Redis memory use:

      --

      Overall: I suggest reading up on 12 Factor Apps to understand a bit more about heroku's intended application model.

      The short version is that dynos are intended to be independent workers that can be easily created and discarded to meet demand, and that dynos access various resources to read or write data and serve your app. A redis instance is an example of a resource. As you can see from the items above, by using a redis add-on you're getting something that's guaranteed to be static, stable, and accessible.

      Reading material:

      1. http://www.12factor.net/ - specifically Processes and Services
      2. The Heroku Process Model
      3. Heroku Blog - The Process Model

      这篇关于在没有插件的情况下,Heroku上的Redis可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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