CentOS配置NTP Server


The NTP server (ntpd) can be setup to run continuously. This will keep the system clock synchronized. You will also be able to server NTP clients on

yum -y install chrony
systemctl start chronyd

your LAN, if you wish. I had problems with the Red Hat configuration GUI not setting the NTP server up correctly.

1、yum -y install ntp
2、The configuration file is /etc/ntp.conf, and there is also an /etc/ntp directory which contains keys and the drift file. I will show you a working

configuration file, with comments:


restrict default nomodify notrap noquery


server prefer
server cn.pool.ntp.org
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org

restrict mask nomodify notrap
restrict mask nomodify notrap noquery notrust

fudge stratum 10

driftfile /var/lib/ntp/drift
broadcastdelay 0.008

keys /etc/ntp/keys


3、After you install this new version of the config file, you can start the service with /etc/init.d/ntpd startTo monitor the service, you can run the

following command: ntpdc -p or ntpdc -p -n
If you are really impatient, you can use this command to watch the system until it synchronizes: watch nptdc -p -n
The ntpdc command can be run interactively as well. There are a number of informative ntpdc commands, such as iostats, sysstats, and peers.
When enough time has gone by, one of the servers will have an * placed in front of it to tell you that your system is synchronized to it. The lower the stratum number, the more accurate the server.

4、If you want to have the NTP server start up automatically, you can use the checkconfig command as follows:
# chkconfig --level 345 ntpd on
# chkconfig --level 0126 ntpd off
# chkconfig --list | grep ntpd
ntpd 0:off 1:off 2:off 3:on 4:on 5:on 6:off

5、To see that your NTP server is listening on UDP port 123, use the following command:

netstat -nulp

Please note that the NTP server makes NTP queries from a UDP source port of 123. Some firewalls will not allow this, even if ntpdate worked (ntpdate

uses a source port > 1023.)
You can also use the ntpq utility, and the ntptrace utility for additional diagnostic support. For complete documentation on setting up and using NTP

servers, see http://www.ntp.org/.

6、other server you can config crontab
# crontab -e
0 0 * * * /usr/sbin/ntpdate;/sbin/hwclock -w;

分类:Linux操作系统 | 标签: |