time synchronization under linux

 

Method 1:

Synchronize with a known time server

 

ntpdate time.nist.gov

 

 

where time.nist.gov is a time server.

Delete local time and set time zone to Shanghai

 

rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

 

 

Method 2:
linux automatically synchronizes time
vi /etc/crontab
with a sentence:

 

00 0 1 * * root rdate -s time.nist.gov

 

 

Configure Time Server Configuration (192.168.10.1)

 

1)、# rpm -ivh ntp-4.1.2-4.EL3.1.i386.rpm
2 、 、 # vi /etc/ntp.conf

 

 

Comment a line:
restrict default ignore
Add a line:

 

restrict 192.168.10.0 mask 255.255.255.0 notrust nomodify notrap

 

 

3), # vi /etc/ntp/step-tickers
add a line:
pool.ntp.org
so that every time ntpd starts, it will automatically connect to the international standard time server;

 

4)、# service ntpd start

 

5), # netstat -an |grep 123
to ensure that the port is open in udp mode

Time client configuration (192.168.10.2)
1), #ntpdate 192.168.10.2
should show sync successful
2), #crond -e
join

0-59/10 * * * * /usr/sbin/ntpdate 192.168.10.1

 

Synchronize time every 10 minutes

 

 

 

 

 

 

Adjust linux system time and time zone to synchronize with Internet time
1. Modify the time zone:
# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
is modified to the East Eighth District of China
# vi /etc/sysconfig/clock
ZONE="Asia/Shanghai"
UTC=false
ARC=false
2. Configure new time and
date settings:
# date -s 2008/05/06
Time setting:
# date -s 18:40:00
Check the hardware time (BIOS):
    hwclock [-rw]
    -r: check the existing BIOS time, the default is -r parameter
    -w: write the current linux system time into the BIOS
    When we finish the Linux time calibration, we also need to update the BIOS time with hwclock -w, because every time the system is powered on, the system will read the time from the BIOS again, so the BIOS is an important time basis.
# hwclock
Tue 06 May 2008 03:49:37 PM CST -0.039646 seconds
Synchronize the BIOS clock and force the system time to be written to the CMOS:
# clock -w
3. Realize Internet time synchronization (the above two steps can be ignored here)
Method 1. Automatic network time calibration when booting:
    vi /etc/rc.d/rc.local
    /usr/sbin/ntpdate -u 192.168.0.2 192.168.0.3 192.168.0.4; /sbin/hwclock -w

Method 2. Set the crontab format for scheduled tasks as follows:
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  *  command to be executed
There are also two ways to set crontab scheduled tasks:
1. Write in /etc/crontab
Code :
00 11 * * * root ntpdate 210.72.145.44 Synchronize time with China National
Time Service Center at 11:00 every
day with China National Time Service Center at 11:00 every day, of
course, the premise is
apt-get install ntpdate
The code can also be
00 11 * * * root ntpdate us.pool.ntp.org
2. Use the command crontab -e
crontab -e
    10 5 * * * root ntpdate us.pool.ntp.org;hwclock -w
every day at 5:10 Automatically perform network time calibration and update the BIOS time at the same time

 

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326927050&siteId=291194637