为 Auto Scaling 配置 AWS Elastic Beanstalk 时区
Configuring AWS Elastic Beanstalk Timezone for Auto Scaling
我在 AWS - Elastic Beanstalk 上部署了一个实例服务器,需要 时区配置 ,我在登录时更改了时区使用 ssh 的 EC2 环境,并使用下面列出的 linux 命令更新它;
sudo rm /etc/localtime
sudo ln -sf /usr/share/zoneinfo/Europe/Istanbul /etc/localtime
sudo reboot
一切正常,因为服务器是 运行 作为单个实例。问题出现了,因为我想使用自动缩放、负载平衡功能。在单个实例上,在 linux AMI 上更新时区很好,但在 自动缩放 模式下,因为根据阈值指标,实例是 created/destroyed/recreated,所有配置丢失。
我的简单问题是,如何 change/configure AWS Elastic Beanstalk 中自动扩展的负载均衡模式的时区?
您可以使用ebextensions配置新启动的服务器。
这是一个对我有用的例子。将以下命令添加到文件 .ebextensions/timezone.config
:
commands:
set_time_zone:
command: ln -f -s /usr/share/zoneinfo/US/Pacific /etc/localtime
你也可以在命令行中通过ssh配置:
当连接到您的 Elastic Beanstalk 实例时:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html#change_time_zone
sudo ln -sf /usr/share/zoneinfo/America/Montreal /etc/localtime
您可以使用 eb 命令行工具连接到您的 EB 实例。
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-cmd-commands.html
eb ssh
这里的答案只能部分地为我工作(我在使用上面的答案时部署时出错)。经过一些修改后,以下内容对我有用。我相信它与 "cwd" 和 "permissions".
有关
commands:
0000_0remove_localtime:
command: rm -rf /etc/localtime
0000_1change_clock:
command: sed -i 's/UTC/Asia\/Singapore/g' /etc/sysconfig/clock
cwd: /etc/sysconfig
0000_2link_singapore_timezone:
command: ln -f -s /usr/share/zoneinfo/Asia/Singapore /etc/localtime
cwd: /etc
对于我在 Whosebug 上的第一个答案...我必须向之前的优秀答案添加新信息。
对于AWS Linux 2、Elastic Beanstalk,新增了一种简单的时间设置方法。将以下命令添加到文件 .ebextensions/xxyyzz.config:
container_commands:
01_set_bne:
command: "sudo timedatectl set-timezone Australia/Brisbane"
command: "sudo systemctl restart crond.service"
我不确定第二个命令是否绝对必要,但实例确实在那里很好地发挥了作用(尤其是对于立即发生的任务!)。
我在 AWS - Elastic Beanstalk 上部署了一个实例服务器,需要 时区配置 ,我在登录时更改了时区使用 ssh 的 EC2 环境,并使用下面列出的 linux 命令更新它;
sudo rm /etc/localtime
sudo ln -sf /usr/share/zoneinfo/Europe/Istanbul /etc/localtime
sudo reboot
一切正常,因为服务器是 运行 作为单个实例。问题出现了,因为我想使用自动缩放、负载平衡功能。在单个实例上,在 linux AMI 上更新时区很好,但在 自动缩放 模式下,因为根据阈值指标,实例是 created/destroyed/recreated,所有配置丢失。
我的简单问题是,如何 change/configure AWS Elastic Beanstalk 中自动扩展的负载均衡模式的时区?
您可以使用ebextensions配置新启动的服务器。
这是一个对我有用的例子。将以下命令添加到文件 .ebextensions/timezone.config
:
commands:
set_time_zone:
command: ln -f -s /usr/share/zoneinfo/US/Pacific /etc/localtime
你也可以在命令行中通过ssh配置:
当连接到您的 Elastic Beanstalk 实例时: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/set-time.html#change_time_zone
sudo ln -sf /usr/share/zoneinfo/America/Montreal /etc/localtime
您可以使用 eb 命令行工具连接到您的 EB 实例。 http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/eb3-cmd-commands.html
eb ssh
这里的答案只能部分地为我工作(我在使用上面的答案时部署时出错)。经过一些修改后,以下内容对我有用。我相信它与 "cwd" 和 "permissions".
有关commands:
0000_0remove_localtime:
command: rm -rf /etc/localtime
0000_1change_clock:
command: sed -i 's/UTC/Asia\/Singapore/g' /etc/sysconfig/clock
cwd: /etc/sysconfig
0000_2link_singapore_timezone:
command: ln -f -s /usr/share/zoneinfo/Asia/Singapore /etc/localtime
cwd: /etc
对于我在 Whosebug 上的第一个答案...我必须向之前的优秀答案添加新信息。
对于AWS Linux 2、Elastic Beanstalk,新增了一种简单的时间设置方法。将以下命令添加到文件 .ebextensions/xxyyzz.config:
container_commands:
01_set_bne:
command: "sudo timedatectl set-timezone Australia/Brisbane"
command: "sudo systemctl restart crond.service"
我不确定第二个命令是否绝对必要,但实例确实在那里很好地发挥了作用(尤其是对于立即发生的任务!)。