Tuesday, February 12, 2008

Manually Editing The Main VCS Configuration File The Right Way

Hey again,

If you're like me and work on all sorts of things in the course of your sysadmin duties, working with Veritas Cluster Server has its pros and cons. On the one hand, it's great once it's all set up and working correctly, and troubleshooting it is fairly easy if you're working off of a solid foundation. On the other hand, making simple additions to the configuration file can be a lengthy and confusing ordeal.

Here's a little trick I picked up along the way, in my experience working with VCS. It's not exactly kosher (if you like to follow rules to the letter), but it works and it's 99% legitimate :)

Let's say, for instance, you wanted to add an NFS mount resource to your VCS cluster configuration. For ease of example, we'll assume you either know the syntax of the main configuration file (main.cf) or can find another cluster setup somewhere else on your network that you can "borrow" from (always more convenient ;) and modify.

Note that this entire process will keep VCS happy and won't cause any sort of split-brain condition that might result from your just manually editing the configuration file and rebooting your server (If things are working correctly, VCS will probably just overwrite your changes if you do this, anyway)

The first thing you'll want to do is to open the main.cf file for editing in memory. You can do this with the haconf command, like so:

host # haconf -makerw

Now, copy off ( just in case ) and open the main.cf file (Generally located in the /etc/VRTSvcs/conf/config directory) in your favorite editor and paste that other configuration addition to the bottom of your config file. We'll assume it's something simple, like this (Note that I haven't included the entire entry for brevity's sake and that you'll also not want to include the "dependency tree" lines. The ones that start with "//" - These will be created for you during this process):

group nfs_sg (
SystemList = { host1 = 0, host2 = 1 }
AutoStartList = { host1, host2 }

DiskGroup nfsdg (
DiskGroup = nfsdg

Now, you'll want to modify the parts that need modifying to suit your particular setup and move your augmented main.cf to another directory:

host # cp /etc/VRTSvcs/conf/config/main.cf /temporary/directory/main.cf

and verify that it's okay (Technically, you could still do this while it's in the regular directory) by running hacf:

host # hacf -verify /temporary/directory <--- This command will assume that there is a main.cf file in the directory you specify

Then, and this is the part that takes the most work out of your job, use hacf to create a commands file (These are commands you would normally have to type at the command line. There are so many of them involved in almost any addition, that I always update this way, just so there's no way I can forget one!):

host # hacf -cftocmd /temporary/directory

This will create a file called main.cmd in the /temporary/directory. This is chock full of commands that you would normally have to execute in order to augment your VCS configuration.

After backing up the main.cmd file in /etc/VRTSvcs/conf/config to, say, main.cmd.bak (Note: Never use the suffix .previous as this is the VCS default and your backup may get overwritten if you run subsequent haconf commands!), move your new main.cmd command into the VCS configuration directory, like so:

host # cp /temporary/directory/main.cmd /etc/VRTSvcs/conf/config/main.cmd

Now, instead of using the "hacf -cmdtocf" command (which should copy the main.cmd file to your configuration, but doesn't always work correctly), do this instead: Simply execute the main.cmd file you just created:

host # sh /etc/VRTSvcs/conf/config/main.cmd

Note: You're going to get a million errors flying across the screen. These are all warning you that you are attempting to add or modify a resource that already exists or has the property you're attempting to change it to. Don't worry about these at all. The errors result in the commands not being executed. Running the entire main.cmd file, and just ignoring those errors, ensures that every "new" command you need to enter will be entered :)

Now that you're all done "running all those commands" you can close the main.cf file in memory the proper way with haconf again, like this:

host # haconf -dump -makero

Now your new resource will have been added to the main configuration file, VCS will be happy and propagate the change to all the nodes in your cluster and you should be able to begin monitoring your new resource and, possibly, troubleshooting any errors that occur if you got any little part of your new entry wrong. Fun ;)

Best wishes,

, Mike