Time server (Linux NTP)

Source: Internet
Author: User
Tags local time

System time and hardware time

Hardware time: Recorded on the motherboard CMOS time, by the motherboard of the button battery power operation, the computer shuts down after the normal operation.

System time: The clock in Linux kernel, when the operating system starts, will read the hardware time, and then run independently.

Run long, there will be a greater deviation between the two. The same is true for clusters, where there are deviations in time between different machines. This is where time synchronization is required.


1) View system time: Date

Date Direct view:

[Email protected] ~]# Datesat June 6 00:01:08 CST 2015

You can also format the output:

[[Email protected] ~]# date + "%y-%m-%d%h:%m:%s" 2015-06-06 00:00:58

Reset system time: date-s or date--set= "pattern"

[Email protected] ~]# date--set= "2015-06-11 15:15:00" Thu June one 15:15:00 CST 2015[[email protected] ~]# date + "%y-%m-%d %h:%m:%s "2015-06-11 15:15:16


2) View hardware time: Hwclock

Hwclock Direct view:

[Email protected] ~]# Hwclockthu June 11:18:26 PM CST-0.345021 seconds

To reset hardware time:

[Email protected] ~]# hwclock--set--date= "2015-06-06 00:00:00" [[email protected] ~]# Hwclocksat June 12:00:06 AM CST-0.594816 seconds

Hardware time synchronized to system time: Hwclock-s or Hwclock--hctosys

System time synchronized to hardware time: hwclock-w or Hwclock--SYSTOHC


Time and time zone

( When coordinating the world, also known as the World Unification Time ), the computer set is this time, when the time server out of sync time, the other side provides this time, and then the local computer due to the time zone file settings, so that the time displayed in the local time zone. The following describes how to set the time zone.

In the/usr/share/zoneinfo directory has compiled the timezone file, the major cities of the country are basically here, you can view the file format through the files:

[Email protected] zoneinfo]# file utcutc:timezone data, version 2, 1 GMT time flag, 1 STD time flag, no leap seconds, no Transition times, 1 abbreviation Char

If you want to see time in a time zone, you can use the Zdump command to directly specify a timezone file for viewing

[Email protected] zoneinfo]# zdump america/new_york america/new_york Thu June one 04:22:14 EDT

So how to set the time zone of this machine? There are two ways to do this:

1) Modify/etc/localtime This file, you can copy the /usr/share/zoneinfo directory under a time zone file/etc directory, rename the bit localtime:

[Email protected] zoneinfo]# cp-a america/new_york/etc/localtime[[email protected] zoneinfo]# datethu June one 04:28:17 E DT 2015

You can also soft-link the/etc/localtime file directly to a time zone file in the/usr/share/zoneinfo directory:

[Email protected] zoneinfo]# Ln-sf/usr/share/zoneinfo/asia/shanghai/etc/localtime[[email protected] zoneinfo]# Datethu June 16:32:28 CST 2015

2) Modify the TZ environment variable can also achieve time zone replacement, through the Tzselect command to select the time zone (follow the prompts to enter ...), after the selection is completed will output similar information:

You can make this change permanent for yourself by appending the linetz= ' Asia/shanghai '; Export Tzto the file '. Profile ' in your home directory; Then logs out and logs in again.

Enter tz= ' Asia/shanghai ' directly on the command line; Export TZ can be. When the date view time, the system is to find the TZ environment variable, TZ is not set to take the search for/etc/localtime file, so the TZ environment variable settings will overwrite the /etc/localtime file information, but the environment variable settings at the next logon is not valid, To be permanently valid, you can write commands to the/etc/profile file.


Time Server Setup

NTP, Network Time Protocol, is a protocol that is used to synchronize the time of each computer in a network. Its purpose is to synchronize the computer's clock to the World coordinated UTC, its fine NTP relay Server, which provides synchronization services to other computers on the local computer. Let's start with how to build.

[[email protected] ~]# Yum install NTP

/etc/ntp.conf is the main configuration file of NTP, the parameters under the introduction (some parameters directly copy from the official website, specifically how to use I do not know):

Server #指定向哪台ntp Server Synchronization time

Restrict #访问控制 (access control for the specified IP address)

Restrict Parameters:

Parameters Definitions

Ignore Deny all packets and Queries #估计是所有从123号端口进来的数据包都丢弃

Kod Send kiss-of-death packet on Access violation

#若违反了连接规则, the kiss-of-death packet is sent directly

nomodify Deny NTPQ/NTPDC queries that attempt to modify the server

                                                           #客户端不能更改服务端的时间参数

Notrap Deny Control Message Trap Service # ...

Noquery Deny all NTPQ/NTPDC queries #拒绝所有ntpq和ntpdc的查询

Noserve Deny all queries-except NTPQ/NTPDC

#拒绝除NTPQ and NTPDC all queries, the client will not be able to synchronize after this addition

Notrust Deny Access unless cryptographically authenticated (ver 4.2 onwards)

# The client source will be treated as untrusted subnet unless authenticated  

Nopeer Deny All packets this attempt to establish a peer association

#

#restrict default Kod nomodify notrap nopeer noquery

#restrict-6 default kod nomodify notrap nopeer noquery

#restrict 127.0.0.1

#默认的是上面这几项, allow all local operations, make these settings for all Ipv4,ipv6 "kod nomodify

#notrap nopeer noquery "

#

#restrict 192.168.0.0 Mask 255.255.255.0 notrap nomodify

#也可以通过上面的设置放宽对指定网段的限制

#

#restrict default Kod nomodify notrap nopeer noquery noserve

#restrict-6 default kod nomodify notrap nopeer noquery noserve

#restrict 127.0.0.1

#restrict cn.pool.ntp.org kod nomodify notrap nopeer noquery

#restrict 0.cn.pool.ntp.org kod nomodify notrap nopeer noquery

#restrict 192.168.0.0 Mask 255.255.255.0 notrap nomodify

#server cn.pool.ntp.org prefer #指定网络上的NTP server

#server 0.cn.pool.ntp.org #指定网络上的NTP Server

#还可以通过上面的设置只对192.168.0.0/24 This network segment open synchronization service, this need in the top two lines plus noserve,

#不过这 Sample will prevent The NTP server comes in and synchronizes this time server service with the specified NTP server .

#还需要加上红色的两行.




Time server (Linux NTP)

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.