GVKun编程网logo

ElasticBeanstalk Java,Spring活动配置文件(java spring 配置文件在哪里)

14

针对ElasticBeanstalkJava,Spring活动配置文件和javaspring配置文件在哪里这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展amazon-web-service

针对ElasticBeanstalk Java,Spring活动配置文件java spring 配置文件在哪里这两个问题,本篇文章进行了详细的解答,同时本文还将给你拓展amazon-web-services – 在单个docker容器环境中配置nginx(AWS ElasticBeanstalk)、AWS Elastic BeanStalk php.ini文件更新、AWS Elastic Beanstalk – 配置我的nginx设置以增加Java Spring maven应用程序的超时、AWS ElasticBeanstalk EC2终止保护等相关知识,希望可以帮助到你。

本文目录一览:

ElasticBeanstalk Java,Spring活动配置文件(java spring 配置文件在哪里)

ElasticBeanstalk Java,Spring活动配置文件(java spring 配置文件在哪里)

我正在尝试通过AWS ElasticBeanstalk启动spring boot .jar。一切正常,配置文件为“默认”。是否有人知道如何为Java
ElasticBeanstalk应用程序(而非tomcat)设置活动配置文件(spring.profiles.active)。我总是收到“未设置有效的配置文件,回退到默认配置文件:默认”。有没有办法直接设置虚拟机选项?

我已经在AWS管理控制台中设置了“ spring.profiles.active”环境属性,但是它不起作用。

谢谢和最好的问候亚历克斯

答案1

小编典典

当设置为环境变量与命令行属性时,大小写不同。尝试在EB配置中设置SPRING_PROFILES_ACTIVE。

amazon-web-services – 在单个docker容器环境中配置nginx(AWS ElasticBeanstalk)

amazon-web-services – 在单个docker容器环境中配置nginx(AWS ElasticBeanstalk)

我目前正在使用AWS ElasticBeanstalk中的single container docker environment部署Django uWsgi应用程序.这个环境已经附带了Nginx,我目前正在尝试配置它.

我想要实现以下目标:

>在环境的负载均衡器处终止HTTPS
>使用Nginx(随环境提供)将HTTP请求重定向到HTTPS
>将请求从Nginx传递给uwsgi

环境信息:

>配置和解决方案堆栈名称:单容器Docker 1.11
版本2.3.0
> AMI:运行Docker的64位Amazon Linux 2016.09 v2.3.0
1.11.2
2016.09.0
> Docker版本:1.11.2
>代理服务器:Nginx 1.10.1

这是我目前的配置:

.ebxtensions / 00-负载均衡器-terminatehttps.config

option_settings:
  aws:elb:listener:443:
    ListenerEnabled: true
    ListenerProtocol: HTTPS
    SSLCertificateId: <resource-id-here>
    InstancePort: 443
    InstanceProtocol: HTTP
  aws:elb:listener:80:
    ListenerEnabled: true
    ListenerProtocol: HTTP
    InstancePort: 80
    InstanceProtocol: HTTP

.ebextensions / 01-Nginx的-proxy.config

files:
  "/etc/Nginx/sites-available/test.domain.com.conf":
    mode: "000644"
    owner: root
    group: root
    content: |
      server {
        listen 80;
        server_name test.domain.com;
        access_log /var/log/Nginx/$server_name.access.log;

        location / {
          return 301 https://$server_name$request_uri;
        }

        location = /status/ {
          access_log /var/log/Nginx/$server_name.healthd.log healthd;
          include uwsgi_params;
          uwsgi_pass docker;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Host $host;
          proxy_set_header X-Forwarded-Server $host;
        }

      }

      server {
        listen 443;
        server_name test.domain.com;
        access_log /var/log/Nginx/$server_name.access.log;

        location / {
          include uwsgi_params;
          uwsgi_pass docker;
          proxy_set_header Host $host;
          proxy_set_header X-Real-IP $remote_addr;
          proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
          proxy_set_header X-Forwarded-Host $host;
          proxy_set_header X-Forwarded-Server $host;
          client_max_body_size 100m;
        }

        location /static {
            alias /var/www/static;
        }
      }

commands:
   00_enable_site:
    command: 'rm -f /etc/Nginx/sites-enabled/* && ln -s /etc/Nginx/sites-available/test.domain.com.conf /etc/Nginx/sites-enabled/test.domain.com.conf'

.ebextensions / 02-healthcheckurl.config

option_settings:
  - namespace:  aws:elasticbeanstalk:application
    option_name:  Application Healthcheck URL
    value:  /status/

application.ini(uwsgi config)

