博客分类: linux

      今天简单的和大家分享一下装ntp服务。完全是个人操作。也希望大家可以一起共同学习

             节省时间。

      首先大家准备三台linux服务器,一个作为服务端。另外2个作为同步服务端。

      

服务器
192.168.1.200
192.168.1.201
192.168.1.202
同步方式
同步windows时间
同步192.168.1.200
192.168.1.200

         首先把三个服务器都装上netdate.命令为yum install ntp ntpdate -y

          装好以后启动NTP服务,命令为/etc/init.d/ntpd start

          启动服务后有Starting ntpd:    【OK】  的字样

          就代表成功启动了。

          接下来就要同步windows时间了。我们要改配置文件。

          使用命令vim /etc/ntp.conf   我们只要修改里面的service 行

          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

          找到这4行并修改为:

           server time.windows.com
          #server 1.centos.pool.ntp.org iburst
          #server 2.centos.pool.ntp.org iburst
          #server 3.centos.pool.ntp.org iburst

           大家可以看到其实只要修改一个配置service文件(随便修改哪一行,其他行在行首加上#把它                变成注释)

          然后保存退出。

          接下来就是重启NTP服务,使用命令:/etc/imnit.d/ntpd restar

              我们192.168.1.200服务器的NTP服务就配置好了。你可以使用date命令查看当前时间                                   和 windows时间是否一样来确定。

            再接下来我们就来同步另外2台服务器。另外2台服务器同步第1台服务器。我们可以做一个               定时任务计划来同步第一个服务器。也可以直接同步第一个服务器

            直接同步第一个服务器命令:/usr/sbin/ntpd 192.168.1.200

            定时任务计划同步则命令为:crontab -e 回车后编辑命令

             */1 * * * * /usr/sbin/ntpd 192.168.1.200  >>/dev/null 

              我这里选择了一分钟同步一次   你们可以根据自己的要求去设计。

             好了,这个小服务就为大家介绍到这里。         谢谢大家