Solaris OS용 Sun Cluster 데이터 서비스 개발 안내서

오류 모니터 정의

샘플 응용 프로그램은 DNS 자원(in.named)의 안정성을 모니터하기 위해 기본 오류 모니터를 구현합니다. 오류 모니터는 다음 요소로 구성됩니다.

검사 프로그램 작동 방식

dns_probe 프로그램은 샘플 데이터 서비스가 제어하는 DNS 자원이 실행 중인지 확인하는 지속적으로 실행되는 프로세스를 구현합니다. dns_probe는 샘플 데이터 서비스가 온라인 상태가 된 후 RGM에서 자동으로 실행하는 dns_monitor_start 메소드에 의해 시작됩니다. 데이터 서비스는 RGM에서 샘플 데이터 서비스를 오프라인 상태로 전환하기 전에 호출하는 dns_monitor_stop 메소드에 의해 중지됩니다.

이 절에서는 샘플 응용 프로그램에 사용된 PROBE 메소드의 주요 부분에 대해 설명합니다. parse_args() 함수, syslog() 함수와 같이 모든 콜백 메소드에 공통된 기능은 다루지 않습니다. 공통된 기능에 대해서는 모든 메소드에 공통 기능 제공에서 설명합니다.

PROBE 메소드의 전체 목록은 PROBE 프로그램 코드 목록을 참조하십시오.

검사 프로그램의 기능

검사는 무한 루프로 실행되며 nslookup을 사용하여 적절한 DNS 자원이 실행 중인지 확인합니다. DNS가 실행 중인 경우 검사는 Thorough_probe_interval 시스템 정의 등록 정보에 의해 설정된 지정된 간격 동안 일시 정지했다가 다시 검사를 수행합니다. DNS가 실행 중이 아닌 경우 이 프로그램은 DNS를 로컬로 다시 시작하기 위해 시도하거나 재시작 시도 횟수에 따라 데이터 서비스를 다른 노드에 재할당하도록 RGM에 요청합니다.

등록 정보 값 얻기

이 프로그램에는 다음 등록 정보 값이 필요합니다.

scha_resource_get() 함수는 다음과 같이 이러한 등록 정보의 값을 검색하여 쉘 변수에 저장합니다.

PROBE_INTERVAL=`scha_resource_get -O Thorough_probe_interval \
-R $RESOURCE_NAME -G $RESOURCEGROUP_NAME`

PROBE_TIMEOUT_INFO=`scha_resource_get -O Extension -R $RESOURCE_NAME \
-G $RESOURCEGROUP_NAME Probe_timeout` 
Probe_timeout=`echo $probe_timeout_info | awk '{print $2}'`

DNS_HOST=`scha_resource_get -O Network_resources_used -R $RESOURCE_NAME \
-G $RESOURCEGROUP_NAME`

RETRY_COUNT=`scha_resource_get -O Retry_count -R $RESOURCE_NAME -G \
$RESOURCEGROUP_NAME`

RETRY_INTERVAL=`scha_resource_get -O Retry_interval -R $RESOURCE_NAME -G \
$RESOURCEGROUP_NAME`

RT_BASEDIR=`scha_resource_get -O RT_basedir -R $RESOURCE_NAME -G \
 $RESOURCEGROUP_NAME`

주 –

Thorough_probe_interval과 같은 시스템 정의 등록 정보의 경우 scha_resource_get() 함수는 값만 반환합니다. Probe_timeout과 같은 확장 등록 정보의 경우 scha_resource_get() 함수는 유형과 값을 반환합니다. 값만 검색하려면 awk 명령을 사용합니다.


서비스의 안정성 검사

검사 자체는 nslookup 명령의 무한 while 루프입니다. while 루프 앞에서 nslookup 응답을 저장하기 위한 임시 파일이 설정됩니다. probefailretries 변수는 0으로 초기화됩니다.

# Set up a temporary file for the nslookup replies.
DNSPROBEFILE=/tmp/.$RESOURCE_NAME.probe
probefail=0
retries=0

while 루프는 다음 작업을 수행합니다.

다음은 while 루프 코드입니다.

