tom*_*hel 28 timezone amazon-web-services amazon-elastic-beanstalk
我正在通过AWS Elastic Beanstalk运行EC2实例.不幸的是,它有不正确的时区 - 比它应该提前2小时,因为时区设置为UTC.我需要的是GMT + 1.
有没有办法设置.ebextensions配置,以强制EC2实例使用正确的时区?
vic*_*orx 32
是的你可以.
只需使用以下内容创建文件/.ebextensions/00-set-timezone.config即可
commands:
set_time_zone:
command: ln -f -s /usr/share/zoneinfo/Australia/Sydney /etc/localtime
Run Code Online (Sandbox Code Playgroud)
这假设您使用的是默认的Amazon Linux AMI映像.如果您使用其他Linux发行版,只需将命令更改为在该Linux中设置时区所需的任何内容.
小智 16
这是aws支持业务的回应,这是有效的!
- - 原始信息 - -
如何将环境的时区或更改为Elastic Beasntalk的环境实例改为UTC/GMT -3小时(布宜诺斯艾利斯,阿根廷)?我目前正在使用Amazon Linux 2016.03.在此先感谢您的帮助.问候.
----------回应----------
您好,感谢您就修改Elastic Beanstalk实例时区以使用UTC/GMT -3小时(阿根廷布宜诺斯艾利斯)联系AWS支持,请参阅下面有关如何执行此修改的步骤.
以下示例显示如何使用.ebextensions为Amazon Linux OS修改Elastic Beanstalk环境的时区:
创建一个.config文件,例如00-set-timezone.config文件,并以yaml格式添加以下内容.
container_commands:
01changePHP:
command: sed -i '/PHP_DATE_TIMEZONE/ s/UTC/America\/Argentina\/Buenos_Aires/' /etc/php.d/environment.ini
01achangePHP:
command: sed -i '/aws.php_date_timezone/ s/UTC/America\/Argentina\/Buenos_Aires/' /etc/php.d/environment.ini
02change_AWS_PHP:
command: sed -i '/PHP_DATE_TIMEZONE/ s/UTC/America\/Argentina\/Buenos_Aires/' /etc/httpd/conf.d/aws_env.conf
03php_ini_set:
command: sed -i '/date.timezone/ s/UTC/America\/Argentina\/Buenos_Aires/' /etc/php.ini
commands:
01remove_local:
command: "rm -rf /etc/localtime"
02link_Buenos_Aires:
command: "ln -s /usr/share/zoneinfo/America/Argentina/Buenos_Aires /etc/localtime"
03restart_http:
command: sudo service httpd restart
Run Code Online (Sandbox Code Playgroud)将应用程序部署到Elastic Beanstalk,包括.ebextensions和时区将按照上述方式更改.
我希望有所帮助
问候!
小智 6
如果您在eb环境中运行Windows...。
在项目的根目录中创建一个名为.ebextensions的文件夹。
在该文件夹中,创建一个名为timezone.config的文件
在该文件中添加以下内容:
commands:
set_time_zone:
command: tzutil /s "Central Standard Time"
Run Code Online (Sandbox Code Playgroud)
根据需要设置时区
我在 php.d 文件夹中使用自定义 .ini 文件以及来自http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html#change_time_zone 的常规建议:
根据上述 AWS 文档,该sed命令仅插入(重写) 的第一行/etc/sysconfig/clock,因为第二行 ( UTC=true) 应单独保留。
# .ebextensions/02-timezone.config
files:
/etc/php.d/webapp.ini:
mode: "000644"
owner: root
group: root
content: |
date.timezone="Europe/Amsterdam"
commands:
01_set_ams_timezone:
command:
- sed -i '1 s/UTC/Europe\/Amsterdam/g' /etc/sysconfig/clock
- ln -sf /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime
Run Code Online (Sandbox Code Playgroud)
Lev*_*glu -3
通过putty或ssh连接AMI(亚马逊linux实例)并执行以下命令;
sudo rm /etc/localtime
sudo ln -sf /usr/share/zoneinfo/Europe/Istanbul /etc/localtime
sudo reboot
Run Code Online (Sandbox Code Playgroud)
上述过程的解释很简单;
请注意,我已将我的时区更改为土耳其当地时间,您可以通过使用以下命令列出 zoneinfo 目录来找到您的时区;
ls /usr/share/zoneinfo
Run Code Online (Sandbox Code Playgroud)
或者只是通过维基百科检查时区缩写;
http://en.wikipedia.org/wiki/Category:Tz_database
您还可以查看相关的亚马逊AWS文档;
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html
注意:我不确定这是否是最佳实践(可能不是),但是我已经应用了上面写的过程并且它对我有用。
| 归档时间: |
|
| 查看次数: |
15468 次 |
| 最近记录: |