ntp同步 mysql_NTP网络时间服务器

本文介绍了在CentOS系统上安装和配置NTP服务器的三种方法:RPM包、源码编译和yum安装。详细解析了ntp.conf配置文件的关键设置,并展示了如何通过ntpdate命令和修改crontab实现服务器间的时间同步。此外,还提供了配置客户端从NTP服务器同步时间的步骤。
摘要由CSDN通过智能技术生成

一.安装方法:

1.RPM包安装:

mount  /dev/cdrom/media/

rpm -ivh  /media/centos/ntp/-4.XXXX.rpm

2. 源码编译安装:

tar -zxvf ntp-4.2xx.tar.gz    -C /usr/local

cd ntp-4.2.xx

./configure --prefix=/usr/local/ntp   --enable-all-clocks --enable-prase-clocks

make

make install

3.yum安装:

yum  install  ntp

二:配置

[root@NMS ~]# cat /etc/ntp.conf# For more information about this file, see the man pages# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).driftfile /var/lib/ntp/drift# Permit time synchronization with our time source, but do not# permit the source to query or modify the service on this system.restrict default kod nomodify notrap nopeer noqueryrestrict -6 default kod nomodify notrap nopeer noquery# Permit all access over the loopback interface.  This could# be tightened as well, but to do so would effect some of# the administrative functions.restrict 127.0.0.1192.168.1.0 mask 255.255.255.0 nomodifyrestrict -6 ::1# Hosts on local network are less restricted.#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap# Use public servers from the pool.ntp.org project.# Please consider joining the pool (http://www.pool.ntp.org/join.html).server cn.pool.ntp.org

server127.127.1.0

#broadcast 192.168.1.255 autokey# broadcast server#broadcastclient # broadcast client#broadcast 224.0.1.1 autokey # multicast server#multicastclient 224.0.1.1 # multicast client#manycastserver 239.255.254.254 # manycast server#manycastclient 239.255.254.254 autokey # manycast client# Undisciplined Local Clock. This is a fake driver intended for backup# and when no outside source of synchronized time is available. #server127.127.1.0# local clock#fudge127.127.1.0 stratum 10# Enable public key cryptography.#cryptoincludefile /etc/ntp/crypto/pw# Key file containing the keys and key identifiers used when operating# with symmetric key cryptography. keys /etc/ntp/keys# Specify the key identifiers which are trusted.#trustedkey 4 8 42# Specify the key identifier to use with the ntpdc utility.#requestkey 8# Specify the key identifier to use with the ntpq utility.#controlkey 8# Enable writing of statistics records.#statistics clockstats cryptostats loopstats peerstats[root@NMS ~]#

[root@NMS ~]# chkconfig ntpd on[root@NMS ~]# [root@NMS ~]# vi /etc/sysconfig/ntpd[root@NMS ~]# service ntpd restartShutting down ntpd:                                        [  OK  ]Starting ntpd:                                             [  OK  ][root@NMS ~]# [root@NMS ~]# netstat -ntulp |grep Usage: grep [OPTION]... PATTERN [FILE]...Try `grep --help' for more information.[root@NMS ~]# netstat -ntulp |grep 123udp        0      0 192.168.1.200:123         0.0.0.0:*                               25982/ntpd          udp        0      0 127.0.0.1:123               0.0.0.0:*                               25982/ntpd          udp        0      0 0.0.0.0:123                 0.0.0.0:*                               25982/ntpd          udp        0      0 ::1:123                     :::*                                    25982/ntpd          udp        0      0 :::123                      :::*                                    25982/ntpd          [root@NMS ~]# dateTue Aug  4 15:30:34 CST 2015

需要同步时间的服务器:

方法1、

[root@acs421 nrpe2.13]# ntpdate 192.168.1.200

4 Aug 15:39:48 ntpdate[26443]: step time server 192.168.1.200 offset 333893.127016 sec[root@acs421 nrpe-2.13]# dateTue Aug  4 15:39:54 CST 2015[root@acs421 nrpe-2.13]#

并且设备同步时间服务器地址:

[root@acs421 nrpe-2.13]# crontab -e*/1 * * * * /usr/sbin/ntpdate 192.168.1.200

[root@acs421 nrpe-2.13]# crontab -l*/1 * * * * /usr/sbin/ntpdate 192.168.1.200

[root@acs421 nrpe-2.13]# cat /etc/crontab SHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMAILTO=rootHOME=/# For details see man 4 crontabs# Example of job definition:# .---------------- minute (0 - 59)# |  .------------- hour (0 - 23)# |  |  .---------- day of month (1 - 31)# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat# |  |  |  |  |# *  *  *  *  * user-name command to be executed[root@NMS ~]#

方法2、

[root@acs421 nrpe-2.13]# vi /etc/ntp.conf [root@acs421 nrpe-2.13]# cat /etc/ntp.conf

# Hosts on local network are less restricted.#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap# Use public servers from the pool.ntp.org project.# Please consider joining the pool (http://www.pool.ntp.org/join.html).#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 iburstserver  192.168.1.200

[root@NMS ~]# chkconfig ntpd on[root@NMS ~]# [root@NMS ~]# vi /etc/sysconfig/ntpd

[root@NMS ~]# cat /etc/sysconfig/ntpd# Command line options for ntpdOPTIONS="-g"SYNC_HWCLOCK=yes[root@NMS ~]# [root@NMS ~]# service ntpd restart

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值