Build an NTP server using CentOS

Source: Internet
Author: User

Build an NTP server using CentOS

I. Description

NTP: time synchronization server

Ntpserver ip: 192.168.0.128

Client ip: 192.168.0.129

2. Preparations

1. view the time

[Root @ ntpserver ~] # Date // view the system time

Friday, November 13, 2015 15:58:07 CST

[Root @ ntpserver ~] # Hwclock // view the hardware time

Friday, November 15, November 13, 2015-0.016335 seconds

Note: If the time and time zone are found to be incorrect (the correct time zone should be CST), perform the following two-3 steps.

2. Modify the time zone

[Root @ ntpserver ~] # Vim/etc/sysconfig/clock

ZONE = "Asia/Shanghai"
UTC = true
ARC = false

3. overwrite the system time file

[Root @ ntpserver ~] # Cp-a/usr/share/zoneinfo/Asia/Shanghai/etc/localtime

[Root @ ntpserver ~] # Date // check whether the time is correct again

3. Set up the NTP service

1. Installation

[Root @ ntpserver ~] # Yum install-y ntp

2. Check whether upper-layer services are connected

The country has 6 servers. You can use the following three

1.cn.pool.ntp.org

2.cn.pool.ntp.org

Ch.pool.ntp.org

[Root @ ntpserver ~] # Ntpdate-q 1.cn.pool.ntp.org // test the three servers in sequence. The correct results are as follows:

Server 202.118.1.130, stratum 2, offset 0.003763, delay 0.06880
Server 202.118.1.81, stratum 2, offset 0.004612, delay 0.06927
Server 202.112.29.82, stratum 2, offset 0.041528, delay 0.14401
Server 202.112.31.197, stratum 0, offset 0.000000, delay 0.00000
13 Nov 16:15:02 ntpdate [3300]: adjust time server 202.118.1.130 offset 0.003763 sec

3. Check the current time

[Root @ ntpserver ~] # Ntpdate 1.cn.pool.ntp.org

13 Nov 16:18:35 ntpdate [3332]: the NTP socket is in use, exiting

Note: If the ntpd service is enabled, you must disable the ntpd service before using it.

4. modify the configuration file

[Root @ ntpserver ~] # Vim/etc/ntp. conf // Add the highlighted red part

Restrict default kod nomodify notrap nopeer noquery // The Service rejects all NTP connections by default.

Restrict-6 default kod nomodify notrap nopeer noquery // reject all NTP connections of IPV6

Restrict 127.0.0.1
Restrict-6: 1 // the above two indicate that local access is allowed

Restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap

// When a host with the IP address range of 192.168.0.0/24 is allowed to perform this operation, the client is not allowed to modify it and the ntp server is logged on.

# Server 0.centos.pool.ntp.org
# Server 1.centos.pool.ntp.org
# Server 2.centos.pool.ntp.org
# Server 3.centos.pool.ntp.org

Server 1.cn.pool.ntp.org
Server 2.cn.pool.ntp.org prefer // prefer is preferred


Logfile/var/log/ntp. log

5. Synchronously update hwclock

[Root @ ntpserver ~] # Vim/etc/sysconfig/ntpd

SYNC_HWCLOCK = yes

6. Start the ntp service.

[Root @ ntpserver ~] # Service ntpd start

7. view the connection status with the upper-layer server

[Root @ ntpserver ~] # Ntpq-p

Remote refid st t when poll reach delay offset jitter
========================================================== ================================

+ News.neu.edu.cn 202.118.1.46 2 u 14 128 377 44.480 2.868
* 202.118.1.130 202.118.1.46 2 u 63 128 377 41.726 1.631
LOCAL (0). LOCL. 10 l 9 64 377 0.000 0.000

Note: * indicates the upper-layer NTP currently in use. + indicates that the server is connected and the backup server with time update is available.

8. Confirm that synchronization has been performed.

[Root @ ntpserver ~] # Ntpstat // it takes several minutes to display the following time

Synchronised to NTP server (202.118.1.130) at stratum 3
Time correct to within 60 MS
Polling server every 128 s

9. Add to start

[Root @ ntpserver ~] # Chkconfig ntpd on

Iv. Client settings

1. Synchronization time

[Root @ linux ~] # Ntpdate 192.168.0.128
13 Nov 16:41:52 ntpdate [3293]: adjust time server 192.168.0.128 offset 0.003880 sec

2. Join the task plan

[Root @ linux ~] # Crontab-e // synchronize every morning

0 1 ***/usr/sbin/ntpdate 192.168.0.128

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.