faith丶

导航

linux系统中设置系统的时间开机自动同步服务器或者节点的时间

一、linux设置开机同步时间

在/etc/init.d/下新建synchronized_date脚本,添加如下内容:

vim /etc/init.d/synchronized_date #
!/bin/bash #chkconfig: 345 63 37 /usr/sbin/ntpdate ntp1.aliyun.com >> /var/log/ntpdate.log 注释: #chkconfig:345 63 37 (数字345是指在运行级别为3、4、5时启动;数字63是指启动的优先级;数字 37是指停止的优先级)

二、修改脚本属性

在linux系统中修改脚本属性
[root@node init.d]$ sudo chmod 755 synchronized_date

[root@node init.d]# ls -l /etc/init.d/synchronized_date
-rwxr-xr-x. 1 root root 92 Dec 25 00:00 /etc/init.d/synchronized_date

三、设置开机自启动

使用chkconfig命令将脚本设置为开机自启
配置脚本自启动
[root@node init.d]$ sudo chkconfig --level 345 synchronized_date on

 

posted on 2020-03-29 10:51  faith丶  阅读(862)  评论(0编辑  收藏  举报