Linux设置时间与时区以及对时
Linux设置时区,对时,修改时间
- 列出系统中所有可用的时区
timedatectl list-timezones
- 设置时区
timedatectl set-timezone Asia/Shanghai
- 查看时区状态
timedatectl status
- 设置本机时间
date -s "2025-01:01 12:00:00"
- 写入机器时钟
hwclock --show
hwclock --systohc #同步系统时间给时钟
安装ntpd
yum install ntp ntpdate -y
rpm -qa|grep ntp #查看是否安装完成
ntp配置文件修改
编辑配置文件/etc/ntp.conf:
1、注释默认的server
#server 0.rhel.pool.ntp.org iburst
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburst
2、配置在联网时使用本地服务器时间作为同步时间
server 127.127.1.0
3、配置使用上游服务器时间,作为本地对时,并且允许上游服务器主动修改本机时间
server 192.28.4.1
restrict 192.28.4.1 nomodify notrap noquery
4、与ntpd server上游服务器同步
ntpdate -u 192.28.4.1
5、启动ntpd服务
systemctl start ntpd
systemctl status ntpd
systemctl enable ntpd
6、查看状态
ntpq -p
remote:本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先
refid:参考上一层ntp主机地址
st:stratum阶层
when:多少秒前曾经同步过时间
poll:下次更新在多少秒后
reach:已经向上层ntp服务器要求更新的次数
delay:网络延迟
offset:时间补偿
jitter:系统时间与bios时间差
版权声明:
本站所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自
编程之家!
喜欢就支持一下吧