简体   繁体   English

在 PHP AWS Elastic Beanstalk 上安装 ElastiCache 集群客户端(不创建资源)

[英]Installing ElastiCache Cluster Client on PHP AWS Elastic Beanstalk (without creating resource)

Elastic Beanstalk does not, by default, install the ElastiCache Cluster Client PHP module.默认情况下,Elastic Beanstalk 不安装 ElastiCache Cluster Client PHP 模块。 This is needed to connect to an ElastiCache node cluster.这是连接到 ElastiCache 节点集群所必需的。 Reading around, most of the instructions relate to creating an ElastiCache resource (which I assume will also install the PHP module on the Elastic Beanstalk).仔细阅读,大部分说明都与创建 ElastiCache 资源有关(我假设它还将在 Elastic Beanstalk 上安装 PHP 模块)。 I want to install the PHP module without creating the resource as I want to use an existing cluster.我想安装 PHP 模块而不创建资源,因为我想使用现有集群。 (64bit Linux PHP5.5) (64位Linux PHP5.5)

The module is not installed by default in Beanstalk nor any EC2 instances.默认情况下,该模块未安装在 Beanstalk 或任何 EC2 实例中。 You have to do this yourself.你必须自己做这件事。 This also is something completely different than creating a resource.这也与创建资源完全不同。 You can do one without the other.你可以做一个没有另一个。

The ElastiCache Cluster Client for PHP is an extension that you can install via pecl on your instances. ElastiCache Cluster Client for PHP 是一个扩展,您可以通过 pecl 在您的实例上安装它。 You can do this manually but if the instance is ever destroyed you have to do this again.您可以手动执行此操作,但如果实例被销毁,则必须再次执行此操作。 Therefore it is much better to include the extension's install procedure as part of your deployment process.因此,最好将扩展的安装过程作为部署过程的一部分包含在内。 In a beanstalk app you can do this by adding configurations files in your .ebextensions dir.在 beanstalk 应用程序中,您可以通过在 .ebextensions 目录中添加配置文件来完成此操作。

For example, create these two files.例如,创建这两个文件。 I took these from an actual config file:我从一个实际的配置文件中获取了这些:

#.ebextensions/01fileselasticachephp.config
files:
  "/tmp/AmazonElastiCacheClusterClient-latest-PHP54-64bit.tgz" :
    mode: "000777"
    owner: ec2-user
    group: ec2-user
    source: http://elasticache-downloads.s3.amazonaws.com/ClusterClient/PHP-5.4/latest-64bit

#.ebextensions/02setupelasticachephp.config
commands: 
  01install: 
    command: "pecl install /tmp/AmazonElastiCacheClusterClient-latest-PHP54-64bit.tgz"

The actual name of the files don't matter.文件的实际名称无关紧要。 They are for your own organization purposes.它们用于您自己的组织目的。 Anything in that directory with a .config extension will be executed in alphabetical order, that's why you want to prefix your files with a number so that they get executed in the right order: first download the extension and then install it.该目录中带有 .config 扩展名的任何内容都将按字母顺序执行,这就是为什么您要在文件前加上一个数字,以便它们按正确的顺序执行:首先下载扩展名,然后安装它。 Mind you that you can also do it all at once in one file.请注意,您也可以在一个文件中一次性完成所有操作。 I split it in two because because my actual config files were a lot bigger.我将其一分为二,因为我的实际配置文件要大得多。

Once you have these files in place do a deployment and the Elastic Cache Cluster Client will be installed.准备好这些文件后,进行部署并安装 Elastic Cache Cluster Client。

Note that at the time I deployed this, only the 5.4 client was available that's why my example shows that.请注意,在我部署它时,只有 5.4 客户端可用,这就是我的示例显示的原因。 I don't know if there is a 5.5 client so it's up to you to find out.我不知道是否有 5.5 客户端,因此由您来查找。 You should only need to change the file name and URL to point to the 5.5 extension and should be all set to go.您应该只需要更改文件名和 URL 以指向 5.5 扩展名,并且应该全部设置好。

UPDATE (as of 10/2020)更新(截至 10/2020)

The solution above didn't work for me with the current software versions, but it definitely pointed me in the right direction.上面的解决方案不适用于当前的软件版本,但它确实为我指明了正确的方向。 What didn't work was specifically the pecl install command (even using pecl7 ): it always threw the error "could not extract the package.xml file from [...]" and I couldn't find a solution for it.不起作用的是pecl install命令(即使使用pecl7 ):它总是抛出错误“无法从 [...] 中提取 package.xml 文件” ,我找不到解决方案。

So here's the config file that worked for me:所以这是对我有用的配置文件:

commands:
  02-get-file:
    command: "wget https://elasticache-downloads.s3.amazonaws.com/ClusterClient/PHP-7.3/latest-64bit"
  02-untar:
    command: "sudo tar -zxf latest-64bit amazon-elasticache-cluster-client.so"
  03-move-file:
    command: "sudo mv amazon-elasticache-cluster-client.so /usr/lib64/php/7.3/modules/"
  04-create-ini:
    command: "grep -qF 'extension=amazon-elasticache-cluster-client.so' /etc/php-7.3.d/50-memcached.ini || echo 'extension=amazon-elasticache-cluster-client.so' | sudo tee --append /etc/php-7.3.d/50-memcached.ini"
  05-cleanup:
    command: "sudo rm latest-64bit*"
  06-restart-apache:
    command: "sudo /etc/init.d/httpd restart"

Hope this helps other people!希望这可以帮助其他人!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM