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.
1 |
db2setup -u db2-install.rsp |
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.
1 2 |
db2inst1:50000 db2inst2:50001 |
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.
1 2 3 4 5 6 7 8 9 |
# Full path of the DB2 media file (gzip file) DB2MEDIA=/media/sf_Downloads/v11.1_linuxx64_server_t.tar.gz # Path where the gzip file will be uncompressed and the path of the db2setup program DB2MEDIAFILES=/opt/IBM DB2SETUP=/opt/IBM/server_t/db2setup # Path where the DB2 software will be installed INSTALLPATH=/opt/ibm/db2/V11.1 |
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.
1 2 3 |
## Do the DB2 installation using the response file echo "Installing DB2" $DB2SETUP -u ~/db2-install.rsp |
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.
1 2 3 4 5 6 |
# Example: Set MySQL compatability su -l $INSTANCE -c 'db2set DB2_COMPATIBILITY_VECTOR=MYS' # Example: Turn on monitoring switches su -l $INSTANCE -c 'db2 -v update dbm cfg using DFT_MON_BUFPOOL ON DFT_MON_LOCK ON DFT_MON_SORT ON DFT_MON_STMT ON DFT_MON_TABLE ON DFT_MON_UOW ON HEALTH_MON OFF' |
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.