[uwsgi]
master = true
socket = :3031
processes = 4
enable-threads = true
threads = 2
chdir = /opt/app/
wsgi-file = test/wsgi.py
logto2 = /var/log/uwsgi.log
callable = application
py-autoreload = 3

现在,在测试配置时:

检查http://test.domain.com/status/工作正常

$wget http://test.domain.com/status/
--2017-01-14 23:00:18--  http://test.domain.com/status/
Resolving test.domain.com... 52.xx.xx.xx, 52.xx.xx.xy
Connecting to test.domain.com|52.xx.xx.xx|:80... connected.
HTTP request sent, awaiting response... 200 OK

检查http://test.domain.com/hello/无法按预期工作.它重定向很好,但它会挂起,直到请求超时.

$wget http://test.domain.com/hello/
--2017-01-14 22:59:13--  http://test.domain.com/hello/
Resolving test.domain.com... 52.xx.xx.xx, 52.xx.xx.xy
Connecting to test.domain.com|52.xx.xx.xx|:80... connected.
HTTP request sent, awaiting response... 301 Moved Permanently
Location: https://test.domain.com/hello/ [following]
--2017-01-14 22:59:15--  https://test.domain.com/hello/
Connecting to test.domain.com|52.xx.xx.xx|:443... connected.
HTTP request sent, awaiting response... 408 REQUEST_TIMEOUT
2017-01-14 23:00:17 ERROR 408: REQUEST_TIMEOUT.

解决方法:

根据@ deviavir的建议,我需要允许来自负载均衡器的流量进入EC2实例.

这是我的最终配置:

   .ebextensions
   |-- 00-resources.config
   |-- 01-Nginx-proxy.config

.ebextensions / 00-resources.config:

Resources:
  AWSEBSecurityGroup:
    Type: "AWS::EC2::SecurityGroup"
    Properties:
      GroupDescription: "Allow traffic to ports 80 and 443 from the load balancer. Restrict SSH access."
  AWSEBLoadBalancer:
    Type: "AWS::ElasticLoadBalancing::LoadBalancer"
    Properties:
      Listeners:
        - {LoadBalancerPort: 80,
          Protocol: 'HTTP',
          InstancePort: 80,
          InstanceProtocol: 'HTTP'}
        - {LoadBalancerPort: 443,
          Protocol: 'HTTPS',
          InstancePort: 443,
          InstanceProtocol: 'HTTP',
          SSLCertificateId: 'arn:aws:acm:us-east-1:xxxx:certificate/yyyy'}
      HealthCheck:
        Target: HTTP:80/status/
        HealthyThreshold: '3'
        UnhealthyThreshold: '5'
        Interval: '30'
        Timeout: '5'
  port80SecurityGroupIngress:
    Type: "AWS::EC2::SecurityGroupIngress"
    Properties:
      GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]}
      IpProtocol: tcp
      ToPort: 80
      FromPort: 80
      SourceSecurityGroupName: {"Fn::GetAtt" : ["AWSEBLoadBalancer" , "SourceSecurityGroup.GroupName"]}
  Port443SecurityGroupIngress:
    Type: "AWS::EC2::SecurityGroupIngress"
    Properties:
      GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]}
      IpProtocol: tcp
      ToPort: 443
      FromPort: 443
      SourceSecurityGroupName: {"Fn::GetAtt" : ["AWSEBLoadBalancer" , "SourceSecurityGroup.GroupName"]}
  SSHSecurityGroupIngress:
    Type: "AWS::EC2::SecurityGroupIngress"
    Properties:
      GroupId: {"Fn::GetAtt" : ["AWSEBSecurityGroup", "GroupId"]}
      IpProtocol: tcp
      ToPort: 22
      FromPort: 22
      CidrIp: xx.xx.xx.xx/yy

.ebextensions / 01-Nginx的-proxy.config:

files:
  "/etc/Nginx/sites-available/test.domain.com.conf":
    mode: "000644"
    owner: root
    group: root
    content: |
      server {
        listen 80;
        server_name test.domain.com;
        access_log /var/log/Nginx/$server_name.access.log;

        location / {
          return 301 https://$server_name$request_uri;
        }

        location = /status/ {
          access_log /var/log/Nginx/$server_name.status.log;
          uwsgi_pass docker;
          include uwsgi_params;
        }

      }

      server {
        listen 443;
        server_name test.domain.com;
        access_log /var/log/Nginx/$server_name.access.log;

        location / {
          uwsgi_pass docker;
          include uwsgi_params;
          client_max_body_size 100m;
        }

        location /static/ {
            root /var/www;
        }
      }

