Linux服务器配置校时

Linux服务器配置校时

在使用服务器时,时间同步很重要,因为很多服务依赖时间,比如数据库、缓存、日志、监控等等。

但是随着运行时间的增长,时间同步的精度会越来越差,因此,建议将服务器的时钟同步到公网时间服务器。

将时区设置为上海

1
sudo timedatectl set-timezone Asia/Shanghai

1.安装

1
2
3
4
5
# 代理配置
#export http_proxy=http://192.168.1.87:3128
#export https_proxy=http://192.168.1.87:3128
yum install chrony -y
# apt install chrony -y

2. 配置国内 NTP 服务器/配置内网ntp服务器

1
2
3
4
5
6
7
8
9
10
sudo vim /etc/chrony.conf


server 192.168.1.244 iburst

server ntp.aliyun.com iburst
server time1.cloud.tencent.com iburst
server ntp1.aliyun.com iburst
server ntp.sjtu.edu.cn iburst
server cn.ntp.org.cn iburst

3. 启动并启用 chronyd 服务\验证 chrony 是否运行

1
2
3
systemctl enable chronyd --now
systemctl start chronyd
systemctl status chronyd

4. 检查时间同步状态

1
2
3
4
## 查看跟踪状态
chronyc tracking
## 查看时间源
chronyc sources -v

5. 设置 timedatectl 使用 NTP

1
timedatectl set-ntp true

6. 再次查看时间状态

1
timedatectl