Modify system time and CMOS time in Centos

Source: Internet
Author: User
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
 
 
  1. Date-s // set the current time. only the root permission can be set. others can only be viewed.

  2. Date-s 20080523 // Set to 20080523, so that the specific time is set to null 00:00:00

  3. Date-s 01:01:01 // set the specific time and do not change the date

  4. Date-s "01:01:01" // you can set all the time

  5. Date-s "01:01:01 20080523" // you can set all the time

  6. Date-s "01:01:01" // you can set all the time

  7. Date-s "20080523 01:01:01" // you can set all the time

2. View hardware Time
 
 
  1. # hwclock

Set hardware Time
 
 
  1. # 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:
 
 
  1. # 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)
 
 
  1. # hwclock ?-systohc

4. use ntpdate to synchronize timeIf you do not have this command, install the following package:
 
 
  1. 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
 
 
  1. iptables -A INPUT -p tcp --sport 123 -s 210.72.145.44 -j ACCEPT

  2. iptables -A OUTPUT -p tcp --dport 123 -d 210.72.145.44 -j ACCEPT  

  3. iptables -A OUTPUT -p udp --dport 123 -d 210.72.145.44 -j ACCEPT  

  4. 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.
 
 
  1. #!/bin/bash


  2. 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

  3. al/mysql5/bin:/root/bin

  4. LOG="/tmp/ntpdate.log"

  5. for((i=0; i<5; i++))

  6. do

  7.    ntpdate 210.72.145.44 &>/dev/null

  8. if [ $? == 0 ];then

  9.       clock -w

  10. echo"$(date +%Y-%m-%d_%T) ==>update time successful!" >>$LOG

  11. echo"" >>$LOG

  12. exit 0

  13. else

  14. echo"$(date +%Y-%m-%d_%T) ==>update time occur error!" >>$LOG

  15. echo"" >>$LOG

  16.    fi  

  17. done


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.