while :
do
   # The interval at which the probe needs to run is specified in the
   # property THOROUGH_PROBE_INTERVAL. Therefore, set the probe to sleep
   # for a duration of THOROUGH_PROBE_INTERVAL.
   sleep $PROBE_INTERVAL

   # Run an nslookup command of the IP address on which DNS is serving.
   hatimerun -t $PROBE_TIMEOUT /usr/sbin/nslookup $DNS_HOST $DNS_HOST \
   > $DNSPROBEFILE 2>&1

      retcode=$?
      if [ $retcode -ne 0 ]; then
            probefail=1
      fi

   # Make sure that the reply to nslookup comes from the HA-DNS
   # server and not from another nameserver mentioned in the 
   # /etc/resolv.conf file.
   if [ $probefail -eq 0 ]; then
# Get the name of the server that replied to the nslookup query.
   SERVER=` awk ' $1=="Server:" { print $2 }' \
   $DNSPROBEFILE | awk -F. ' { print $1 } ' `
   if [ -z "$SERVER" ]; then
      probefail=1
      else
         if [ $SERVER != $DNS_HOST ]; then
            probefail=1
         fi
   fi
fi

재시작 및 페일오버 비교

probefail 변수가 0(성공)이 아닌 다른 값일 경우 nslookup 명령이 시간 초과되었거나 샘플 서비스의 DNS가 아닌 다른 서버에서 응답을 보낸 것입니다. 이러한 경우 DNS 서버는 예상대로 작동하지 않으며 오류 모니터는 decide_restart_or_failover() 함수를 호출하여 데이터 서비스를 로컬로 다시 시작할 것인지 아니면 데이터 서비스를 다른 노드로 재할당하도록 RGM에 요청할 것인지 결정합니다. probefail 변수가 0일 경우 검사에 성공했다는 메시지가 생성됩니다.

   if [ $probefail -ne 0 ]; then
         decide_restart_or_failover
   else
         logger -p ${SYSLOG_FACILITY}.err\
         -t [$SYSLOG_TAG]\
         "${ARGV0} Probe for resource HA-DNS successful"
   fi

decide_restart_or_failover() 함수는 시간 창(Retry_interval)과 실패 횟수(Retry_count)를 사용하여 DNS를 로컬로 재시작할 것인지 아니면 데이터 서비스를 다른 노드로 재할당하도록 RGM에 요청할 것인지 결정합니다. 이 함수는 다음 조건부 논리를 구현합니다. PROBE 프로그램 코드 목록decide_restart_or_failover() 코드 목록에 코드가 들어 있습니다.

시간 간격 동안에 재시작 횟수가 한도에 도달할 경우 이 함수는 데이터 서비스를 다른 노드로 재할당하도록 RGM에 요청합니다. 재시작 횟수가 한도 이내이거나 간격이 초과되어 카운트가 다시 시작된 경우 이 함수는 동일한 노드에서 DNS의 재시작을 시도합니다. 이 함수와 관련하여 다음 사항에 주의하십시오.

데이터 서비스 재시작

동일한 노드에서 데이터 서비스를 재시작하기 위해 decide_restart_or_failover()에 의해 restart_service() 함수가 호출됩니다. 이 함수는 다음 논리를 실행합니다.

function restart_service
{

        # To restart the data service, first verify that the 
        # data service itself is still registered under PMF.
        pmfadm -q $PMF_TAG
        if [[ $? -eq 0 ]]; then
                # Since the TAG for the data service is still registered under
                # PMF, first stop the data service and start it back up again.

                # Obtain the Stop method name and the STOP_TIMEOUT value for
                # this resource.
                STOP_TIMEOUT=`scha_resource_get -O STOP_TIMEOUT \
                        -R $RESOURCE_NAME -G $RESOURCEGROUP_NAM?
                STOP_METHOD=`scha_resource_get -O STOP \
                        -R $RESOURCE_NAME -G $RESOURCEGROUP_NAM?
                hatimerun -t $STOP_TIMEOUT $RT_BASEDIR/$STOP_METHOD \
                        -R $RESOURCE_NAME -G $RESOURCEGROUP_NAME \
                        -T $RESOURCETYPE_NAME

                if [[ $? -ne 0 ]]; then
                        logger-p ${SYSLOG_FACILITY}.err -t [$SYSLOG_TAG] \
                                “${ARGV0} Stop method failed.”
                        return 1
                fi

                # Obtain the START method name and the START_TIMEOUT value for
                # this resource.
                START_TIMEOUT=`scha_resource_get -O START_TIMEOUT \
                        -R $RESOURCE_NAME -G $RESOURCEGROUP_NAM?
                START_METHOD=`scha_resource_get -O START \
                        -R $RESOURCE_NAME -G $RESOURCEGROUP_NAM?
                hatimerun -t $START_TIMEOUT $RT_BASEDIR/$START_METHOD \
                        -R $RESOURCE_NAME -G $RESOURCEGROUP_NAME \
                        -T $RESOURCETYPE_NAME

                if [[ $? -ne 0 ]]; then
                        logger-p ${SYSLOG_FACILITY}.err -t [$SYSLOG_TAG] \
                                “${ARGV0} Start method failed.”
                        return 1
                fi


        else
                # The absence of the TAG for the dataservice 
                # implies that the data service has already
                # exceeded the maximum retries allowed under PMF.
                # Therefore, do not attempt to restart the
                # data service again, but try to failover
                # to another node in the cluster.
                scha_control -O GIVEOVER -G $RESOURCEGROUP_NAME \
                        -R $RESOURCE_NAME
        fi

        return 0
}

