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. When the hardware time and system time are synced and restarted, the hardware time reads the system time for synchronization. However, when the system time is not restarted, you need to use the hwclock command for synchronization. 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. If you do not have the command to use ntpdate to synchronize time, 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. Run the following script by running the script on crontab at the scheduled synchronization time. 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