zhangkuilong2018

博客园 首页 联系 订阅 管理

linux服务部署

1、构建NTP时间服务器

ntpdate ntp.fudan.edu.cn 复旦大学的NTP免费提欧共互联网时间同步。

NTP服务器监听端口为UDP的123,需要在本地防火墙开启运行客户端访问123端口;  vi /etc/sysconfig/iptables添加如下规则;

-A INPUT -m stat --state NEW -m udp -p --dport 123 -j ACCEPT

NTP时间服务器配置:

yum install ntp ntpdate -即可!

修改ntp.conf配置文件

cp /etp/ntp.conf   /etc/ntp.conf.bak

vi /etc/ntp.conf 只修改如下两行,把 #号去掉即可!

server 127.127.1.0  #local clock

fudge 127.127.1.0 stratum 10

以守护进程启动ntpd

/etc/init.d/ntpd start 即可

(注意:ntpd启动后,客户机哟啊等几分钟再与其进行时间同步,否则会提示“no server suitable for synchronization fond”错误。)

配置时间同步客户机

crontab -e

增加一行,在每天的6点10分与时间同步服务器进行同步;

10  06 * * * /usr/sbin/ntpdate  ntp-serverd的ip>>/usr/local/logs/crontab/ntpdate.log

备注:

如果客户机没有update,可以yum -y install ntp 即可!

一下是ntp服务器配置文件内容(局域网NTP,如果需要跟外网同步,添加外网server即可)

driftfile/var/lib/ntp/drift

restrict default kod nomodify notrap nopeer noquery

restrict -6 default kod nomodify notrap nopeer noquery

restrict 127.0.0.1

restrict -6::1

server 127.127.1.0  #local clock

fudge 127.127.1.0 stratum 10

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

 

自此,NTP服务搭建完毕,然后在所有客户端crontab里添加如下语句:

0 0 *  * * /usr/sbin/ntpdat 10.0.0.155 >>/data/logs/ntp.log 2>&1

 

第一步,安装NTP服务:

  1)rpm -ivh ntp-4.2.2p1-8.el5.centos.1.rpm

  2)yum install -y ntp ntpdate

 

  第二步,配置NTP服务:

  编辑配置文件/etc/ntp.conf ,配置之前记得先备份文件。          

  restrict default kod nomodify notrap nopeer noquery               restrict、default定义默认访问规则,nomodify禁止远程主机修改本地服务器

  restrict -6 default kod nomodify notrap nopeer noquery   ===== 》》》》》》》 配置,notrap拒绝特殊的ntpdq捕获消息,noquery拒绝btodq/ntpdc查询  

  restrict 127.0.0.1                                (这里的查询是服务器本身状态的查询)。

  restrict -6 ::1

  

  restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap ===== 》》》》》》 这句是手动增加的,意思是指定的192.168.1.0--192.168.1.254的服务器都

                                            可以使用ntp服务器来同步时间。

  server 192.168.1.117                    ===== 》》》》》》   这句也是手动添加的,可以将局域网中的指定ip作为局域网内的ntp服务器。

  server 0.centos.pool.ntp.org

  server 1.centos.pool.ntp.org                ===== 》》》》》》 这3个域名都是互联网上的ntp服务器,也还有许多其他可用的ntp服务器,能连上

  server 2.centos.pool.ntp.org                           外网时,本地会跟这几个ntp服务器上的时间保持同步。

 

  server  127.127.1.0     # local clock               ===== 》》》》》》  当服务器与公用的时间服务器失去联系时,就是连不上互联网时,以局域网内的时

  fudge   127.127.1.0 stratum 10                         间服务器为客户端提供时间同步服务。

 

  第三步,启动NTP服务:

  /etc/init.d/ntpd start                当前启动ntpd服务

  chkconfig  ntpd on                 下次开机自启ntpd服务

  

  第四步,检查时间服务器是否正确同步

  在服务端执行  ntpq -p  下面是我在自己的服务器上面的测试的结果,仅供参考:

  

  当所有远程服务器(不是本地服务器)的jitter值都为4000,并且reach和dalay的值是0时,就表示时间同步有问题。可能原因有2个:

  1)服务器端的防火墙设置,阻断了123端口(可以用 iptables -t filter -A INPUT -p udp --destination-port 123 -j ACCEPT 解决)

  2)每次重启ntp服务器之后,大约3-5分钟客户端才能与服务端建立连接,建立连接之后才能进行时间同步,否则客户端同步时间时会显示

   no server suitable for synchronization found的报错信息,不用担心,等会就可以了。

 

客户端的配置:

  第一步,客户端安装NTP服务:

  yum install -y ntp

  

  第二步,同步时间:

  ntpdate   服务器IP或者域名 

 

posted on 2018-07-10 17:45  zhangkuilong2018  阅读(112)  评论(0编辑  收藏  举报