Linux automatic synchronization server time and linux synchronization server
Introduction
When a Linux server runs for a long time, there will be some errors in the system time. This article will introduce how to synchronize the server time with the network server time.
Environment: centos
Network Time Server
First, make sure these servers can be pinged. Otherwise, time synchronization will fail. Otherwise, the error "no server suitable for synchronization found" will be reported"
- China National Time Service Center: 210.72.145.44 ---- unavailable for the time being
- NTP server (Shanghai): ntp. api. bz
- China ntp server: cn.pool.ntp.org
- Pool.ntp.org
Time Synchronization Tool
Rdate: rdate-s
Ntpdate: ntpdate-u (using the-u parameter will return an error, you can also use-s)
Both of the above tools can be used to synchronize network time servers. centos is installed by default. Both tools are easy to use. This chapter mainly introduces the ntpdate tool. The installation method is as follows:
yum -y install ntp
Synchronization time
1. Modify the time zone
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
Vim/etc/sysconfig/clock
ZONE="Asia/Shanghai"UTC=falseARC=false
2. Synchronization time
/usr/sbin/ntpdate -u cn.pool.ntp.org
3. Hardware write time
Each time the server is restarted, it will refer to the hardware time. Therefore, you need to write the current system time to the hardware.
View the current hardware time:
hwclock -r
[root@localhost ~]# hwclock -rThu 12 May 2016 08:05:43 PM CST -0.674165 seconds
Hardware write time:
hwclock -w
Automatic Time Synchronization
1. Configure Boot Check
Vim/etc/rc. d/rc. local
/usr/sbin/ntpdate -u cn.pool.ntp.org> /dev/null 2>&1; /sbin/hwclock -w
2. configure a scheduled task
Vim/etc/crontab
00 10 * * * root /usr/sbin/ntpdate -u cn.pool.ntp.org > /dev/null 2>&1; /sbin/hwclock -w
Or
Crontab-e
00 10 * * * /usr/sbin/ntpdate -u cn.pool.ntp.org > /dev/null 2>&1; /sbin/hwclock -w
Summary
For more information about scheduled tasks, see my previous article: http://www.cnblogs.com/chenmh/p/5430258.html.
Note: Author: pursuer. chen Blog: http://www.cnblogs.com/chenmh All essays on this site are original. You are welcome to repost them. However, you must indicate the source of the article and clearly give the link at the beginning of the article. Welcome to discussion |