In a clustered environment and multi-server applications that require log synchronization, in order to ensure normal collaboration between multiple servers, it is necessary to keep their time consistent, and manually adjust the time on multiple servers is extremely unscientific, and this requires the use of NTP time servers to complete the synchronization of time.
One, the installation of NTP server
We only need to install the NTP software, which can be installed using Yum-y install NTP.
However, in addition to NTP, Tzdata Software may also be required to provide time zone-related data files.
650) this.width=650; "Style=" border-bottom:0px;border-left:0px;height:auto;vertical-align:middle;border-top:0px; border-right:0px; "title=" 1435125479101346.png "alt=" 1.png "src=" http://www.178linux.com/ueditor/php/upload/image /20150624/1435125479101346.png "/>
As shown, the/usr/share/zoneinfo directory contains time zone-dependent files. Here's an introduction to NTP-related files:
1)/etc/ntp.conf:ntp The main configuration file of the server.
2)/usr/share/zoneinfo: Time format file for each time zone provided by Tzdata.
3)/etc/sysconfig/clock: Used to define the local time zone, the file is automatically read when the system starts.
4)/etc/localtime: Used to define the local time zone, effective immediately.
For example, the current time zone for this machine is as follows:
650) this.width=650; "Style=" border-bottom:0px;border-left:0px;height:auto;vertical-align:middle;border-top:0px; border-right:0px; "title=" 1435125996125453.png "alt=" 2.png "src=" http://www.178linux.com/ueditor/php/upload/image /20150624/1435125996125453.png "/>
Now you want to change the time zone to America/new_york, you can use the following methods:
650) this.width=650; "Style=" border-bottom:0px;border-left:0px;height:auto;vertical-align:middle;border-top:0px; border-right:0px; "title=" 1435126581885061.png "alt=" 3.png "src=" http://www.178linux.com/ueditor/php/upload/image /20150624/1435126581885061.png "/>
Modify the/etc/sysconfig/clock time zone first, and then copy the corresponding time zone file in the/usr/share/zoneinfo to the/etc/localtime file.
Second, the ntp.conf configuration file Settings
You can use this profile to control permissions and settings for the upstream server.
1. Permission control
Restrict ip| Subnet Mask parameter
Common parameters:
Ignore: Denies all types of NTP connections.
Nomodify: The client cannot modify the server's time parameters by using both NTPC and NTPQ programs.
Noquery: The client cannot use NTPC and NTPQ to query the time server, that is, the NTP service is not provided.
No parameters are added to indicate that there are no restrictions.
2. Set up an upstream NTP server
server [IP or hostname] [prefer]
Prefer indicates that this server is preferred for use.
3. Ntp.conf Configuration Example
650) this.width=650; "Style=" border-bottom:0px;border-left:0px;height:auto;vertical-align:middle;border-top:0px; border-right:0px; "title=" 1435129452109359.png "alt=" 9.png "src=" http://www.178linux.com/ueditor/php/upload/image /20150624/1435129452109359.png "/>
Third, start the NTP service
650) this.width=650; "Style=" border-bottom:0px;border-left:0px;height:auto;vertical-align:middle;border-top:0px; border-right:0px; "title=" 1435129508748899.png "alt=" 4.png "src=" http://www.178linux.com/ueditor/php/upload/image /20150624/1435129508748899.png "/>
The NTP service consumes UDP 123 ports, as shown in:
650) this.width=650; "Style=" border-bottom:0px;border-left:0px;height:auto;vertical-align:middle;border-top:0px; border-right:0px; "title=" 1435129558615343.png "alt=" 6.png "src=" http://www.178linux.com/ueditor/php/upload/image /20150624/1435129558615343.png "/>
After the NTP service is started, it takes about 15 minutes or so to synchronize the time.
You can use the following command to view the synchronization situation for NTP:
650) this.width=650; "Style=" border-bottom:0px;border-left:0px;height:auto;vertical-align:middle;border-top:0px; border-right:0px; "title=" 1435129910101769.png "alt=" 5.png "src=" http://www.178linux.com/ueditor/php/upload/image /20150624/1435129910101769.png "/>
Indicates that an upstream server has been connected, 123MS is corrected, and each 64s is actively synchronized.
650) this.width=650; "Style=" border-bottom:0px;border-left:0px;height:auto;vertical-align:middle;border-top:0px; border-right:0px; "title=" 1435130150744442.png "alt=" 7.png "src=" http://www.178linux.com/ueditor/php/upload/image /20150624/1435130150744442.png "/>
Displays the status of the current NTP server with the upstream NTP server.
Iv. Time synchronization of the client
Use the ntpdate command to synchronize network time.
650) this.width=650; "Style=" border-bottom:0px;border-left:0px;height:auto;vertical-align:middle;border-top:0px; border-right:0px; "title=" 1435130492500440.png "alt=" 8.png "src=" http://www.178linux.com/ueditor/php/upload/image /20150624/1435130492500440.png "/>
We can also use task scheduling to automate synchronization.
650) this.width=650; "Style=" border-bottom:0px;border-left:0px;height:auto;vertical-align:middle;border-top:0px; border-right:0px; "title=" 1435130609830111.png "alt=" 10.png "src=" http://www.178linux.com/ueditor/php/upload/ Image/20150624/1435130609830111.png "/>
Synchronize time every 5 minutes.
Note: The Ntpdate command cannot be used on an NTP server that is running the NTPD service.
NTP time server