ntpdate小记
目录
1. 修改时区
2. 同步时间
1. 修改时区
通过ln -sf a b命令,修改a的软连接来改变时区
[root@k8s-master-02 ~]# ll /etc/localtime
lrwxrwxrwx. 1 root root 41 Mar 16 07:08 /etc/localtime -> ../usr/share/zoneinfo/America/Los_Angeles
[root@k8s-master-02 ~]# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
[root@k8s-master-02 ~]# ll /etc/localtime
lrwxrwxrwx 1 root root 33 Mar 20 23:13 /etc/localtime -> /usr/share/zoneinfo/Asia/Shanghai
[root@k8s-master-02 ~]#
2. 同步时间
2.1 通过“ntpdate 服务器”命令实现1次时间同步
[root@k8s-master-02 ~]# ntpdate time1.aliyun.com
20 Mar 23:18:58 ntpdate[10944]: adjust time server 203.107.6.88 offset 0.003002 sec
2.2 设置定时任务
通过“crontab -e”命令编写定时任务(跟vim一样)。通过“crontab -l”命令查看
[root@k8s-master-02 ~]# crontab -e
no crontab for root - using an empty one
crontab: installing new crontab
[root@k8s-master-02 ~]# crontab -l
00 00 * * * ntpdate ntp1.aliyun.com &>/dev/null
分 时 日 月 周
2.3 设置crond 开启自启动
[root@k8s-master-02 ~]# chkconfig --level 345 crond on
Note: Forwarding request to 'systemctl enable crond.service'.
[root@k8s-master-02 ~]# systemctl status crond.service
● crond.service - Command Scheduler
Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2023-03-20 22:54:34 CST; 28min ago
Main PID: 846 (crond)
CGroup: /system.slice/crond.service
└─846 /usr/sbin/crond -n
Mar 20 22:54:34 k8s-master-02 systemd[1]: Started Command Scheduler.
Mar 20 22:54:34 k8s-master-02 systemd[1]: Starting Command Scheduler...
Mar 20 22:54:34 k8s-master-02 crond[846]: (CRON) INFO (RANDOM_DELAY will be scaled with factor 45% if used.)
Mar 20 22:54:34 k8s-master-02 crond[846]: (CRON) INFO (running with inotify support)
[root@k8s-master-02 ~]#

浙公网安备 33010602011771号