この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
はじめに
こんにちは、川原です。 最近、業務の関係で運用監視ツールのZabbixをさわる機会が多いです。 弊社のブログで以前、Zabbix2.0系のインストールを紹介した記事がありましたが1、今回はその最新バージョンである2.4系をAmazon Linuxにインストールしてみたので、その方法を紹介します。
前提
インストール先のAmazon Linuxは下記
- Amazon Linux AMI 2015.03 (HVM)
インストールするZabbixのバージョンは下記
- 2.4-1
やってみた
まずはパッケージ群のインストールを行います。インストール対象のEC2インスタンスにSSHでログインして、下記のような感じですすめます。
# rootにスイッチ
$ sudo su -
# RPMファイルの登録
$ rpm -ivh http://repo.zabbix.com/zabbix/2.4/rhel/6/x86_64/zabbix-release-2.4-1.el6.noarch.rpm
# Zabbixパッケージ群のインストール
$ yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-web-japanese zabbix-agent
〜出力省略〜
#インストール結果の確認
$ zabbix_server -V
Zabbix server v2.4.5 (revision 53282) (21 April 2015)
Compilation time: Apr 22 2015 23:08:17
次にZabbixで使用するDBMSをインストールします。MySQLやPostgresqlなどメジャーなものは使えるようですが、今回はMySQLをインストールします。
$ yum -y install mysql-server
〜出力省略〜
$ mysqladmin version
mysqladmin Ver 8.42 Distrib 5.5.42, for Linux on x86_64
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Server version 5.5.42
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /var/lib/mysql/mysql.sock
Uptime: 20 min 48 sec
Threads: 23 Questions: 1479 Slow queries: 0 Opens: 59 Flush tables: 1 Open tables: 52 Queries per second avg: 1.185
バージョン5.5.42のものがインストールされました。 次にMySQLの設定を行います。
#データベースとユーザーの作成
$ mysql -uroot
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'YOURPASSWORD';
mysql> exit
#スキーマの登録
$ cd /usr/share/doc/zabbix-server-mysql-2.4.5/create/
$ mysql -uroot zabbix < schema.sql
$ mysql -uroot zabbix < images.sql
$ mysql -uroot zabbix < data.sql
ZabbixはPHPを使って実装されています。 PHPの設定ファイルの編集を行います。
# メモリ周りの設定変更
$ sed -i -e "s/memory_limit = 128M/memory_limit = 256M/g" /etc/php.ini
$ sed -i -e "s/post_max_size = 8M/post_max_size = 16M/g" /etc/php.ini
$ sed -i -e "s/max_execution_time = 90/max_execution_time = 300/g" /etc/php.ini
$ sed -i -e "s/max_input_time = 60/max_input_time = 300/g" /etc/php.ini
# タイムゾーンの設定
$ sed -i -e "s/;date.timezone =/date.timezone = Asia\/Tokyo/g" /etc/php.ini
# Zabbixの起動時のセキュリティチェックでエラーとなるのでコメントアウトする
$ sed -i -e "s/;always_populate_raw_post_data/always_populate_raw_post_data/g" /etc/php.ini
Apacheの設定を行います。 Apacheは2.2系と2.4系でアクセス制御回りの設定方法が変わっていますが、Zabbixのパッケージに付属している設定ファイルが2.2系のものなので、その辺りの変更を行います。 詳しくはこちらを参照ください。
$ vi /etc/httpd/conf.d/zabbix.conf
#
# Zabbix monitoring system php web frontend
#
Alias /zabbix /usr/share/zabbix
<Directory "/usr/share/zabbix">
Options FollowSymLinks
AllowOverride None
#Order allow,deny
#Allow from all
Require all granted
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
# php_value date.timezone Europe/Riga
php_value date.timezone Asia/Tokyo
</Directory>
<Directory "/usr/share/zabbix/conf">
#Order deny,allow
#Deny from all
Require all denied
<files *.php>
#Order deny,allow
#Deny from all
Require all denied
</files>
</Directory>
<Directory "/usr/share/zabbix/api">
#Order deny,allow
#Deny from all
Require all denied
<files *.php>
#Order deny,allow
#Deny from all
Require all denied
</files>
</Directory>
<Directory "/usr/share/zabbix/include">
#Order deny,allow
#Deny from all
Require all denied
<files *.php>
#Order deny,allow
#Deny from all
Require all denied
</files>
</Directory>
<Directory "/usr/share/zabbix/include/classes">
#Order deny,allow
#Deny from all
Require all denied
<files *.php>
#Order deny,allow
#Deny from all
Require all denied
</files>
</Directory>
最後にZabbix設定ファイルの編集を行います。
$ vi /etc/zabbix/zabbix_server.conf
#以下箇所を適切に修正します
#DBName、DBUser、DBPasswordは上のMySQLの設定で行ったデータベース名、ユーザー名、パスワードと整合するように記載
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=YOURPASSWORD
これで設定ファイルの編集はおしまいです。 各ミドルの起動と、OS起動時の設定を行います。
$ service mysqld start
$ chkconfig mysqld on
$ service zabbix-server start
$ chkconfig zabbix-server on
$ service httpd start
$ chkconfig httpd on
これで準備は完了です。
疎通確認
ブラウザから、下記URLにアクセスしてみましょう。
http://"EC2のPublic IP"/zabix/
無事、アクセスできました。 初回アクセス時はウィザード画面で色々聞かれます。ウィザード後の下記画面では次のアカウント情報でログインしてください。
- Username: Admin
- Password: zabbix
最初は英語表示ですが、ユーザー設定画面で「Language(言語)」を変更することで日本語表示も問題ありません。
まとめ
現時点の最新Amazon LinuxにZabbix2.4系をインストールしてみました。 2.0系から大きく手順が変わるところはありませんでした。 Zabbixを使い倒して運用監視を楽にしましょう。 では、また。