Automated IBM DB2 Installation

If you need to do multiple installations of DB2 and want to standardize how they are installed, one way to do it is by using response files. The command is simple, you just run db2setup and provide the response file as a parameter. Below is an example.

If you always install the same instance (db2inst1), you can just create a single response file that you use every time. But, what about if you need different configurations for different environments. Some environments will use different ports or multiple instances running in the same server.

To resolve this problem I created a script that can install DB2 and then install multiple instances with a custom configuration. You just provide a text file with the name of the instance and port. You can find the script in my Github repository. Lets go over the the different sections of the script. First you need to create a text file that list the instances and their ports. This can be provided as a parameter, or if not provided, it assumes the filename instance-list.txt. The example file below will create two instances.

In the first part of the script (install-db2.sh) you provide the information like the location of the DB2 media (gzip file), the location to uncompress the media and the target location for the DB2 software.

The script will then create the db21adm1 group and also the db2fenc1 user. It enables the firewall and then creates the first part of the response which includes information about the dasusr1 user with a random password. It will then read the file that has the instance information. Once the information is saved into a newly created response file (~/db2-install.rsp), it will install DB2 and create the instances.

But, after installing DB2, we probably want to configure the instances. In the last part of the script I provided an option for that. There is one example to set the MySQL compatibility by updating the registry and another example to turn on the monitoring switches by updating the DBM configuration.

I hope this script helps your to automate your DB2 installations. I found it very helpful when doing multiple cloud deployments where we need to use the same configuration across dozens of environments.