在PHP AWS Elastic Beanstalk上安装ElastiCache Cluster Client(无需创建资源)

时间:2014-02-03 12:14:16

标签: php amazon-web-services memcached amazon-ebs amazon-elasticache

默认情况下,Elastic Beanstalk不会安装ElastiCache Cluster Client PHP模块。这是连接到ElastiCache节点群集所必需的。阅读时,大多数指令都与创建ElastiCache资源有关(我假设它也会在Elastic Beanstalk上安装PHP模块)。我想安装PHP模块而不创建资源,因为我想使用现有的集群。 (64位Linux PHP5.5)

2 个答案:

答案 0 :(得分:3)

默认情况下,Beanstalk中没有安装该模块,也没有安装任何EC2实例。你必须自己做。这也与创建资源完全不同。你可以做一个没有另一个。

用于PHP的ElastiCache群集客户端是可以通过pecl在您的实例上安装的扩展。您可以手动执行此操作,但如果实例被销毁,则必须再次执行此操作。因此,在部署过程中包含扩展程序的安装过程要好得多。在beanstalk应用程序中,您可以通过在.ebextensions目录中添加配置文件来完成此操作。

例如,创建这两个文件。我从一个实际的配置文件中获取了这些:

#.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"

文件的实际名称并不重要。它们是出于您自己的组织目的。该目录中具有.config扩展名的任何内容都将按字母顺序执行,这就是为什么您希望在文件前加上一个数字,以便按正确的顺序执行:首先下载扩展然后安装它。请注意,您也可以在一个文件中一次完成所有操作。我把它分成两部分,因为我的实际配置文件要大得多。

准备好这些文件后,执行部署并安装Elastic Cache Cluster Client。

请注意,在我部署此版本时,只有5.4客户端可用,这就是我的示例显示的原因。我不知道是否有5.5客户,所以由您来了解。您只需要更改文件名和URL以指向5.5扩展名,并且应该全部设置为。

答案 1 :(得分:1)

更新(截至10/2020)

以上解决方案不适用于当前软件版本,但绝对可以为我指明正确的方向。没用的是专门的pecl install命令(甚至使用pecl7):它总是抛出错误“无法从[...]中提取package.xml文件” ,但我找不到解决方案。

这是对我有用的配置文件:

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"

希望这对其他人有帮助!