I have CentOS machine and each time I've noticed that the server loses correct time after a while. It is usually behind by several minutes after time passes from having manually set the correct time. Is there a mechanism whereby I can update the server with the time from a specific time server?
10 Answers
Use the ntp
daemon. Run yum install ntp
and ensure that the service is started via ntsysv
or chkconfig ntpd on
.
To get an immediate sync, run ntpdate time.apple.com
(or something similar).
- 194,921
- 91
- 434
- 799
-
@ewhite I did yum and it is show ing is also already install. so what should be my next step? How to config my time to point to the ntp server? – user111196 Mar 12 '12 at 05:22
-
3Try `/sbin/service ntpd stop`, followed by `ntpdate time.apple.com` and then `/sbin/service ntpd start` – ewwhite Mar 12 '12 at 05:36
-
8@ewwhite Another solution is to run `ntpdate -b -u time.nist.gov` which will attempt to use a separate port than the ntpd daemon is using. – Shard Jan 07 '15 at 05:58
-
For me `ntpdate` worked without specifying a timeserver. – SPRBRN Mar 17 '15 at 12:38
-
In 2018 it is systemctl can you update? – YumYumYum Jul 10 '18 at 08:54
-
On CentOS 7.2.1511, the ntpdate is installed at /sbin/ntpdate. So, I had to run sudo /sbin/ntpdate time.apple.com to fix its time. – user674669 Sep 27 '19 at 07:28
You need to install and configure ntp.
yum install ntp
chkconfig ntpd on
ntpdate pool.ntp.org
service ntpd start
should get things set up and running. You may find that the ntp package is already installed and just needs configuring.
- 114,104
- 20
- 206
- 289
-
3If the computer being changed is not a VM, then I `hwclock -w` after the `ntpdate` command. This means the next time the computer reboots, your clock will be less out-of-sync than it is now. – David Mackintosh Mar 12 '12 at 03:45
-
@lain I already check is install but what to config to point to the ntp server and keep it remain syn? – user111196 Mar 12 '12 at 05:23
-
@user111196: JUst perform the chkconfig, ntpdate and service commands above. – user9517 Mar 12 '12 at 07:12
-
@lain what I am interest to learn on which time will it syn to is it my current time zone is it? – user111196 Mar 12 '12 at 15:59
-
Yes, the time will be correct for the time zone that your system is set to. – user9517 Mar 12 '12 at 17:49
Yes.
yum install ntp
chkconfig ntpd on
Do an initial sync, with
ntpdate pool.ntp.org
and start the time daemon with:
/etc/init.d/ntpd start
- 27,440
- 10
- 72
- 148
-
how to do the initial sync any command? You mean just run ntpdate pool.ntp.org but where is the time set? – user111196 Mar 12 '12 at 05:24
-
-
ntpdate set the date according to the server's time zone settings rite – user111196 Mar 14 '12 at 02:00
-
ntpdate sets the hardware clock. Whatever you're doing with /etc/timezone is a bit more userspacey. – Tom O'Connor Mar 14 '12 at 09:48
You'll need to configure ntpd for the server. I suspect it is already installed but needs to be configured. Note: if it is a virtual server, you probably have the option of syncing with the virtual host.
- 6,337
- 21
- 36
For centos 7.x installation:
yum install ntp
systemctl enable ntpd
initial sync, with:
ntpdate pool.ntp.org
start the daemon with:
systemctl start ntpd
- 131
- 4
-
1CentOS 7 systems use chrony by default, so if you want to switch NTP clients you should disable or remove chrony first before installing ntpd. – Michael Hampton Apr 16 '18 at 21:05
-
@MichaelHampton I have CentOS 7 and it didn't had chrony by default. – Unicornist Sep 10 '18 at 07:10
-
@Unicornist You are only guaranteed to get chrony if you install from official CentOS media. If someone else performs the installation for you, or you use custom media, then you might not get it. – Michael Hampton Sep 11 '18 at 23:20
Basically there are two ways. NTP daemon and the ntpdate command. The most important difference is that ntpdate will synchronize the time at once even though it means that the system time will change. On the other hand NTP daemon will take care of the time synchronization and it will adjust the time by small steps - you can think about it like slowing down/speeding up the time of the computer to synchronize it to the correct time. Thats why people suggest to do the initial synchronization by ntpdate and then leave it to ntp daemon.
- 600
- 1
- 3
- 14
Yea I'd use NTP, install ntp with yum and turn it on.
yum install ntp
chkconfig ntpd on
Then sync it to any ntp server of your liking with the ntpdate
command
- 16,818
- 9
- 57
- 92
In the case of Centos 8
, I just start/enble chronyd
like below:
systemctl start chronyd
systemctl enable chronyd
- 101
- 2
Also if using CPanel like I was and had this issue. I think using rdate. Changing to ntpd as per above fixes all issues with email, especially dovecot,etc.
- 1
- 1