1. set the system time date-s // set the current time. only the root permission can be set. others can only be viewed. Date-s20080523 // Set to 20080523, this will set the specific time to null 00: 00: 00date-s01: 01: 01 // set the specific time, do not change the date-s "-01 2008-05-23" // you can set the full time date-s "012008
1. set the system time
Date-s // set the current time. only the root permission can be set. others can only be viewed.
Date-s 20080523 // Set to 20080523, so that the specific time is set to null 00:00:00
Date-s 01:01:01 // set the specific time and do not change the date
Date-s "01:01:01" // you can set all the time
Date-s "01:01:01 20080523" // you can set all the time
Date-s "01:01:01" // you can set all the time
Date-s "20080523 01:01:01" // you can set all the time
2. View hardware Time
# hwclock
Set hardware Time
# Hwclock -- set -- date = "07/07/06" (month/day/year hour: minute: Second)
3. hardware Time and system Time SynchronizationWhen you restart the system, the hardware Time reads the system time for synchronization. However, you must use the hwclock command to synchronize data without restarting the system. Hardware clock and system clock synchronization:
# Hwclock -- hctosys (hc indicates the hardware Time, sys indicates the system time)
System clock and hardware clock synchronization: (synchronize the system time to the hardware clock)
# hwclock ?-systohc
4. use ntpdate to synchronize timeIf you do not have this command, install the following package:
rpm -ivh ntp-4.2.2p1-9.el5.centos.2.1.i386.rpm
National Time Service Center Address: 210.72.145.44 use ntpdate 210.72.145.44 to synchronize time. after the synchronization is complete, clock-w writes to CMOS. if iptables is used as the firewall, add the following statement to update
iptables -A INPUT -p tcp --sport 123 -s 210.72.145.44 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 123 -d 210.72.145.44 -j ACCEPT
iptables -A OUTPUT -p udp --dport 123 -d 210.72.145.44 -j ACCEPT
iptables -A INPUT -p udp --sport 123 -s 210.72.145.44 -j ACCEPT
5. use scripts to regularly synchronize timeUse crontab to execute the following script. the synchronization time is 30 23*5/root/ntpdate. sh at every week.
#!/bin/bash
export PATH=/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/java/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/loc
al/mysql5/bin:/root/bin
LOG="/tmp/ntpdate.log"
for((i=0; i<5; i++))
do
ntpdate 210.72.145.44 &>/dev/null
if [ $? == 0 ];then
clock -w
echo"$(date +%Y-%m-%d_%T) ==>update time successful!" >>$LOG
echo"" >>$LOG
exit 0
else
echo"$(date +%Y-%m-%d_%T) ==>update time occur error!" >>$LOG
echo"" >>$LOG
fi
done