Showing posts with label TimeDate. Show all posts
Showing posts with label TimeDate. Show all posts

Friday, May 31, 2019

Update time and date using chrony

Chrony is an application for a machine to sync with network time protocol servers.

To install chrony
# yum install chrony -y

Then, make sure to include some legit ntp servers in /etc/chrony.conf. In this case, we are using centos ntp pool servers.
# cat /etc/chrony.conf
...
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst

...

Start chronyd (chrony daemon)
# systemctl start chronyd

Chrony will gradually update the system clock to follow the ntp servers, once chronyd is started. But if you want to chrony to update the time quickly, just use below command
# chronyc makestep

To start chronyd on boot:
# systemctl enable chronyd

To check if the time has been synced (make sure one of the server has ^* on the left hand side)
# chronyc sources -v
...
^* time.cloudflare.com           0   6     0     -     +0ns[   +0ns] +/-    0ns
...

Tuesday, June 14, 2011

Convert time to unix timestamp and vice versa

To convert current time to unix timestamp

$ date +%s
1308021863
where %s is seconds since 1970-01-01 00:00:00 UTC

To convert a unix timestamp to a readable time/date
$ date -d @1308021863
Mon Jun 13 22:24:23 CDT 2011
where -d is for displaying time described by the string after @

Tuesday, October 26, 2010

Xen's domU always depend on dom0's time and date

By default, the time and date in domU is following dom0. To reset that, below are just what you have to do to decouple the domU's date from dom0

On dom0:

Append xen.independent_wallclock=1 to /etc/sysctl.conf

# echo "xen.independent_wallclock=1"  >> /etc/sysctl.conf
Activate the change
# sysctl -p
Append extra="clocksource=jiffies" to the domU's configuration file.
# echo "extra=\"clocksource=jiffies\"" >> /etc/xen/<domU's name>.cfg 


On domU:

Append xen.independent_wallclock=1
# echo "xen.independent_wallclock=1"  >> /etc/sysctl.conf 
Activate the change
# sysctl -p 
Append jiffies to /sys/devices/system/clocksource/clocksource0/current_clocksource
# echo "jiffies" >> /sys/devices/system/clocksource/clocksource0/current_clocksource

Now you can set your domU's date using "date" command or "ntpdate" to get update from ntp servers.

That's all folks

Thursday, August 23, 2007

Setting up your own ntp server

NTP or network time protocol is a protocol that will synchronize the time of a computer client or server to another server or reference time source, such as a radio or satellite receiver or modem. Typical NTP configurations utilize multiple redundant servers and diverse network paths in order to achieve high accuracy and reliability.
Follow the below setup to install your ntp server:

1. install ntp: $ yum install -y ntp

2. edit ntp.conf: $ vi /etc/ntp.conf
example of ntp.conf:
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.rhel.pool.ntp.org
#server 1.rhel.pool.ntp.org
#server 2.rhel.pool.ntp.org
#server mst.sirim.my prefer
#server my.pool.ntp.org

#broadcast 192.168.1.255 key 42 # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 key 42 # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 key 42 # manycast client

# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
#server mst.sirim.my prefer
#server my.pool.ntp.org


# Drift file. Put this in a directory which the daemon can write to.
# No symbolic links allowed, either, since the daemon updates the file
# by creating a temporary in the same directory and then rename()'ing
# it to the file.
driftfile /var/lib/ntp/drift

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8

3. If the server you are setting up do not have internet connection, you can synchronize it with the local time of the server itself. Just comment the server part, and change it to 127.127.1.0. The sratum level is for determining what level this time server is set up for. Stratum 0 usually refers to real clock, for example atomic (cesium, rubidium) clocks or GPS clocks or other radio clocks. Stratum 1 is the machine connected to stratum 0 devices.

#server mst.sirim.my prefer
#server my.pool.ntp.org
server 127.127.1.0
fudge 127.127.1.0 stratum 10

4. synchronize the server's time with the ntp server: $ ntpdate -du mst.sirim.my

5. start ntp service: $ /etc/init.d/ntpd start

In the client machine, just type: $ ntpdate -du ntpservername. You can also put this command in crontab for the client to be update frequently

Friday, July 20, 2007

Setting system clock and date

To set system clock and date using command, date command can be used.
This is how to do it:

-> date mmddttttyyyy.ss where;
mm - month
dd - day
tttt - time in hours and minutes
yyyy - year
ss - seconds

For example, to set the current date to 17 July 2007, 11:15 a.m., this command below can be used:

-> date 071711152007

To see the current date, the date command without argument can be used.

-> date

Thursday, June 14, 2007

rpm building error

When you try to build rpm file from source, if this error comes out:

error: Legacy syntax is unsupported: copyright
error: line 10: Unknown tag: Copyright: distributable

This error can be settled by modifying the spec file. Usually the source will have the spec file.

-> vi filename.spec

Then; change this line "Copyright: GPL" to "License: GPL". Save the changes.

Run back rpmbuild.