9
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Zabbix入門のメモ(インストール)

Last updated at Posted at 2014-04-17

仕事で使うので、Zabbixのメモ。
書籍「Zabbix統合監視実践入門」をベースにお勉強します。
使用するバージョンは2.2.3。書籍とバージョンが違うけれども気にしない。

インストール

Zabbixエージェント

LinuxにもWindowsにも入る。
とりあえずCentOSに対して、yumでzabbixのリポジトリを追加してインストール。

Linuxの設定ファイル
Windowsの設定ファイル

recipes/agent.rb
# zabbixのリポジトリを追加
include_recipe 'zabbix-origin::yumrepo'

# zabbix-agentのインストール
package "zabbix-agent"

# サーバのIPアドレス、自身のホスト名とIPアドレスを設定ファイルに記載
template "/etc/zabbix/zabbix_agentd.conf" do
  source "zabbix_agentd.conf.erb"
  variables(
    :server_ipaddr  => node['zabbix']['server']['ipaddr'],
    :agent_hostname => node['zabbix']['agent']['hostname'],
    :agent_ipaddr   => node['zabbix']['agent']['ipaddr']
  )
  notifies :restart, "service[zabbix-agent]"
end

# zabbix-agentの自動起動設定と起動
service "zabbix-agent" do
  supports :status => true, :restart => true
  action   [:enable, :start]
end

Zabbixサーバ

ZabbixサーバにはバックエンドとしてDBが必要で、MySQLPostgreSQLなどが利用できる。
PostgreSQLを使いたいけど、ネットで見てる感じだとみんなMySQLを使っているようなので、MySQLで構築。
テンプレートとかの設定はDBの値で保持しているみたいなので、設定を変更したい場合はインポートするためのSQLを自動生成してあげればいいのかな。

設定ファイルのリファレンス

recipes/server.rb
# リポジトリの追加とZabbixエージェントのインストール
include_recipe 'zabbix-origin::yumrepo'
include_recipe 'zabbix-origin::agent'

# MySQLのインストール、設定、自動起動設定、起動
package 'mysql-server'

template "/etc/my.cnf" do
  source "mysql_my.cnf.erb"
  variables(
    :buffer_pool_size   => node['zabbix']['server']['mysql']['buffer_pool_size']
    :log_file_size      => node['zabbix']['server']['mysql']['log_file_size']
    :log_files_in_group => node['zabbix']['server']['mysql']['log_files_in_group']
  )
  notifies :restart, "service[mysqld]"
end

service "mysqld" do
  supports :status => true, :restart => true
  action   [:enable, :start]
end

# zabbix-serverのパッケージをインストール
%w[
  zabbix-server-mysql
  zabbix-web-mysql
  zabbix-web-japanese
].each do |p|
  package p do
    version "#{node['zabbix']['version']}-1.el6"
  end
end

# MySQLへのデータ初期投入
import_sql_dir = "/usr/share/doc/zabbix-server-mysql-#{node['zabbix']['version']}/create"
template File.join(import_sql_dir, "create.sql") do
  source "mysql_create.sql.erb"
  variables(
    :dbhost     => node['zabbix']['server']['mysql']['dbhost']
    :dbname     => node['zabbix']['server']['mysql']['dbname']
    :dbuser     => node['zabbix']['server']['mysql']['dbuser']
    :dbpassword => node['zabbix']['server']['mysql']['dbpassword']
  )
end

execute "create zabbix database and user" do
  command "mysql -uroot < create.sql && touch create.sql.executed"
  creates "create.sql.executed"
  cwd     import_sql_dir
end

%w[
  schema.sql
  images.sql
  data.sql
].each do |sql|
  execute "import #{sql}" do
    command "mysql -uroot #{node['zabbix']['server']['mysql']['dbname']} < #{sql} && touch #{sql}.executed"
    creates "#{sql}.executed"
    cwd     import_sql_dir
  end
end

# Zabbixサーバの設定ファイルの編集
template "/etc/zabbix/zabbix_server.conf" do
  source "zabbix_server.conf.erb"
  variables(
    :dbhost     => node['zabbix']['server']['mysql']['dbhost']
    :dbname     => node['zabbix']['server']['mysql']['dbname']
    :dbuser     => node['zabbix']['server']['mysql']['dbuser']
    :dbpassword => node['zabbix']['server']['mysql']['dbpassword']
  )
  notifies :restart, "service[zabbix-server]"
end

template "/etc/httpd/conf.d/zabbix.conf" do
  source   "httpd_zabbix.conf.erb"
  notifies :restart, "service[httpd]"
end

template "/etc/zabbix/web/zabbix.conf.php" do
  source "web_zabbix.conf.php.erb"
  variables(
    :dbhost     => node['zabbix']['server']['mysql']['dbhost']
    :dbname     => node['zabbix']['server']['mysql']['dbname']
    :dbuser     => node['zabbix']['server']['mysql']['dbuser']
    :dbpassword => node['zabbix']['server']['mysql']['dbpassword']
  )
  notifies :restart, "service[zabbix-server]"
end

# zabbix-serverとapacheの自動起動設定と起動
service "zabbix-server" do
  supports :status => true, :restart => true
  action   [:enable, :start]
end

service "httpd" do
  supports :status => true, :restart => true
  action   [:enable, :start]
end

クイックスタートガイド

  • Webインタフェースへのログインはhttp://<サーバ>/zabbix
  • デフォルトのアカウントはアカウント:Admin、パスワード:zabbix
  • 日本語化するにはWebインタフェースから[管理] - [ユーザー] → メンバーを選択して言語を日本語にするか、データ初期投入前に/usr/share/doc/zabbix-server-mysql-2.2.3/create/data.sqlusersテーブルへのINSERT文をen_USja_JPに変更しておく
9
10
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
9
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?