Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationEventAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
0
Help us understand the problem. What are the problem?

More than 5 years have passed since last update.

posted at

updated at

solaris10にzabbix-agent3.0を導入する

1.はじめに

zabbix3.0でsolarisを監視する事になりました。
クラウドに行き遅れてしまったsolarisの情報は少ないのでzabbix-agentを導入した際の記録を残します。

2.インストール方法

最初はsrcを入手してコンパイルを試みましたが、ライブラリの32ビット問題が出てあきらめました。

で公開されている「Zabbix pre-compiled agents」を使う事にしました。

3.インストール

必要なディレクトリの作成

# mkdir /var/log/zabbix
# chmod 777 /var/log/zabbix
# mkdir /var/run/zabbix
# chmod 777 /var/run/zabbix
# mkdir /etc/zabbix
# chmod 777 /etc/zabbix

それぞれ、ログ出力先とPID出力先とconfig配置先です。

agentファイルの配置

# cd /usr/local/src
# gzip -cd zabbix_agent_so10.tar.gz|tara xvf -
# cd zabbix_agent_so10

# cd bin
# cp -p * /usr/local/bin/

# cd ../sbin
# cp -p * /usr/local/sbin/

# cd ../conf
# cp -pr * /etc/zabbix/

# cd ../init.d
# cp -p * /etc/init.d/

# cd ../manifest
# cp -p * /var/svc/manifest/network/

# cd ../method
# cp -p * /lib/svc/method/

init.dとmanifestとmethodは、自動起動(SMF)用で自分で作成しました。

zabbix_agentd(起動スクリプト)

#!/bin/sh

# Zabbix
# Copyright (C) 2001-2016 Zabbix SIA
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

# Start/Stop the Zabbix agent daemon.
# Place a startup script in /sbin/init.d, and link to it from /sbin/rc[023].d 

SERVICE="Zabbix agent"
DAEMON=/usr/local/sbin/zabbix_agentd
PIDFILE=/var/run/zabbix/zabbix_agentd.pid

case $1 in
  'start')
    if [ -x ${DAEMON} ]
    then
      $DAEMON
      # Error checking here would be good...
      echo "${SERVICE} started."
    else
      echo "Can't find file ${DAEMON}."
      echo "${SERVICE} NOT started."
    fi
  ;;
  'stop')
    if [ -s ${PIDFILE} ]
    then
      if kill `cat ${PIDFILE}` >/dev/null 2>&1
      then
        echo "${SERVICE} terminated."
        rm -f ${PIDFILE}
      fi
    fi
  ;;
  'restart')
    $0 stop
    sleep 10
    $0 start
  ;;
  *)
    echo "Usage: $0 start|stop|restart"
    ;;
esac

XML形式のマニフェスト(zabbix-agent.xml)

<?xml version="1.0"?>
<!DOCTYPE service_bundle SYSTEM "/usr/share/lib/xml/dtd/service_bundle.dtd.1">
<service_bundle type='manifest' name='AVSzabbix:zabbix-agent'>
  <service name='network/zabbix-agent' type='service' version='1'>

    <create_default_instance enabled='false'/>
    <single_instance/>

    <dependency name='fs' 
        type='service'
        grouping='require_all'
        restart_on='none'>
        <service_fmri value='svc:/system/filesystem/local'/>
    </dependency>

    <dependency name='net'
        type='service'
        grouping='require_all'
        restart_on='none'>
        <service_fmri value='svc:/network/loopback'/>
    </dependency>

    <exec_method type='method' name='start' 
        exec='/lib/svc/method/svc-zabbix-agent start'
        timeout_seconds='60'/>

    <exec_method type='method' name='stop'
        exec='/lib/svc/method/svc-zabbix-agent stop'
        timeout_seconds='60'/>

  </service>
</service_bundle>

SMF起動/停止スクリプト(svc-zabbix-agent)

#!/bin/bash
#

. /lib/svc/share/smf_include.sh

# Variables
# Edit these to match your system settings

# Zabbix-Directory
BASEDIR=/usr/local

# Binary File
BINARY_NAME=zabbix_agentd

# Full Binary File Call
FULLPATH=$BASEDIR/sbin/$BINARY_NAME

# PID file
PIDFILE=/var/run/zabbix/$BINARY_NAME.pid

# Establish args
RETVAL=$SMF_EXIT_OK
ERROR=0
STOPPING=0

# conf
CONF=/etc/zabbix/zabbix_agentd.conf

#
# No need to edit the things below
#

# application checking status
if [ -f $PIDFILE  ] && [ -s $PIDFILE ]
        then
        PID=`cat $PIDFILE`

        if [ "x$PID" != "x" ] && kill -0 $PID 2>/dev/null && [ $BINARY_NAME == `ps -e | grep $PID | awk '{print $4}'` ]
        then
                STATUS="$BINARY_NAME (pid `pidof $APP`) running.."
                RUNNING=1
        else
                rm -f $PIDFILE
                STATUS="$BINARY_NAME (pid file existed ($PID) and now removed) not running.."
                RUNNING=0
        fi
else
        if [ `ps -e | grep $BINARY_NAME | head -1 | awk '{ print $1 }'` ]
                then
                STATUS="$BINARY_NAME (pid `pidof $APP`, but no pid file) running.."
        else
                STATUS="$BINARY_NAME (no pid file) not running"
        fi
        RUNNING=0
fi

# functions
start() {
        if [ $RUNNING -eq 1 ]
                then
                echo "$0 $ARG: $BINARY_NAME (pid $PID) already running"
        else
                echo "Starting $BINARY_NAME" 
                exec $FULLPATH -c $CONF
                RETVAL=$?
        fi
}

stop() {
        echo -n $"Shutting down $BINARY_NAME"
        pkill $BINARY_NAME
        RETVAL=$?
}


# logic
case "$1" in
        start)
                start
                ;;
        stop)
                stop
                ;;
        restart)
                stop
                start
                ;;
        help|*)
                echo $"Usage: $0 {start|stop|status|help}"
                cat <<EOF

                        start           - start $BINARY_NAME
                        stop            - stop $BINARY_NAME
                        restart         - restart $BINARY_NAME if running by sending a SIGHUP or start if not running
                        help            - this screen

EOF
        exit $SMF_EXIT_ERR_FATAL
        ;;
esac

exit $RETVAL

zabbix設定ファイルの修正

# vi /etc/zabbix/zabbix_agentd.conf
Hostname=   

ホスト名を設定する。
→共通の設定はすでに登録済み。(内容は後日公開予定)

4.agentの設定

自動起動を有効にする

配置済みのマニュフェストファイルをSMFにインポートする。

# svccfg import /var/svc/manifest/network/zabbix-agent.xml

zabbix-agentの自動起動を有効にする

# svcs -a|grep zabbix
# svcadm enable svc:/network/zabbix-agent:default
# svcs -a|grep zabbix

onlineになれば起動されて、自動起動もONになります。

ココまでが、global ZONEでの導入です。
次回以降、コンテナZONEの導入について記載します。

2017/11/17 配布ファイルを記載しました。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
0
Help us understand the problem. What are the problem?