While attempting to configure one of our AWS Linux servers I needed to do a few things that I have not had to do in the past and didn’t know how to do. I thought I would share some of those learnings.
Setting the timezone on AWS Linux EC2
I was setting up a server that users would be using to schedule some tasks so it needed to be in our local time zone to make it easier to schedule. AWS documentation is pretty detailed and I found this page, Setting the Time for Your Linux Instance.
Essentially you need to:
- Determine what time zone you want. The hierarchy of time zone files can be found in the /usr/share/zoneinfo.
I needed the “NZ”.
- Update the /etc/sysconfig/clock file. Because I was configuring this during start-up I used the following command in the User Data field of the instance (if you are doing it manually you’ll need to do with sudo as the clock file is owned by root).
sed -i.bak ‘s/ZONE=”UTC”/ZONE=”NZ”/’ /etc/sysconfig/clock
- Create a symbolic link between /etc/localtime and your selected time zone file. The command I used is below (again you may need to use sudo).
ln -sf /usr/share/zoneinfo/NZ /etc/localtime
- Reboot instance to ensure all services reference new time zone.
Time zone set. That’s it.
Barry, Preventer of Chaos