Linux configuration NTP server, time synchronization

Source: Internet
Author: User

When the server is more, time is accurate or not, the same is a big problem. Although this problem is always overlooked, it is necessary to unify the time. Here's how to configure a Linux time server within a LAN.

Configuration of the environment and requirements:

Assume that in the 192.168.0.0 network segment, a Linux machine time server with IP 192.168.0.101 is needed.

192.168.0.101 Server can Sisu network, can be synchronized with the more authoritative public network time server

Automatically synchronizes time to 192.168.0.101 per hour for other machines in the same network segment

1. Install the NTP service and back up the configuration file

[Plain]View PlainCopy
    1. Yum Install NTP
    2. Chkconfig ntpd on
    3. cd/etc/
    4. MV Ntp.conf Ntp.conf.bak



2. vi/etc/ntp.conf, enter the following configuration:

[Plain]View PlainCopy
  1. #设置此服务器同上层服务器做时间同步的IP地址, prefer means the preferred IP address
  2. #经试验, the next few times the server is pretty fast.
  3. Server 210.72.145.44 prefer
  4. Server 218.21.130.42
  5. Server 0.asia.pool.ntp.org
  6. Server 1.asia.pool.ntp.org
  7. Server 2.asia.pool.ntp.org
  8. The time spent #记录上次的NTP server joins the upper NTP server
  9. Driftfile/etc/ntp/drift
  10. #设置默认策略为允许任何主机进行时间同步
  11. Restrict default Ignore
  12. #设置允许访问此时间服务器的时间服务的IP地址
  13. #根据自己实际情况配置
  14. Restrict 127.0.0.1
  15. Restrict 192.168.10.2 # Specify a machine time synchronization
  16. Restrict 192.168.0.0 mask 255.255.255.0 #允许192.168.0.0/254 in-subnet host time synchronization
  17. Restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap #允许任何主机跟进行时间同步
  18. #指定阶层编号为10, reducing its priority.
  19. Fudge 127.127.1.1 Stratum 10
  20. #设置ntp日志的path
  21. statsdir/var/log/ntp/
  22. #设置ntp日志文件
  23. Logfile/var/log/ntp/ntp.log


3. Maintenance of NTP Server

[Plain]View PlainCopy
    1. ----added as a service
    2. Chkconfig--level 345 ntpd on
    3. ----Start
    4. Service NTPD Start
    5. Or
    6. /ETC/RC.D/INIT.D/NTPD start
    7. ----Stop
    8. Service NTPD Stop
    9. Or
    10. /ETC/RC.D/INIT.D/NTPD stop
    11. ----Management Commands
    12. Ntpq–p #查看本机和上层服务器的时间同步结果
    13. Ntptrace #可以用來追踪某台时间服务器的时间对应关系
    14. Ntpdate IP #客户端要和NTP server for clock synchronization.
    15. /var/log/ntp/ntp.log #查看ntp日志


4. Configure Client Linux client: (Time-required machine in LAN)

Clock synchronization with NTP server hourly and write to native BIOS

[Plain]View PlainCopy
      1. echo "*/1 * * * * root/usr/sbin/ntpdate 192.168.0.240;/sbin/hwclock-w" >>/etc/crontab
-------------------------------------------------------------------------------------1.4 Configuring time synchronization between clusters 1.4.1 Configure the primary Time service node in the cluster

1) Check if NTP server is installed

Rpm–qa|grep NTP;

2) Modify the configuration file/etc/ntp.conf

Modify three Places

1. Open Restrict 192.168.60.0 mask 255.255.255.0 nomodify notrap;

2. Comment out

#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 Iburst

3. Add

Server 127.127.1.0

Fudge 127.127.1.0 Stratum 10

3) Modify the configuration file/etc/sysconfig/ntpd

In the first line add: Sync_hwclock=yes

4) Start the NTP service

1. Check that there is no boot

Service NTPD status;

2. Start

Service NTPD start;

3. Set the next system boot, NTPD automatically start

Chkconfig ntpd on;

5) Set the time of the CDH1 node

Execute Date-s 17:55:00, after the modification, remember to execute the CLOCK-W, the system time to write to the CMOS.

1.4.2 configuration in the cluster from the Time service node

In Cdh2, CDH3, CDH4 cluster, set synchronization time every 10 seconds;

To be set under root user is only valid.

Crontab–e;

0-59/10 * * * * */usr/sbin/ntpdate CDH1;

Manual Sync Time

/usr/sbin/ntpdate Cdh1;

Linux configuration NTP server, time synchronization

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.