LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Need to write a Shell Script for Zabbix Application Level Clustering (https://www.linuxquestions.org/questions/linux-newbie-8/need-to-write-a-shell-script-for-zabbix-application-level-clustering-826533/)

vinaytp 08-16-2010 09:00 AM

Need to write a Shell Script for Zabbix Application Level Clustering
 
Dear All,

We have zabbix Network monitoring tool installed on two servers 172.17.11.6 ( Master ) and 172.17.11.3 ( Slave ) RHEL 5.4 Servers with 172.17.11.4 being Virtual Ipaddress.

We are trying to implement High Availability with Red Hat Cluster Suite.

OS level Clustering has been implemented with following cluster configuraiton.

Code:

<?xml version="1.0"?>
<cluster alias="CDCTGIMCLSSVR" config_version="9" name="new_cluster">
        <fence_daemon post_fail_delay="0" post_join_delay="3"/>

        <clusternodes>
                <clusternode name="172.17.11.6" nodeid="1" votes="1">
                        <fence>
                                <method name="1"/>
                        </fence>
                </clusternode>
                <clusternode name="172.17.11.3" nodeid="2" votes="1">
                        <fence>
                                <method name="1"/>
                        </fence>
                </clusternode>
        </clusternodes>

        <cman expected_votes="1" two_node="1"/>

        <fencedevices>
                <fencedevice agent="fence_xvm" name="vm_fencing"/>
        </fencedevices>
       
        <rm>
                <failoverdomains/>
                <resources>
                        <fs device="/dev/sdb1" force_fsck="0" force_unmount="0" fsid="1582" fstype="ext3" mountpoint="/data"
name="database" options="" self_fence="0"/>
                </resources>

                <service autostart="1" name="IP_Service">
                        <ip address="172.17.11.4" monitor_link="1"/>
                        <fs ref="database"/>
                </service>

        </rm>

</cluster>

This is working well when Master Server's OS goes down.

But we need to implement Application level clustering for Zabbix_server process which inturn depends on httpd and mysqld deamons to be running.
So I have to check the health of mysqld and httpd with a shell script along with the health of zabbix_server process.

Any good tutorials for this ? Any guidlines that I have to follow ?

Here I may need to take care of following things when any one of the process goes down

1. Shifhting Virtual IP
2. Shifting /dev/sdb1 ( Shared drive to slave )
3. stopping other services on master
4. starting all the services on slave

Please help..

Thanks in advance

konsolebox 08-17-2010 01:52 AM

For quick hints, you can check if the process of mysqld, httpd and zabbix_server is still running by using pidof. Example
Code:

pidof mysqld >/dev/null 2>&1 || echo 'mysqld is no longer running.'
If you can tell their PID, you can use these two methods:
Code:

[[ -d /proc/$PID ]] || echo '... is no longer running.'
Code:

kill -s 0 "$PID" || echo '... is no longer running.'
Or perhaps killall? Not sure which is the most suitable:
Code:

killall -s 0 mysqld || echo 'mysqld is no longer running.'

konsolebox 08-17-2010 02:03 AM

Example implementation script:
Code:

#!/bin/bash

function shutdownall {
        # place commands here the will close the servers
}

function checkprocessbyname {
        pidof "$1" >/dev/null 2>&1
}

function checkprocessbypid {
        kill -s 0 "$1" >/dev/null 2>&1
}

for (( ;; )); do
        if ! checkprocessbyname mysqld; then
                echo 'mysqld is no longer running.'
                shutdownall
        elif ! checkprocessbyname httpd; then
                echo 'httpd is no longer running.'
                shutdownall
        elif ! checkprocessbyname zabbix_server ; then
                echo 'zabbix_server is no longer running.'
                shutdownall
        fi
done

For the tutorials btw, I suggest Advanced Bash-Scripting Guide. You'll also find the bash manual and the help command very handy in most cases.

vinaytp 08-17-2010 06:21 AM

Thanks konsolebox !!

I am Writing the script, thanks again for your inputs.

konsolebox 08-17-2010 06:37 AM

No prob.


All times are GMT -5. The time now is 08:31 AM.