ken*_*nny 70 ubuntu timezone automation
当我第一次设置Ubuntu服务器时,我确保我aptitude install tzdata,然后dpkg-reconfigure tzdata我正确地设置了我的时区.
我正在尝试使用脚本自动化我的服务器设置,并注意到这一部分会引发自动化,因为它需要一个用户干预的交互式会话.
有没有办法在没有交互的情况下使用dpkg-reconfigure?
swi*_*ill 84
我找到了以下详细信息.
https://serverfault.com/a/84528
编辑:(从上面的链接复制和粘贴...)
您需要将前端指定为"非交互式",它将保存您当前的设置.
dpkg-reconfigure将当前系统设置作为福音,所以只需按照通常的方式更改时区,并使用非交互式标志运行它
例如,我改为"欧洲/都柏林"我所在的地方:
__PRE__
显然,这允许你使用puppet/cfengine来分发/ etc/timezone.
jos*_*sch 56
sw水的答案不是如何正确完成的.如果您想要无人参与/脚本化的dpkg配置包,那么您希望使用debconf预置机制.
在您的情况下,这意味着您必须执行以下操作:
设置以下环境变量以避免debconf尝试向用户询问任何问题:
export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
然后使用以下preseed.txt文件(或您想要的任何其他设置)预置debconf:
tzdata tzdata/Areas select Europe
tzdata tzdata/Zones/Europe select Berlin
您通过运行以下命令设置上述预置文件:
debconf-set-selections /your/preseed.txt
您现在可以通过apt或运行安装tzdata(如果尚未安装)dpkg-reconfigure.最后,将根据您在debconf预置文件中指定的内容设置tzdata.
请记住,您可以使用debconf preseeding自动执行更多操作.例如,在我的预设中,我总是设置:
locales locales/locales_to_be_generated multiselect     en_US.UTF-8 UTF-8
locales locales/default_environment_locale      select  en_US.UTF-8
您始终可以通过运行来检查当前系统的debconf设置debconf-get-selections.输出应该让您了解使用debconf preseeding能够自动化多少系统配置.
tde*_*ton 24
在16.04中有一个错误(https://bugs.launchpad.net/ubuntu/+source/tzdata/+bug/1554806,在编写此答案时未修复)导致内容/etc/timezone被旧的覆盖运行时的值dpkg-reconfigure -f noninteractive tzdata.修复如下(来自上面的错误报告):
$ sudo ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime
$ sudo dpkg-reconfigure --frontend noninteractive tzdata
Current default time zone: 'America/New_York'
Local time is now:      Mon Feb 20 07:30:33 EST 2017.
Universal Time is now:  Mon Feb 20 12:30:33 UTC 2017.
$ cat /etc/timezone
America/New_York
无需手动更改内容/etc/timezone.这在Ubuntu 16.04.2 LTS上对我有用.
Nil*_*ann 18
这样做Dockerfile:
FROM ubuntu:xenial
## for apt to be noninteractive
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NONINTERACTIVE_SEEN true
## preesed tzdata, update package index, upgrade packages and install needed software
RUN echo "tzdata tzdata/Areas select Europe" > /tmp/preseed.txt; \
    echo "tzdata tzdata/Zones/Europe select Berlin" >> /tmp/preseed.txt; \
    debconf-set-selections /tmp/preseed.txt && \
    rm /etc/timezone && \
    rm /etc/localtime && \
    apt-get update && \
    apt-get install -y tzdata
## cleanup of files from setup
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
在我的实验中,我决定删除/etc必要的文件.
jah*_*jah 10
推进josch的回答; 设置debconf db值并在运行之前删除/etc/{localtime,timezone}dpkg-reconfigure: -
$ echo "tzdata tzdata/Areas select Europe" > some/file.txt
$ echo "tzdata tzdata/Zones/Europe select Berlin" >> some/file.txt
$ sudo debconf-set-selections some/file.txt
$ sudo rm /etc/timezone
$ sudo rm /etc/localtime
$ sudo dpkg-reconfigure -f noninteractive tzdata
Current default time zone: 'Europe/Berlin'
Local time is now:      Thu Sep  1 17:13:16 CEST 2016.
Universal Time is now:  Thu Sep  1 15:13:16 UTC 2016.
已知这种方法适用于: -
小智 7
这是我Dockerfile的最新Ubuntu 18.04 LTS发行版,改编自@NilsBallmann的回答。我还删除了临时文件的创建,并将软件包安装压缩到一个单独的层中:
FROM ubuntu:bionic
RUN export DEBIAN_FRONTEND=noninteractive; \
    export DEBCONF_NONINTERACTIVE_SEEN=true; \
    echo 'tzdata tzdata/Areas select Etc' | debconf-set-selections; \
    echo 'tzdata tzdata/Zones/Etc select UTC' | debconf-set-selections; \
    apt-get update -qqy \
 && apt-get install -qqy --no-install-recommends \
        tzdata \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/*
在带有 systemd 的 Ubuntu 18.04 中,我使用:
  $ sudo timedatectl set-timezone 'Europe/Madrid'
  $ sudo dpkg-reconfigure --frontend noninteractive tzdata
| 归档时间: | 
 | 
| 查看次数: | 50203 次 | 
| 最近记录: |