openvzopenvz

How To Change Timezone in OpenVZ VE Environment

Steps to set the time zone for a particular node in VPS. Login into your NODE/OpenVZ Master Server via SSH and Stop the VE with this command below:


1. Login to the main host node.(SSH).

2. Stop the node(container) which you want to set time.

vzctl stop VZID

3. Set the container to have capability to change the time zone.

vzctl set VZID -–capability sys_time:on –-save

For example

~]# vzctl set 11 –capability sys_time:on –save
CT configuration saved to /etc/vz/conf/11.conf
[@~]#

4. Start the container.

vzctl start VZID
  1. Login in to the container and Change your local timezone.
    To find correct time zone location, do this command to search exiting timezones

# find /usr/share/zoneinfo/ | more
# mv /etc/localtime /etc/localtime_bk
# ln -s /usr/share/zoneinfo/Asia/Jakarta /etc/localtime

6. Set the date

In Cpanel server it will not work sometime. In that case follow below steps.

rpm -qi tzdata

It will show output like below

ame : tzdata
Version : 2019c
Release : 1.el7
Architecture: noarch
Install Date: Thu Sep 26 19:00:20 2019
Group : System Environment/Base
Size : 2018657
License : Public Domain
Signature : RSA/SHA256, Thu Sep 26 07:20:57 2019, Key ID 24c6a8a7f4a80eb5
Source RPM : tzdata-2019c-1.el7.src.rpm
Build Date : Thu Sep 26 06:34:13 2019
Build Host : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager : CentOS BuildSystem
Vendor : CentOS
URL : https://www.iana.org/time-zones
Summary : Timezone data
Description :

Run below command.

date && date -u && rdate -p rdate.cpanel.net && ntpdate -qv clock.isc.org

If you are getting below error.

Fri Apr 10 21:09:50 CDT 2020
Sat Apr 11 02:09:50 UTC 2020
rdate: [rdate.cpanel.net] Fri Apr 10 20:48:23 2020

-bash: ntpdate: command not found

In that case you have to install ntpdate command on server

yum install ntpdate
Loaded plugins: fastestmirror, tsflags, universal-hooks
Loading mirror speeds from cached hostfile
* EA4: 185.53.12.144
* cpanel-addons-production-feed: 185.53.12.144
* cpanel-plugins: 185.53.12.144
* base: centos.mirror.ate.info
* extras: centos.mirrors.proxad.net
* updates: centos.mirror.ate.info
EA4 | 2.9 kB 00:00:00
cpanel-addons-production-feed | 2.9 kB 00:00:00
cpanel-plugins | 2.9 kB 00:00:00
MariaDB101 | 2.9 kB 00:00:00
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
vz-base | 951 B 00:00:00
vz-updates | 951 B 00:00:00
Resolving Dependencies
–> Running transaction check
—> Package ntpdate.x86_64 0:4.2.6p5-29.el7.centos will be installed
–> Finished Dependency Resolution

Dependencies Resolved

=========================================================================================================================================================================================
Package Arch Version Repository Size
=========================================================================================================================================================================================
Installing:
ntpdate x86_64 4.2.6p5-29.el7.centos base 86 k

Transaction Summary
=========================================================================================================================================================================================
Install 1 Package

Total download size: 86 k
Installed size: 121 k
Is this ok [y/d/N]: y
Downloading packages:
ntpdate-4.2.6p5-29.el7.centos.x86_64.rpm | 86 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : ntpdate-4.2.6p5-29.el7.centos.x86_64 1/1
Verifying : ntpdate-4.2.6p5-29.el7.centos.x86_64 1/1

Installed:
ntpdate.x86_64 0:4.2.6p5-29.el7.centos

Complete!

Once done execute same command again

date && date -u && rdate -p rdate.cpanel.net && ntpdate -qv clock.isc.org
Fri Apr 10 21:10:47 CDT 2020
Sat Apr 11 02:10:47 UTC 2020
rdate: [rdate.cpanel.net] Fri Apr 10 20:49:20 2020

10 Apr 21:10:47 ntpdate[2724]: ntpdate [email protected] Thu Aug 8 11:48:00 UTC 2019 (1)
server 64.62.194.189, stratum 3, offset -1286.770695, delay 0.17567
server 204.93.207.11, stratum 3, offset -1286.764660, delay 0.12953
server 64.62.194.188, stratum 3, offset -1286.778583, delay 0.17670
server 2001:470:1:b07::123:2001, stratum 0, offset 0.000000, delay 0.00000
server 2001:1838:2000:41b::123:2000, stratum 0, offset 0.000000, delay 0.00000
server 2001:470:1:b07::123:2000, stratum 0, offset 0.000000, delay 0.00000
10 Apr 21:10:56 ntpdate[2724]: step time server 204.93.207.11 offset -1286.764660 sec

rdate -s rdate.cpanel.net
ntpdate -v clock.isc.org

10 Apr 20:49:56 ntpdate[2768]: ntpdate [email protected] Thu Aug 8 11:48:00 UTC 2019 (1)
10 Apr 20:50:05 ntpdate[2768]: adjust time server 204.93.207.11 offset 0.404790 sec