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
# 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
date settings:
# date -s 2008/05/06
# date -s 18:40:00
hwclock [-rw]
-r: check the existing BIOS time, the default is -r parameter
-w: write the current linux system time into the BIOS
# hwclock
Tue 06 May 2008 03:49:37 PM CST -0.039646 seconds
# clock -w
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
# .---------------- 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
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
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