We’re running multiple servers and a database on our cloud server. The JVM appears to be off by 2 hours, as it’s operating in UTC time when it should be operating in CEST.
When I ssh into the server and run date
I get the following:
Fri Sep 16 09:21:16 CEST 2016
Our Database is set to System time and it has the same (correct) time as above.
Which is exactly what I’d expect.
When I look at the log files for my java servers, which are using Log4j2 as their logger, the Timestamps
on the log messages are fine (the timezone is configured in log4j2.xml
file), but an date printed from the server itself is off. If I remove the timezone from the log4j2 config file then it defaults to UTC too.
After looking at the above for a while, I ran the ‘locale’ command, and got the following:
LANG=en_US.UTF-8 LC_CTYPE="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_PAPER="en_US.UTF-8" LC_NAME="en_US.UTF-8" LC_ADDRESS="en_US.UTF-8" LC_TELEPHONE="en_US.UTF-8" LC_MEASUREMENT="en_US.UTF-8" LC_IDENTIFICATION="en_US.UTF-8" LC_ALL=
This is clearly wrong.
Before changing this on the live server, I modified the locale.conf
file on our test server and rebooted it to see if the changes would make a difference. They didn’t. The java servers running on the test server still had the same time as they did before I made the changes.
What am I missing here? These servers run as services on the server, and have their own users and groups (I don’t know if that’s relevant).
Any help would be greatly appreciated.
Advertisement
Answer
The timezone
on the server isn’t controlled by the locale settings, the jvm
takes its time from the system clock, which is a separate thing.
This command resolved the issue for me:
sudo timedatectl set-timezone Europe/Stockholm
Also, see this detailed answer I received on serverfault.