LoginSignup
2
3

More than 5 years have passed since last update.

CentOS6.7+zabbix3.0 install

Posted at

概要

zabbixの概要理解についてはさくらのナレッジの次の記事が役立った。

統合監視ツール「Zabbix」によるサーバー監視

めちゃくちゃ簡単にまとめると次の通り

  • 目的
    • Serverの監視、通知(起動の有無、設定した閾値を超えた場合のmail通知等
  • 類似Tool
  • 以下の3つのmoduleで動作
    • zabbix-web:zabbixの設定、serverで収集した情報の表示
    • zabbix-server:agentから情報を収集
    • zabbix-agent:監視対象にinstall。serverに情報を送信

環境

OS CentOS 6.7
Zabbix Zabbix 3.0

Install

Zabbixのweb,server,agentをすべて一つのserverにinstallする。
監視対象を増やしたい場合には対象serverにzabbix-agentのみinstallすれば良い。
今回Ansible Galaxyの次のRoleを使わせていただいた。

  • geerlingguy.apache
  • geerlingguy.mysql
  • dj-wasabi.zabbix-server
  • dj-wasabi.zabbix-agent

zabbixをinstallした際にapacheとのversionが合わず、zabbix-serverの設定fileが上手く設定されなかったためtemplateで置き換えた。
zabbix-webのIPはGlobal IPを使い、zabbix-serverのIPはPrivate IPを使うようにした。

zabbixserver.yml
- name: Install php
  hosts: zabbixserver
  tasks:
  - name: Add repository 'epel-repo'
    yum: name=http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm state=present
  - name: Add repository 'remi-repo'
    yum: name=http://rpms.famillecollet.com/enterprise/remi-release-6.rpm state=present
  - name: Install php 5.5
    yum: name={{ item }} state=present enablerepo=remi,remi-php55
    with_items:
      - php
      - php-mysql
      - php-mbstring
      - php-gd
      - php-bcmath
      - php-xml

- name: configure zabbix-server
  hosts: zabbixserver
  roles:
    - { role: geerlingguy.apache }
    - { role: geerlingguy.mysql }
    - role: dj-wasabi.zabbix-server
      zabbix_url: "{{ zabbixserver.global_ip }}"
      zabbix_version: 3.0
      zabbix_timezone: Asia/Tokyo
      database_type: mysql
      database_type_long: mysql
  tasks:
    - name: set up config file
      template: src=roles/zabbix/templates/zabbix.conf.j2 dest=/etc/httpd/conf.d/zabbix.conf
      vars:
        zabbix_host: "{{ zabbixserver.global_ip }}"
    - name: replace hostname to IpAddress in config file
      lineinfile: >
        dest=/etc/zabbix/web/zabbix.conf.php
        regexp='^\$ZBX_SERVER      ='
        line="$ZBX_SERVER      = '{{ zabbixserver.private_ip }}';"
      notify: restart httpd
  handlers:
    - name: restart httpd
      service: name=httpd state=restarted

- name: configure zabbix-agent
  hosts: zabbixserver
  roles:
    - role: dj-wasabi.zabbix-agent
      agent_server: "{{ zabbixserver.private_ip }},127.0.0.1"
      agent_serveractive: "{{ zabbixserver.private_ip }},127.0.0.1"
roles/zabbix/templates/zabbix.conf.j2
<VirtualHost *:80>
  ServerName {{ zabbix_host }}

  ## Vhost docroot                                                                                          
  DocumentRoot "/usr/share/zabbix"


  <Directory "/usr/share/zabbix">
      AllowOverride None
    Order Allow,Deny
    Allow from all
    </Directory>

  <Directory "/usr/share/zabbix/conf">
      AllowOverride None
    Order Deny,Allow
    Deny from all
    </Directory>

  <Directory "/usr/share/zabbix/api">
      AllowOverride None
    Order Deny,Allow
    Deny from all
    </Directory>

  <Directory "/usr/share/zabbix/include">
      AllowOverride None
    Order Deny,Allow
    Deny from all
    </Drectory>

  <Directory "/usr/share/zabbix/include/classes">
      AllowOverride None
    Order Deny,Allow
    Deny from all
    </Directory>

  ## Logging                                                                                                
  ErrorLog "/var/log/httpd/{{ zabbix_host }}_error.log"
  ServerSignature Off
  CustomLog "/var/log/httpd/{{ zabbix_host }}_access.log" combined

  ## Rewrite rules                                                                                          
  RewriteEngine On
  RewriteRule ^$ /index.php [L]

  ## Custom fragment                                                                                        
  php_value max_execution_time 300
  php_value memory_limit 128M
  php_value post_max_size 16M
  php_value upload_max_filesize 2M
  php_value max_input_time 300
  # Set correct timezone.                                                                                   
  php_value date.timezone Asia/Tokyo
</VirtualHost>

結果

defaultの設定だとAdmin/zabbixでloginできる。
mysqlは勝手にzabbixというDBを作成してくれるので特に気にしなくても大丈夫だった。
後、defaultではserverとagentでportの10050と10051を使うので開放を忘れずに。

どういう値を監視するのかといった設定はこのweb frontから行う。また色々いじってみたい。

スクリーンショット 2016-07-18 23.49.17.png

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3