검사 종료 상태

로컬 재시작 시도에 실패하고 다른 노드로 페일오버하려는 시도 역시 실패한 경우 샘플 데이터 서비스의 PROBE 프로그램은 실패 상태로 종료하고 페일오버 시도가 실패했습니다라는 메시지를 기록합니다.

Monitor_start 메소드 작동 방식

RGM은 샘플 데이터 서비스가 온라인 상태가 된 후 Monitor_start 메소드를 호출하여 dns_probe 메소드를 시작합니다.

이 절에서는 샘플 응용 프로그램에 사용된 Monitor_start 메소드의 주요 부분에 대해 설명합니다. parse_args() 함수, syslog() 함수와 같이 모든 콜백 메소드에 공통된 기능은 다루지 않습니다. 공통된 기능에 대해서는 모든 메소드에 공통 기능 제공에서 설명합니다.

Monitor_start 메소드의 전체 목록은 Monitor_start 메소드 코드 목록을 참조하십시오.

Monitor_start 메소드의 기능

이 메소드는 PMF(pmfadm)를 사용하여 검사를 시작합니다.

검사 시작

Monitor_start 메소드는 RT_basedir 등록 정보 값을 가져와서 PROBE 프로그램에 대한 전체 경로 이름을 구성합니다. 이 메소드는 pmfadm의 무한 재시도 옵션(-n -1, -t -1)을 사용하여 검사를 시작하며 이는 검사를 시작하는 데 실패할 경우 PMF에서 시간 제한 없이 검사 시작을 무한대로 시도한다는 것을 의미합니다.

# Find where the probe program resides by obtaining the value of the
# RT_basedir property of the resource.
RT_BASEDIR=`scha_resource_get -O RT_basedir -R $RESOURCE_NAME -G \
$RESOURCEGROUP_NAME`

# Start the probe for the data service under PMF. Use the infinite retries
# option to start the probe. Pass the resource name, type, and group to the
# probe program. 
pmfadm -c $RESOURCE_NAME.monitor -n -1 -t -1 \
   $RT_BASEDIR/dns_probe -R $RESOURCE_NAME -G $RESOURCEGROUP_NAME \
   -T $RESOURCETYPE_NAME

Monitor_stop 메소드 작동 방식

RGM은 샘플 데이터 서비스가 오프라인 상태가 되었을 때 Monitor_stop 메소드를 호출하여 dns_probe의 실행을 중지합니다.

이 절에서는 샘플 응용 프로그램에 사용된 Monitor_stop 메소드의 주요 부분에 대해 설명합니다. parse_args() 함수, syslog() 함수와 같이 모든 콜백 메소드에 공통된 기능은 다루지 않습니다. 공통된 기능에 대해서는 모든 메소드에 공통 기능 제공에서 설명합니다.

Monitor_stop 메소드의 전체 목록은 Monitor_stop 메소드 코드 목록을 참조하십시오.

Monitor_stop 메소드의 기능

이 메소드는 PMF(pmfadm)를 사용하여 검사가 실행 중인지 확인하고 검사가 실행 중일 경우 이를 중지합니다.

모니터 중지

Monitor_stop 메소드는 pmfadm -q를 사용하여 검사가 실행 중인지 확인하고 검사가 실행 중일 경우 pmfadm -s를 사용하여 이를 중지합니다. 검사가 이미 중지된 경우에도 이 메소드는 성공적으로 종료하므로 메소드의 멱등성이 보장됩니다.


주의 – 주의 –

