Install and configure the NTP server in CentOS
Introduction
See wikipedia: Network Time Protocol (NTP) is a networking protocol for clock synchronization between computer systems over packet-switched, variable-latency data networks.
Refer to Baidu Encyclopedia: NTP is a Network Time Protocol used to synchronize the Time of each computer in the Network.
Environment2 Centos 7
- One NTP server: 192.168.1.101
- One NTP client: 192.168.1.102
The system versions are as follows:
[root@localhost ~]# cat /etc/redhat-releaseCentOS Linux release 7.1.1503 (Core
Install
yum -y install ntp
- View the installed Service: (the ntp service name is ntpd .)
service ntpd status
The following output is displayed: the service has not been started.
[root@localhost ~]# service ntpd statusRedirecting to /bin/systemctl status ntpd.servicentpd.service - Network Time Service Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled) Active: inactive (dead) since Thu 2016-01-28 17:49:27 CST; 1s ago Process: 16123 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS) Main PID: 16124 (code=exited, status=0/SUCCESS)
service ntpd start
ConfigurationConfiguration file:/etc/ntp.conf
The modification allows other hosts to query and synchronize the configuration files through the ntp server. By default, only local hosts are allowed to query, as shown below:
restrict 127.0.0.1 restrict ::1
Modify the above content in the following format
restrict [ip] mask [mask] [parameter]
For example
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
WhereParameter can be the following value
- Ignore: Actually all types of ntp connections
- Nomodify: the client is not allowed to modify the time parameter of the server, but the client is allowed to perform time verification through this host.
- Noquery: the client is not allowed to perform time verification.
- Notrap: No Logon Time is provided.
- Notrust: reject unauthenticated clients
Modify the upstream NTP server address (skip this configuration if it is accessible by default)
What is the configuration of the NTP server on?server [hostname]
Field
server 0.centos.pool.ntp.org iburst........
According to the above format, you can add your own NTP server address
Restart service
service ntpd restart
Test and verificationPerform the following operations on the client:
Install ntpdate (skip this step if it is already installed). The installation method is the same as that for installing ntp, but ntpd service is not started by default after installation, just to install an ntpdate
yum install ntp
Modify the local time to change the local time to a previous time
[root@localhost ~]# date -s 20000101Sat Jan 1 00:00:00 HKT 2000[root@localhost ~]#
Synchronize time using commandsntpdate -u [hostname-of-server]
For example:
[root@localhost ~]# ntpdate -u 192.168.1.10128 Jan 18:10:41 ntpdate[15174]: step time server 192.168.1.101 offset 507319821.530152 sec[root@localhost ~]#
You can see that the time has been fixed.