m_shige1979のときどきITブログ

プログラムの勉強をしながら学習したことや経験したことをぼそぼそと書いていきます

Github(変なおっさんの顔でるので気をつけてね)

https://github.com/mshige1979

zabbixインストールでエージェントを監視対象サーバへ設定

エージェントの設定

サーバにエージェントをいれても仕方ないので別サーバを用意して設定

環境

zabbixサーバ

CentOS6.5 64bit
MySQL5.6
PHP5.5
Nginx
IP:192.168.51.129

zabbixエージェント用のサーバ

CentOS6.5 64bit
IP:192.168.51.130

設定(エージェント用サーバ設定)

zabbixのユーザーを作成
[root@localhost ~]# groupadd zabbix
[root@localhost ~]# useradd -g zabbix zabbix
[root@localhost ~]# cat /etc/passwd | grep zabbix
zabbix:x:502:502::/home/zabbix:/bin/bash
[root@localhost ~]#
ダウンロードしたソースファイルを配置
[root@localhost ~]# ll /tmp/zabbix-2.2.2.tar.gz
-rw-r--r-- 1 root root 14595839  3月 17 20:08 2014 /tmp/zabbix-2.2.2.tar.gz
[root@localhost ~]#
解凍
[root@localhost ~]# cd /tmp/
[root@localhost tmp]# tar zxf zabbix-2.2.2.tar.gz
[root@localhost tmp]#
コンパイル&インストール
[root@localhost ~]# cd /tmp/
[root@localhost tmp]# tar zxf zabbix-2.2.2.tar.gz
[root@localhost tmp]#

# コンパイル
[root@localhost ~]# cd /tmp/
[root@localhost tmp]# tar zxf zabbix-2.2.2.tar.gz
[root@localhost tmp]# cd zabbix-2.2.2
[root@localhost zabbix-2.2.2]#
[root@localhost zabbix-2.2.2]# ./configure \
    --prefix=/usr/share/zabbix \
    --enable-agent

[root@localhost zabbix-2.2.2]# make install
[root@localhost zabbix-2.2.2]# ll /usr/share/zabbix/
合計 20
drwxr-xr-x 2 root root 4096  3月 22 10:40 2014 bin
drwxr-xr-x 4 root root 4096  3月 22 10:40 2014 etc
drwxr-xr-x 2 root root 4096  3月 22 10:40 2014 lib
drwxr-xr-x 2 root root 4096  3月 22 10:40 2014 sbin
drwxr-xr-x 3 root root 4096  3月 22 10:40 2014 share
[root@localhost zabbix-2.2.2]#
設定ファイルを編集
[root@localhost etc]# mkdir -p /var/log/zabbix
[root@localhost etc]# chown -R zabbix.zabbix /var/log/zabbix/
[root@localhost etc]# vim /usr/share/zabbix/etc/zabbix_agentd.conf
----
LogFile=/var/log/zabbix/zabbix_agentd.log
Server=192.168.51.129
ServerActive=192.168.51.129
Hostname=zabbix_agent01
----
  • LogFile:ログファイルのパス
  • Server:ZabbixサーバのIPアドレス
  • ServerActive:ZabbixサーバのIPアドレス
  • Hostname:このzabbixエージェントのホスト名とする
起動スクリプトの設定
[root@localhost zabbix-2.2.2]# cp -a /tmp/zabbix-2.2.2/misc/init.d/fedora/core5/zabbix_agentd /etc/init.d/.
[root@localhost zabbix-2.2.2]# vim /etc/init.d/zabbix_agentd
----
ZABBIX_BIN="/usr/share/zabbix/sbin/zabbix_agentd"
----
起動
[root@localhost zabbix-2.2.2]# service zabbix_agentd start
Zabbix Agent を起動中:                                     [  OK  ]
[root@localhost zabbix-2.2.2]#
起動確認
[root@localhost zabbix-2.2.2]# ps aux | grep zabbix_agentd
zabbix    9973  0.9  0.0  17584   732 ?        S    11:06   0:00 /usr/share/zabbix/sbin/zabbix_agentd
zabbix    9974  0.0  0.0  17584   708 ?        S    11:06   0:00 /usr/share/zabbix/sbin/zabbix_agentd: collector [idle 1 sec]
zabbix    9975  0.0  0.0  17584   620 ?        S    11:06   0:00 /usr/share/zabbix/sbin/zabbix_agentd: listener #1 [waiting for connection]
zabbix    9976  0.0  0.0  17584   620 ?        S    11:06   0:00 /usr/share/zabbix/sbin/zabbix_agentd: listener #2 [waiting for connection]
zabbix    9977  0.0  0.0  17584   620 ?        S    11:06   0:00 /usr/share/zabbix/sbin/zabbix_agentd: listener #3 [waiting for connection]
zabbix    9978  0.1  0.0  17596   768 ?        S    11:06   0:00 /usr/share/zabbix/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
root      9980  0.0  0.0 107520   948 pts/0    S+   11:06   0:00 grep zabbix_agentd
[root@localhost zabbix-2.2.2]#
自動起動設定
[root@localhost zabbix-2.2.2]# chkconfig zabbix_agentd on
[root@localhost zabbix-2.2.2]# chkconfig --list zabbix_agentd
zabbix_agentd   0:off   1:off   2:on    3:on    4:on    5:on    6:off
[root@localhost zabbix-2.2.2]#



zabbixサーバの設定

ホスト設定

「設定」>「ホスト」で画面を移動

f:id:m_shige1979:20140322122726j:plain

「ホストの作成」をクリック

f:id:m_shige1979:20140322122740j:plain

設定

f:id:m_shige1979:20140322122747j:plain

  • ホスト名  :zabbix_agent01
  • 表示名   :zabbix_agent01
  • 所属グループ:Linux servers
  • エージェントのインターフェース

 IP:192.168.51.130

追加されたことを確認

f:id:m_shige1979:20140322122752j:plain

テンプレート設定

「設定」>「テンプレート」で画面遷移

f:id:m_shige1979:20140322122758j:plain

「テンプレートの作成」をクリック

f:id:m_shige1979:20140322122802j:plain

設定

f:id:m_shige1979:20140322122808j:plain

  • テンプレート名:Test_template01
  • 表示名    :テストテンプレート01
  • グループ   :Linux servers
  • ホスト/テンプレート:zabbix_agent01
テンプレートが作成されたことを確認

f:id:m_shige1979:20140322122814j:plain

アイテム

「アイテム」をクリック

f:id:m_shige1979:20140322122820j:plain

「アイテムの作成」をクリック

f:id:m_shige1979:20140322122900j:plain

設定

f:id:m_shige1979:20140322122906j:plain

  • 名前:CPU usage
  • タイプ    :CPU usage
  • キー     :Zabbixエージェント
  • データ型   :system.cpu.util[,,]
  • 更新間隔(秒):数値(浮動小数
作成されたことを確認

f:id:m_shige1979:20140322122914j:plain

監視確認

「監視データ」>「最新データ」を指定

f:id:m_shige1979:20140322122923j:plain

グループを「Linux servers」へ切り替え表示切り替え

f:id:m_shige1979:20140322122930j:plain

「CPU usage」の「グラフ」をクリック

f:id:m_shige1979:20140322122937j:plain



まとめ

サーバもエージェントも最初は設定が面倒な感じ…。インストールがうまくいけばあとはある程度簡単に出来そう。
自宅の環境では重いので外部にサーバを借りてやってみよう。