TERM과 같은 마스크 가능한 신호가 아니라 KILL 신호를 pmfadm과 함께 사용하여 검사를 중지해야 합니다. 그렇지 않을 경우 Monitor_stop 메소드가 무한대로 정지되고 결국 시간이 초과될 수 있습니다. 이 문제의 원인은 PROBE 메소드가 데이터 서비스를 재시작하거나 페일오버해야 할 경우 scha_control()을 호출하기 때문입니다. scha_control()이 데이터 서비스를 오프라인 상태로 전환하는 과정의 일부로 Monitor_stop을 호출할 때 Monitor_stop이 마스크 가능한 신호를 사용하면 Monitor_stopscha_control()이 완료되기를 기다리면서 일시 정지되고 scha_control()Monitor_stop이 완료되기를 기다리면서 일시 정지됩니다.


# See if the monitor is running, and if so, kill it.
if pmfadm -q $PMF_TAG; then
   pmfadm -s $PMF_TAG KILL
   if [ $? -ne 0 ]; then
         logger -p ${SYSLOG_FACILITY}.err \
            -t [$SYSLOG_TAG] \
            "${ARGV0} Could not stop monitor for resource " \
            $RESOURCE_NAME
           exit 1
   else
         # could successfully stop the monitor. Log a message.
         logger -p ${SYSLOG_FACILITY}.err \
            -t [$SYSLOG_TAG] \
            "${ARGV0} Monitor for resource " $RESOURCE_NAME \
            " successfully stopped"
   fi
fi
exit 0

Monitor_stop 종료 상태

Monitor_stop 메소드는 PROBE 메소드를 중지할 수 없는 경우 오류 메시지를 기록합니다. RGM은 기본 노드에서 샘플 데이터 서비스를 MONITOR_FAILED 상태로 만들며 이로 인해 기본 노드에 패닉이 발생할 수 있습니다.

Monitor_stop은 검사가 중지되기 전까지 종료해서는 안 됩니다.

Monitor_check 메소드 작동 방식

PROBE 메소드가 데이터 서비스를 포함하는 자원 그룹을 새 노드로 페일오버하려고 시도할 때마다 RGM은 Monitor_check 메소드를 호출합니다.

이 절에서는 샘플 응용 프로그램에 사용된 Monitor_check 메소드의 주요 부분에 대해 설명합니다. parse_args() 함수, syslog() 함수와 같이 모든 콜백 메소드에 공통된 기능은 다루지 않습니다. 공통된 기능에 대해서는 모든 메소드에 공통 기능 제공에서 설명합니다.

Monitor_check 메소드의 전체 목록은 Monitor_check 메소드 코드 목록을 참조하십시오.

동시에 실행되는 다른 메소드와 충돌하지 않도록 Monitor_check 메소드를 구현해야 합니다.

Monitor_check 메소드는 새 노드에서 DNS 구성 디렉토리를 사용할 수 있는지 확인하기 위해 Validate 메소드를 호출합니다. Confdir 확장 등록 정보는 DNS 구성 디렉토리를 가리킵니다. 따라서 Monitor_check은 다음에 나온 것처럼 Validate 메소드의 경로 및 이름과 Confdir의 값을 얻은 다음 이 값을 Validate에 전달합니다.

# Obtain the full path for the Validate method from
# the RT_basedir property of the resource type.
RT_BASEDIR=`scha_resource_get -O RT_basedir -R $RESOURCE_NAME \
   -G $RESOURCEGROUP_NAM?

# Obtain the name of the Validate method for this resource.
VALIDATE_METHOD=`scha_resource_get -O Validate \
   -R $RESOURCE_NAME -G $RESOURCEGROUP_NAM?

# Obtain the value of the Confdir property in order to start the
# data service. Use the resource name and the resource group entered to
# obtain the Confdir value set at the time of adding the resource.
config_info=`scha_resource_get -O Extension -R $RESOURCE_NAME \
 -G $RESOURCEGROUP_NAME Confdir`

# scha_resource_get returns the type as well as the value for extension
# properties. Use awk to get only the value of the extension property.
CONFIG_DIR=`echo $config_info | awk `{print $2}'`

# Call the validate method so that the dataservice can be failed over
# successfully to the new node.
$RT_BASEDIR/$VALIDATE_METHOD -R $RESOURCE_NAME -G $RESOURCEGROUP_NAME \
   -T $RESOURCETYPE_NAME -x Confdir=$CONFIG_DIR

샘플 응용 프로그램에서 데이터 서비스를 호스트하는 데 특정 노드가 적합한지 확인하는 방법에 대해서는 Validate 메소드 작동 방식을 참조하십시오.