How configure synchronization of time between devices?

Antrax - Initial configuration of the system

How configure synchronization of time between devices?

In order to synchronize the time successfully, it is necessary that all devices work in the same time zone, in order to check the time zone, you must run the following command:
  date
This command displays the current time and time zone:
Чтв Фев  8 14:44:57 EET 2018
If the devices have different time zones, then you need to install the same one, for this you can use the following commands:
For Debian8:
dpkg-reconfigure tzdata
For CentOS6.X:
rm -f /etc/localtime
ln -s /usr/share/zoneinfo/Region/City /etc/localtime

Where:

 Region - this is the region in which this time zone is located, examples:
Africa/      Atlantic/    Chile/       Eire         Factory      GMT-0        Iceland      Jamaica      MET          NZ           posix/       ROC          UCT          W-SU
America/     Australia/   CST6CDT      EST          GB           GMT+0        Indian/      Japan        Mexico/      NZ-CHAT      posixrules   ROK          Universal    zone.tab
Antarctica/  Brazil/      Cuba         EST5EDT      GB-Eire      Greenwich    Iran         Kwajalein    MST          Pacific/     PRC          Singapore    US/          Zulu
Arctic/      Canada/      EET          Etc/         GMT          Hongkong     iso3166.tab  Libya        MST7MDT      Poland       PST8PDT      SystemV/     UTC         
Asia/        CET          Egypt        Europe/      GMT0         HST          Israel       localtime    Navajo       Portugal     right/       Turkey       WET
 - The city in which the given time zone is located, examples of cities for  - Asia:
Aden           Baghdad        Chita          Dili           Hovd           Karachi        Kuching        Nicosia        Qatar          Shanghai       Thimbu         Vientiane
Almaty         Bahrain        Choibalsan     Dubai          Irkutsk        Kashgar        Kuwait         Novokuznetsk   Qyzylorda      Singapore      Thimphu        Vladivostok
Amman          Baku           Chongqing      Dushanbe       Istanbul       Kathmandu      Macao          Novosibirsk    Rangoon        Srednekolymsk  Tokyo          Yakutsk
Anadyr         Bangkok        Chungking      Gaza           Jakarta        Katmandu       Macau          Omsk           Riyadh         Taipei         Ujung_Pandang  Yekaterinburg
Aqtau          Beirut         Colombo        Harbin         Jayapura       Khandyga       Magadan        Oral           Saigon         Tashkent       Ulaanbaatar    Yerevan
Aqtobe         Bishkek        Dacca          Hebron         Jerusalem      Kolkata        Makassar       Phnom_Penh     Sakhalin       Tbilisi        Ulan_Bator    
Ashgabat       Brunei         Damascus       Ho_Chi_Minh    Kabul          Krasnoyarsk    Manila         Pontianak      Samarkand      Tehran         Urumqi        
Ashkhabad      Calcutta       Dhaka          Hong_Kong      Kamchatka      Kuala_Lumpur   Muscat         Pyongyang      Seoul          Tel_Aviv       Ust-Nera      
Example of setting the time zone - Asia and - Almaty, this is the time zone which refers to GMT +6
sudo cp /etc/localtime /etc/localtime.bak
sudo ln -s -f /usr/share/zoneinfo/Asia/Almaty /etc/localtime
After configuring one time zone for all devices, you can start configuring the services that are responsible for synchronizing the time between devices, such as ntpd and chrony.

Configuring ntdp and chrony

On the main server with OS (Operating System) CentOS6.X (the so-called CS-server), you must have access to the Internet. Using the below-described configuration will allow VS and SS servers to synchronize with CS even if they do not have access to the Internet. Synchronization is performed on the port: "123".

Ntpd confed only for Centos 6

Install ntp and ntpdate:
yum install -y ntp ntpdate
Add ntpd to startup and remove chronyd from startup:
chkconfig ntpd on
chkconfig chronyd off

Stoped сhrony и ntp

/etc/init.d/chronyd stop
/etc/init.d/ntpd stop

Configuring ntpd:

mcedit /etc/ntp.conf
Give the list of servers for synchronization to the form:
server time1.google.com iburst
server time2.google.com iburst
server time3.google.com iburst
server time4.google.com iburst

Reload new settings:

sudo service ntpd reload

Turn on ntpd

/etc/init.d/ntpd start

Give access UDP port 123 to iptables:

iptables -A INPUT -s 192.168.0.0/16 -m state --state NEW -p udp --dport 123 -j ACCEPT

Save settings:

service iptables save

Chrony configure is only for Debian 8

Install chrony и  ntpdate: 

apt-get install -y chrony ntpdate
Add ntpd to startup and remove chronyd from startup:
systemctl disable ntp
systemctl enable chrony

Stoped сhrony и ntp 

systemctl stop ntp
systemctl stop chrony

Configuring chrony:

mcedit /etc/chrony/chrony.conf
Give the list of servers for synchronization to the form:
server Static_public_IP_address_of_CS iburst
server time1.google.com iburst
server time2.google.com iburst
server time3.google.com iburst
server time4.google.com iburst
initstepslew 5 Static_public_IP_address_of_CS

where Static_public_IP_address_of_CS - static-public IP address of the server where Control Server is installed

We include and add to the auto-run chrony:

systemctl enable chrony
systemctl start chrony

Manual time synchronization

Stoped сhrony and ntp in Centos 6.X or Debian 8:

/etc/init.d/chronyd stop
/etc/init.d/ntpd stop

Try to synchronize the time using the ndpdate utility

ntpdate ntp_server
ntp_server - IP address or domain name of the service by which the time synchronization will be performed, for example:
ntp.time.in.ua
time1.google.com
time.org
If the synchronization is not successful, you can make a one-time synchronization using ntpdate using a non-standard port
ntpdate -u ntp_server

or

date -s "$(wget -qSO- --max-redirect=0 google.com 2>&1 | grep Date: | cut -d' ' -f5-8)Z"


 


Loading...