I want to share my experience of solving time problem inside OpenVZ container.
This article is not related to KVM containers, they should have no problems with time.
OpenVZ container is running on same Linux kernel as host machine, and OpenVZ container is very well isolated from host system and cannot change many important system-wide parameters.
Problem #1: Bad container timezone
Time is wrong, difference can be measured in hours.
'date' command - result: Wed Mar 8 10:15:05 GMT 2017
'date' command - expected result: Wed Mar 8 15:15:05 GMT+5 2017
Solution: 'dpkg-reconfigure tzdata'.
System clock keep running in UTC time, your container timezone is changed, you see correct time in your console but always can check original UTC clock (with command 'date -u' or any other way).
Problem #2: Bad system time
Time is wrong, difference can be measured in minutes.
'date' command - result: Wed Mar 8 10:15:05 GMT 2017
'date' command - expected result: Wed Mar 8 10:37:05 GMT 2017
'ntpdate time.nist.gov' - result: Operation not permitted
'date -s 10:37' - result: Operation not permitted
Solution 1: Ask your provider to allow you to change system time.
Google quickly finds a command like "vzctl set 101 --capability sys_time:on --save". But this is bad solution because your container will be able to set whole system time (for other containers, too). Your provider should not give you this option.
Solution 2: Ask your provider to fix time on host system. The best variant but depends on provider support quality. Solution can take some time.
Solution 3: Do it yourself. Use libfaketime
Most google links say that it's impossible to change time inside OpenVZ container. But you can change time for your important applications, even for shell. You can use special library for any application and it will tune time to any value. Link is here: https://github.com/wolfcw/libfaketime, there is complete instruction about installation and usage.
Proof:
↧
How to set time in OpenVZ container
↧