OCI BM DB – Automatic Scaling

Demo Video:

Here is how you can setup the Automatic Scaling script in your baremetal instance.

Setup the right time zone
To make sure you schedule runs in the right timezone, make sure you have setup the right timezone region in your baremetal instance. You can set your time zone with the following commands:

sudo rm /etc/localtime
sudo ln -s /usr/share/zoneinfo/Europe/Amsterdam /etc/localtime

Setting up python27
The Oracle Database Baremetal instance has a fairly old version of python and is missing some extra tools and libraries. So we need to fix this.

cd /etc/yum.repos.d
sudo wget http://yum.oracle.com/public-yum-ol6.repo

Edit the repo and enable the [ol6_software_collections] repository by changing enabled=0 to enabled=1 under the ol6_software_collections

sudo yum install python27 python-setuptools
sudo scl enable python27 bash

Now we can install the Oracle OCI python libraries:

pip install oci
exit (go back to opc user)

Now we need to install the script using git, but first have to install git itself

sudo yum install git
git clone https://github.com/AnykeyNL/OCI-AutoScale.git

Finally we need a config file with the right user ID for making the api calls. Create a file in your home folder called [config]:

[DEFAULT]
user=[your user ID]
fingerprint=[Your finger print]
key_file=[your ssh key file .pem]
tenancy=[your tenancy id]
region=eu-frankfurt-1

It does not matter what you fill in as region, as this will automatically be read out using the instance metadata. You can get/set the information in the OCI portal under identity->Users:

Create a file in your home directory (/home/opc) called: Scale.sh and give it the following content:

export PATH=/opt/rh/python27/root/usr/bin
export LD_LIBRARY_PATH=/opt/rh/python27/root/usr/lib64
/opt/rh/python27/root/usr/bin/python /home/opc/OCI-AutoScale/AutoScale.py $1 >> /home/opc/debug.txt 2>&1

Make the file executable:

chmod 755 Scale.sh

Schedule the script

We can now use crontab to automatically schedule to run this script. Run the command ‘crontab -e’ and enter the following text:

1 * * * * /home/opc/Scale.sh up
59 * * * * /home/opc/Scale.sh down

This Schedule will scale down just before the end of the hour and scale up just after the hour.

Making the Schedule

Now all that is left to do, is to make the schedule. First make you you have created the “Schedule” namespace in the Governance -> Tag Namespaces. And create the following Tag Key Definitions (case sensitive):

  • AnyDay
  • WeekDay
  • Weekend
  • Monday
  • Tuesday
  • Wednesday
  • Thursday
  • Friday
  • Saturday
  • Sunday

Now you can go to your Database Baremetal instance and add the schedule you would like to have for it by clicking on theĀ  Apply Tags button:

The schedule has to consist of 24 number, each representing one hour of the day starting with 0:00am 1:00am etc. The number it self is the amount of cpu core you want to give your instance.

That’s it šŸ™‚ You can now easily design the most optimal schedule that will help you run an Oracle Database at the most efficient cost.