首页 文章

创建Elastic Beanstalk环境时“连接被拒绝”

提问于
浏览
2

我正在按照本教程在Elastic Beanstalk环境中设置Laravel:

https://deliciousbrains.com/scaling-laravel-using-aws-elastic-beanstalk-part-3-setting-elastic-beanstalk/

我已经完成了两次完全全新的Laravel安装,只是为了看看它是否有效,并且它有效 .

现在,我再次经历过,但这一次是在我的主要Laravel项目上 . 我已经仔细检查了教程中的所有内容,我相信我没有错过任何内容 .

但是,当我使用教程中的此命令创建环境时(当然填充了值):

eb create --vpc.id {VPCID} --vpc.elbpublic --vpc.elbsubnets {VPCELBSUBNETS} --vpc.ec2subnets {VPCEC2SUBNETS} --vpc.securitygroups {VPCSG}

我收到以下输出错误:

Printing Status:
INFO: createEnvironment is starting.
INFO: Using elasticbeanstalk-us-east-1-487650495335 as Amazon S3 storage bucket for environment data.
INFO: Created security group named: sg-018fe470
INFO: Created load balancer named: awseb-e-7-AWSEBLoa-1M3V7HA824OQ0
INFO: Created security group named: sg-7489ec08
INFO: Environment health has transitioned to Pending. Initialization in progress (running for 19 seconds). There are no instances.
INFO: Created Auto Scaling launch configuration named: awseb-e-7xdtjzn4bn-stack-AWSEBAutoScalingLaunchConfiguration-RZPSBCGFS6HY
INFO: Added instance [i-09cc6faf451ef3670] to your environment.
INFO: Created Auto Scaling group named: awseb-e-7xdtjzn4bn-stack-AWSEBAutoScalingGroup-BQI6UG2OLL7E
INFO: Waiting for EC2 instances to launch. This may take a few minutes.
INFO: Created Auto Scaling group policy named: arn:aws:autoscaling:us-east-1:457680865345:scalingPolicy:a3629314-6d24-4871-a0a1-59d74a1087c2:autoScalingGroupName/awseb-e-7xdtjzn4bn-stack-AWSEBAutoScalingGroup-BQI6UG2OLL7E:policyName/awseb-e-7xdtjzn4bn-stack-AWSEBAutoScalingScaleDownPolicy-1SM372VEND7T6
INFO: Created Auto Scaling group policy named: arn:aws:autoscaling:us-east-1:457680865345:scalingPolicy:b03a08fb-e39f-4dc5-8e00-f81f8059fc56:autoScalingGroupName/awseb-e-7xdtjzn4bn-stack-AWSEBAutoScalingGroup-BQI6UG2OLL7E:policyName/awseb-e-7xdtjzn4bn-stack-AWSEBAutoScalingScaleUpPolicy-AS65NNA5M4PP
INFO: Created CloudWatch alarm named: awseb-e-7xdtjzn4bn-stack-AWSEBCloudwatchAlarmLow-1D9SO13U3HBR0
INFO: Created CloudWatch alarm named: awseb-e-7xdtjzn4bn-stack-AWSEBCloudwatchAlarmHigh-1FUCKP1GWED3A
ERROR: [Instance: i-09cc6faf451ef3670] Command failed on instance. Return code: 1 Output: (TRUNCATED)...
  [PDOException]
  SQLSTATE[HY000] [2002] Connection refused


Script php artisan optimize handling the post-install-cmd event returned with error code 1.
Hook /opt/elasticbeanstalk/hooks/appdeploy/pre/10_composer_install.sh failed. For more detail, check /var/log/eb-activity.log using console or EB CLI.
INFO: Command execution completed on all instances. Summary: [Successful: 0, Failed: 1].
ERROR: Create environment operation is complete, but with errors. For more information, see troubleshooting documentation.

如您所见,在post-install-cmd中运行 php artisan optimize 时会显示 SQLSTATE[HY000] [2002] Connection refused .

如果我尝试在命令行上连接到我的MySQL RDS数据库,它会成功连接,所以看起来连接不是问题所在 .

我花了一段时间才发现post-install-cmd的意思,但我在 composer.json 文件中找到了它:

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "php": ">=5.6.4",
        "laravel/framework": "5.3.*",
        "doctrine/dbal": "^2.5",
        "embed/embed": "^2.7",
        "pda/pheanstalk": "~3.0",
        "guzzlehttp/guzzle": "^6.2",
        "intervention/image": "^2.3",
        "approached/laravel-image-optimizer": "2.3.0",
        "php-ffmpeg/php-ffmpeg": "0.9.3",
        "laravelcollective/html": "^5.3",
        "tymon/jwt-auth": "0.5.*",
        "brozot/laravel-fcm": "^1.2",
        "league/flysystem": "^1.0",
        "cybercog/laravel-ban": "^2.1",
        "pragmarx/firewall": "^1.0",
        "predis/predis": "^1.1",
        "aws/aws-sdk-php": "^3.31",
        "dusterio/laravel-aws-worker": "^0.1.9",
        "fideloper/proxy": "^3.3",
        "aws/aws-sdk-php-laravel": "^3.1",
        "league/flysystem-aws-s3-v3": "^1.0"
    },
    "require-dev": {
        "fzaninotto/faker": "~1.4",
        "mockery/mockery": "0.9.*",
        "phpunit/phpunit": "~5.0",
        "symfony/css-selector": "3.1.*",
        "symfony/dom-crawler": "3.1.*"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-root-package-install": [
            "php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "php artisan key:generate"
        ],
        "post-install-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postInstall",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "Illuminate\\Foundation\\ComposerScripts::postUpdate",
            "php artisan optimize"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}

对我来说,看起来并不是什么都不合适 .

问题是什么?


更新

我只是尝试将我的项目 composer.json 的内容复制并粘贴到Laravel的全新安装中,并且它成功创建了一个Elastic Beanstalk环境,所以看起来我的 composer.json 不是问题所在 .

会是什么呢?


更新#2

看着 eb logs ,我发现了这个:

[Illuminate\Database\QueryException]                                                                                                                                                              
SQLSTATE[HY000] [2002] Connection refused (SQL: select * from `categories` where exists (select * from `topics` where `topics`.`category_id` = `categories`.`id`) order by `name` asc)

[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[HY000] [2002] Connection refused

调用此查询的唯一位置是在我的 AppServiceProvider.php 类中 . 所以我删除了它,以及我添加到类中的所有其他内容,但我仍然得到上面完全相同的错误,即使我删除了该查询调用 .

为什么?

1 回答

  • 0

    要回答我自己的问题,我的 AppServiceProvider.php 文件中的代码(在 boot() 方法中)导致它失败 .

    我所做的是用 boot() 方法包装所有代码:

    public function boot()
    {
        if (!$this->app->runningInConsole())
        {
            // Code here
        }
    }
    

相关问题