Modify system time and CMOS time in Centos

Source: Internet
Author: User

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. 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:
    
    
  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. If you do not have the command to use ntpdate to synchronize time, 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. 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.
      
      
  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.