Step 3: Configure etcha.dharesources


Step 3: Configure /etc/ha.d/haresources

Normally the /etc/ha.d/haresources file will contain the names of the resources the primary server should own. Heartbeat generally controls its resources with the normal init script that comes with your distribution, or with a script you build, such as the iptakeover script shown in Chapter 6, but for now we will use a very simple test script to see how they work. Follow these steps:

  1. Create a script called test1 in the /etc/ha.d/resource.d directory with the following command (this script is also included on the CD-ROM in the chapter7 subdirectory):

     #vi /etc/ha.d/resource.d/test1 

  2. Now press the I key to enter insert mode, and then enter the following simple bash script:

     #!/bin/bash logger $0 called with $1 case "$1" in start)     # Start commands go here      ;; stop) # Stop commands go here     ;; status)     # Status commands go here ;; esac 

    The logger command in this script is used to send a message to the syslog daemon. syslog will then write the message to the proper log file based on the rules in the /etc/syslog.conf file. (See the man pages for logger and syslog for more information about custom message logging.)

    Note 

    The case statement in this script does not do anything. It is included here only as a template for further development of your own custom resource script that can handle the start, stop, and status arguments that Heartbeat will use to control it.

  3. Quit this file and save your changes (press ESC, and then type :wq).

  4. Make this script executable by entering this command:

     #chmod 755 /etc/ha.d/resource.d/test 

  5. Run the script by entering the following command:

     #/etc/ha.d/resource.d/test start 

  6. You should be returned to the shell prompt where you can enter this command to see the end of the messages:

     #tail /var/log/messages 

    The last message line in the /var/log/messages file should look like this:

     [timestamp] localhost root: /etc/ha.d/resource.d/test called with start 

    This line indicates that the test resource script was called with the start argument and is using the case statement inside the script properly.

Configure the Haresources File

You can use this simple test script to see what Heartbeat does with resources by telling it that test is a resource. To do so, locate and copy the sample haresources file into place with these commands:

 #rpm -qd heartbeat | grep haresources #cp /usr/share/doc/packages/heartbeat/haresources /etc/ha.d 

Now edit /etc/ha.d/haresources (which really just contains commented documentation at this point), and add the following line to the end of the file:

 primary.mydomain.com test 

In this example, primary.mydomain.com should be replaced with the name of the primary server as returned by the command uname -n.

The haresources file tells the Heartbeat program which machine owns a resource. The resource name is really a script in either the /etc/init.d directory or the /etc/ha.d/resource.d directory. (A copy of this script must exist on both the primary and the backup server.)

Heartbeat uses the haresources configuration file to determine what to do when it first starts up. For example, if you specify that the httpd script (/etc/init.d/httpd) is a resource, Heartbeat will run this script and pass it the start command when you start the heartbeat daemon on the primary server. If you tell Heartbeat to stop (with the command /etc/init.d/heartbeat stop or service heartbeat stop), Heartbeat will run the /etc/init.d/httpd script and send it the stop command. Therefore, if Heartbeat is not running, the resource daemon (httpd in this case) will not be running.

If you use a previously existing init script (from the /etc/init.d directory) that was included with your distribution, be sure to tell the system not to start this script during the normal boot process with the chkconfig --del <scriptname> command. (See Chapter 1 for a detailed description of the chkconfig command.)

Note 

If you're not using Red Hat or SuSE, you should also make sure the script prints OK, Running, or running when it is passed the status argument. See Chapter 6 for a discussion of using init scripts as Heartbeat resource scripts.

The power and flexibility available for controlling resources using the haresources file will be covered in depth in Chapter 8.

image from book
RESPAWNING DAEMONS WITH HEARTBEAT

You can tell Heartbeat to start a daemon each time it starts, and then to restart this daemon automatically if the daemon stops running. To do so, use a line like this in the /etc/ha.d/ha.cf file:

 respawn userid /usr/bin/mydaemon 

Note, though, that such a daemon (called /usr/bin/mydaemon in this example) will not failover to the backup server. If you use this method to start a daemon, it will always be running when Heartbeat is running, so this technique is probably only useful for a daemon that needs to run on the primary and the backup server[3] in conjunction with Heartbeat (the ipfail daemon described in Chapter 9 is an example of one such daemon).

For high-availability daemons that would normally be started from init with the respawn option, and that need to failover from the primary server to the backup server (such as a serial telecommunications program like Hylafax) you must use the cl_respawn program included with the Heartbeat package, or a separate package, such as Daemontools (discussed in Chapter 8) in conjunction with Heartbeat.

image from book

[3]In a good high-availability configuration, the ha.cf, haresources, and authkeys files will be the same on the primary and the backup server.



The Linux Enterprise Cluster. Build a Highly Available Cluster with Commodity Hardware and Free Software
Linux Enterprise Cluster: Build a Highly Available Cluster with Commodity Hardware and Free Software
ISBN: 1593270364
EAN: 2147483647
Year: 2003
Pages: 219
Authors: Karl Kopper

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net