LXC容器设置时区

转载自:Proxmox VE 的 LXC 容器安装 NTP 时间同步 — 董仁文的博客 (dongrenwen.github.io)

CentOS 系统修改 NTP 时间同步

修改时区

1
2
# 修改时区
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

安装客户端

1
2
# 安装 ntp 客户端
yum install ntp ntpdate -y

修改配置文件 /etc/ntp.conf 中和 NTP 服务相关部分

1
2
3
4
5
6
7
8
9
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst

# Use Aliyun's ntp server as a fallback.
server ntp.aliyun.com

将 NTP 服务设置成为开机自启

1
2
# 将 ntp 服务设置成为开机自启
systemctl enable ntpd

启动 NTP 服务

1
2
# 启动 ntp 服务
systemctl start ntpd

查看连接的 NTP 服务器

1
2
# 查看连接的 ntp 服务器
ntpq -p

Ubuntu 系统修改 NTP 时间同步

修改时区

1
2
# 修改时区
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

安装客户端

1
2
# 安装 ntp 客户端
apt-get install ntp ntpdate -y

修改配置文件 /etc/ntp.conf 中和 NTP 服务相关部分

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Specify one or more NTP servers.

# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
#pool 0.ubuntu.pool.ntp.org iburst
#pool 1.ubuntu.pool.ntp.org iburst
#pool 2.ubuntu.pool.ntp.org iburst
#pool 3.ubuntu.pool.ntp.org iburst

# Use Ubuntu's ntp server as a fallback.
#pool ntp.ubuntu.com

# Use Aliyun's ntp server as a fallback.
pool ntp.aliyun.com

重启 NTP 服务

1
2
# 重启 ntp 服务
systemctl restart ntp

查看连接的 NTP 服务器

1
2
# 查看连接的 ntp 服务器
ntpq -p