Bog*_*byk 2 amazon-ec2 amazon-web-services redis laravel
我在安装在EC2实例上的Laravel应用程序连接到ElastiCache Redis时遇到问题,甚至使用EC2实例中的redis-cli.
Laravel
我尝试在database.php中使用predis配置
'redis' => [
'client' => 'predis',
'default' => [
'host' => env('REDIS_HOST', '127.0.0.1'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => 0,
'read_write_timeout' => -1,
'timeout' => 0
],
],
Run Code Online (Sandbox Code Playgroud)
得到' Error while reading line from the server. [tcp:server here]'
我尝试使用相同配置的phpRedis扩展只改变'client' => 'phpredis'并得到错误read error on connection {"exception":"[object] (RedisException(code: 0): read error on connection at vendor/laravel/framework/src/Illuminate/Redis/Connectors/PhpRedisConnector.php:69)
Redis cli
使用redis cli redis-cli -h host_here -p 6379 -a password_here我看到提示,host:6379>但键入任何命令会引发错误Error: Connection reset by peer
ElastiCache Redis配置
我的EC2和弹性缓存在同一个VPC中,使用telnet我可以连接到redis实例
~$ telnet host 6379
Trying 172.31.23.113...
Connected to host.
Escape character is '^]'.
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我在这里回答过:https : //stackoverflow.com/a/48876398/663058
相关详情如下:
由于您拥有集群和TLS,因此您将需要完全不同的配置:
'redis' => [
'client' => 'predis',
'cluster' => env('REDIS_CLUSTER', false),
// Note! for single redis nodes, the default is defined here.
// keeping it here for clusters will actually prevent the cluster config
// from being used, it'll assume single node only.
//'default' => [
// ...
//],
// #pro-tip, you can use the Cluster config even for single instances!
'clusters' => [
'default' => [
[
'scheme' => env('REDIS_SCHEME', 'tcp'),
'host' => env('REDIS_HOST', 'localhost'),
'password' => env('REDIS_PASSWORD', null),
'port' => env('REDIS_PORT', 6379),
'database' => env('REDIS_DATABASE', 0),
],
],
'options' => [ // Clustering specific options
'cluster' => 'redis', // This tells Redis Client lib to follow redirects (from cluster)
]
],
'options' => [
'parameters' => [ // Parameters provide defaults for the Connection Factory
'password' => env('REDIS_PASSWORD', null), // Redirects need PW for the other nodes
'scheme' => env('REDIS_SCHEME', 'tcp'), // Redirects also must match scheme
],
'ssl' => ['verify_peer' => false], // Since we dont have TLS cert to verify
]
]
Run Code Online (Sandbox Code Playgroud)
解释以上内容:
'client' => 'predis':这指定要使用的 PHP 库 Redis 驱动程序 (predis)。'cluster' => 'redis':这告诉 Predis 假设服务器端集群。这只是意味着“跟随重定向”(例如-MOVED响应)。与集群一起运行时,节点将响应-MOVED您必须请求特定密钥的节点。
-MOVED1/ n次异常,n是 Redis 集群中的节点数(它会很幸运,每隔一段时间就会询问正确的节点)'clusters' => [...]:指定节点列表,但仅设置一个“默认”并将其指向AWS 的“配置端点”将使其动态查找任何/所有其他节点(推荐用于 Elasticache,因为您不知道节点何时到来)或去')。'options':对于Laravel,可以在top-level、cluster-level、node选项中指定。(在传递给 Predis 之前,它们在 Illuminate 中组合在一起)'parameters':这些“覆盖” Predis 用于新连接的默认连接设置/假设。由于我们为“默认”连接明确设置了它们,因此不使用它们。但对于集群设置,它们至关重要。“主”节点可能会发回重定向 ( -MOVED) 并且除非设置了参数password并且scheme它将采用默认值,否则到新节点的新连接将失败。| 归档时间: |
|
| 查看次数: |
4911 次 |
| 最近记录: |