【操作系统----Linux】Linux设置时间同步

所有节点都要确保已安装ntpd(在步骤4已安装)

1.首先选择一台服务器作为时间服务器。

   假设选定为node1.sunny.cn服务器为时间服务器。

2.ntp服务器的配置

  修改ntp.conf文件:

 vi /etc/ntp.conf

  一共修改三处内容,将#去掉,并且将网段修改正确。

  restrict 192.168.2.2  mask 192.168.2.255  nomodify notrap

  将以下4个server进行#注释掉。

#server 0.centos.pool.ntp.org iburst

#server 1.centos.pool.ntp.org iburst

#server 2.centos.pool.ntp.org iburst

#server 3.centos.pool.ntp.org iburst

   最后添加俩句话:

server 127.127.1.0 #local clock

fudge  127.127.1.0 stratum 10

3.编辑/etc/sysconfig/ntpd文件,替换为以下内容

vim /etc/sysconfig/ntpd

# Drop root to id 'ntp:ntp' by default.

SYNC_HWCLOCK=yes

OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"

4.设置正确时间,启动ntpd服务,并且设置开机启动

可以忽略这步

date -s ‘2017-01-01 01:01:01’

启动服务service ntpd start

  在/etc/rc.local中添加如下ntp服务器的启动命令行

/etc/init.d/ntpd start

5.root账户下在每个需要同步的子节点编写crontab任务。

命令:

crontab -e

输入以下内容: 

 0-59/10 * * * * /usr/sbin/ntpdate node1.sunny.cn

  这个任务的意义就是每10分钟和node1同步时间。

6.执行/usr/sbin/ntpdate node1.sunny.cn立刻同步服务器时间。

猜你喜欢

转载自blog.csdn.net/ningjiebing/article/details/89410940