commands:
   00_enable_site:
    command: 'rm -f /etc/Nginx/sites-enabled/* && ln -s /etc/Nginx/sites-available/test.domain.com.conf /etc/Nginx/sites-enabled/test.domain.com.conf'

AWS Elastic BeanStalk php.ini文件更新

AWS Elastic BeanStalk php.ini文件更新

我想将我的PHP web应用程序的最小上传文件大小从2MB增加到64 MB.我有一个存储在.ebextensions目录中的配置文件..在部署到aws时,发生了一个错误:

应用程序版本try10中的配置文件.ebextensions / yep.config包含无效的YAML或JSON. YAML异常:在“”,第7行,第7列中扫描一个简单的键时:upload_max_filesize = 64M ^在“”,第8行,第7列中找不到预期的’:’:post_max_size = 64M ^,JSON异常:意外的字符( f)在位置0处.更新配置文件.

下面是我开始使用的配置文件.我花了8个小时进行故障排除而没有运气.任何帮助都将非常有用.

files:
"/etc/PHP.ini":
  mode: "000755"
  owner: root
  group: root
  content: |
  upload_max_filesize = 64M
  post_max_size = 64M

解决方法:

我在Elastic Beanstalk应用程序中成功使用它.只需将以下内容放入应用程序根目录中.ebextensions目录内的yep.config文件中即可.

files:
  "/etc/PHP.d/project.ini" :
    mode: "000644"
    owner: root
    group: root
    content: |
      upload_max_filesize=64M
      post_max_size=64M

AWS Elastic Beanstalk – 配置我的nginx设置以增加Java Spring maven应用程序的超时

AWS Elastic Beanstalk – 配置我的nginx设置以增加Java Spring maven应用程序的超时

所以我使用AWS Elastic Beanstalk来托管我的Java Spring应用程序,并且某些请求需要60多秒才能完成.我想提高超时限额以便完成,所以我开始关注this教程.

我成功地在ELB控制台中更改了Load Balancer超时,但是我在更改Nginx代理的设置时遇到了问题.本教程建议创建一个名为.ebextensions / Nginx-timeout.config的文件,其中.ebextensions位于“我项目的根目录”中.本教程假设我们正在使用带有Docker的Beanstalk,我不是,所以我找到了this链接,建议用这些内容填充Nginx-timeout.config的内容:

files:
    "/tmp/proxy.conf":
        mode: "000644"
        owner: root
        group: root
       content: |
           proxy_send_timeout 1200;
           proxy_read_timeout 1200;
           send_timeout       1200;
container_commands:
    00-add-config:
        command: cat /tmp/proxy.conf >> /var/elasticbeanstalk/staging/Nginx/conf.d/elasticbeanstalk/00_application.conf
    01-restart-Nginx:
        command: service Nginx restart

我的一个问题是我不确切知道我的应用程序的根目录.我正在使用Maven和Java Spring Boot,所以我的结构如下:

enter image description here

我不确定是否应该将.ebextensions放在我的pom.xml文件所在的基本目录中,或者放在其他地方.我正在部署这个应用程序的方法是使用maven来构建一个jar,然后上传jar,我不确定这是否会改变任何东西.

关于这个问题的任何建议?我目前也在试图看看我是如何ssh到我的实例可能会改变那里的Nginx服务器的配置,但我不确定这是否可行.

解决方法:

可能重复Where to add .ebextensions in a WAR?,但由于您没有使用war包装,您可以使用基于procfile的configuration并将jar和.ebextensions存档到附加的zip层.然后你的zip文件结构应如下所示:

your_app.zip
|
|_.ebextensions
|   |_ Nginx-timeout.config
|
|_ your_app.jar
|_ procfile

并且您的procfile应该包含您的jar文件启动说明

$cat procfile
web: java -jar your_app.jar

AWS ElasticBeanstalk EC2终止保护

AWS ElasticBeanstalk EC2终止保护

无法在启动配置中执行此操作,因为AutoScaling会忽略该设置,即使已启用它也会终止您的实例。您将必须使用启动模板,并且到那时,如果您自定义所有内容,那么使用beantalk并没有多大意义。

我们今天的关于ElasticBeanstalk Java,Spring活动配置文件java spring 配置文件在哪里的分享已经告一段落,感谢您的关注,如果您想了解更多关于amazon-web-services – 在单个docker容器环境中配置nginx(AWS ElasticBeanstalk)、AWS Elastic BeanStalk php.ini文件更新、AWS Elastic Beanstalk – 配置我的nginx设置以增加Java Spring maven应用程序的超时、AWS ElasticBeanstalk EC2终止保护的相关信息,请在本站查询。

本文标签: