[个人笔记] Linux配置NTP时间同步

Linux - 运维篇

第四章 Linux配置NTP时间同步

  • Linux - 运维篇
  • 系列文章回顾
  • Linux配置NTP时间同步
    • Linux配置CST时区
  • 参考来源


系列文章回顾

第一章 Linux扩容LVM分区
第二章 Linux虚拟机安装VMware Tools插件
第三章 ssh-keygen和openssl工具的使用


Linux配置NTP时间同步

仅实验CentOS 7.X系列的Linux操作系统

[root@localhost ~]# yum install ntp -y		# 安装ntp服务
# 配置ntp时间从X.X.X.X同步
[root@localhost ~]# vim /etc/ntp.conf
...		# 注释掉其他server,仅保留一条server配置
server X.X.X.X iburst
:x

# 配置HWCLOCK硬件层的ntp时间同步
[root@localhost ~]# vim /etc/sysconfig/ntpd
# Command line options for ntpd
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
SYNC_HWCLOCK=yes
:x

[root@localhost ~]# systemctl enable --now ntpd		# 添加ntpd (ntp deamon) 服务的开机自启
[root@localhost ~]# systemctl restart ntpd			# 重启ntpd服务
[root@localhost ~]# ntpstat							# 查看ntp的status状态
[root@localhost ~]# ntpq -p							# 打印remote主机ntp状态

Linux配置CST时区

timedatectl工具配置CST时区

[root@localhost ~]# timedatectl list-timezones					# 查看可配置的时区列表
[root@localhost ~]# timedatectl list-timezones | grep Shanghai	# 仅查看上海时区
[root@localhost ~]# timedatectl set-timezone Asia/Shanghai		# set-timezone选项更改时区

验证

# CentOS 7.X 系列查看当前时区配置
[root@localhost ~]# timedatectl
      Local time: Xxx 2023-0X-XX 08:00:00 CST
  Universal time: Xxx 2023-0X-XX 00:00:00 UTC
        RTC time: Xxx 2023-0X-XX 00:00:00
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: yes
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a

[root@localhost ~]# date
Xxx Xxx XX 00:00:00 CST 2023


参考来源

你可能感兴趣的:(Linux,linux,运维)