【連載Zabbix】 Zabbix 3.4 を Amazon Linux で試す 【UserDataで簡単インストール】

記事タイトルとURLをコピーする

カスタマーサポート課の伊藤です。
普段は九龍と呼ばれています。

前回のBlogでご紹介したとおり、 Zabbix 3.4 がリリースされました。
同時に、serverworks の Zabbix リポジトリでもAmazon Linux用パッケージの提供を開始しています。
今回はテスト用の環境を簡単に構築する方法をご紹介します。
※EC2 on MySQL の構成ですので、本番環境などではRDS等の高可用化、パスワードの高度化などを行ってください。

Zabbixインストール

UserDataによる環境構築

UserDataを利用して、必要パッケージのインストール、一部対話処理の部分のためのスクリプト配置を行います。
以下のUserDataを入力してEC2インスタンスを起動します。

#!/bin/bash
version=3.4#Zabbixのバージョンをしていします。必要に応じて変更してください
docversion=3.4.0#初期DBのバージョンを指定します。最新のナンバーに変更します。
echo [serverworks-zabbix] >> /etc/yum.repos.d/serverworks.repo
echo name=Serverworks-Zabbix >> /etc/yum.repos.d/serverworks.repo
echo baseurl=https://s3-ap-northeast-1.amazonaws.com/serverworks-yum-repos/zabbix/$version/\$basearch >> /etc/yum.repos.d/serverworks.repo
echo gpgcheck=0 >> /etc/yum.repos.d/serverworks.repo
yum update -y
yum install --enablerepo=epel iksemel iksemel-devel -y
yum install zabbix-server-mysql zabbix-web-mysql zabbix-web-japanese zabbix-java-gateway zabbix-agent zabbix-get zabbix-sender httpd24 mysql56 mysql56-server -y
echo "mysql -root -p -e \"create database zabbix character set utf8 collate utf8_bin; grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';\" "> /home/ec2-user/createdb1.sh
echo zcat \/usr\/share\/doc\/zabbix-server-mysql-$docversion\/create.sql.gz \| mysql -uzabbix -p zabbix > /home/ec2-user/createdb2.sh
echo "mysql -uzabbix -p zabbix -e \"ALTER TABLE history ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8; ALTER TABLE history_log ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8; ALTER TABLE history_str ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8; ALTER TABLE history_text ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8; ALTER TABLE history_uint ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8; ALTER TABLE events ROW_FORMAT=COMPRESSED KEY_BLOCK_SIZE=8;\" " > /home/ec2-user/conplesdb.sh
chmod +x /home/ec2-user/createdb1.sh /home/ec2-user/createdb2.sh /home/ec2-user/conplesdb.sh
sed -i -e 's/# DBHost=localhost/DBHost=localhost/g' /etc/zabbix/zabbix_server.conf
sed -i -e 's/# DBPassword=/DBPassword=zabbix/g' /etc/zabbix/zabbix_server.conf
sed -i -e 's/# php_value date.timezone Europe\/Riga/php_value date.timezone Asia\/Tokyo/g' /etc/httpd/conf.d/zabbix.conf
chkconfig zabbix-server on
chkconfig zabbix-agent on
chkconfig zabbix-java-gateway on
chkconfig httpd on
chkconfig mysqld on
echo [mysqld] > /etc/my.cnf
echo user=mysql >> /etc/my.cnf
echo datadir=/data >> /etc/my.cnf
echo socket=/var/lib/mysql/mysql.sock >> /etc/my.cnf
echo character-set-server=utf8 >> /etc/my.cnf
echo ignore-db-dir = lost+found >> /etc/my.cnf
echo \#\#\# Tuning Setting >> /etc/my.cnf
echo innodb_file_per_table =1 >> /etc/my.cnf
echo innodb_autoextend_increment = 1 >> /etc/my.cnf
echo innodb_file_format=Barracuda >> /etc/my.cnf
echo innodb_buffer_pool_size = 512M >> /etc/my.cnf
echo innodb_thread_concurrency = 20 >> /etc/my.cnf
echo innodb_flush_log_at_trx_commit=2 >> /etc/my.cnf
echo innodb_log_buffer_size=32M >> /etc/my.cnf
echo innodb_log_file_size = 256M >> /etc/my.cnf
echo innodb_support_xa = 0 >> /etc/my.cnf
echo innodb_checksums = 0 >> /etc/my.cnf
echo innodb_doublewrite = 0 >> /etc/my.cnf
echo [mysqld_safe] >> /etc/my.cnf
echo log-error=/var/log/mysqld.log >> /etc/my.cnf
echo pid-file=/var/run/mysqld/mysqld.pid >> /etc/my.cnf
echo [mysql] >> /etc/my.cnf
echo default-character-set=utf8 >> /etc/my.cnf
service mysqld start
cd /tmp
yum install -y https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm

MySQL設定

MySQLのsecure_installationは対話型なので、この部分はインスタンスにログインして実施します。

$ mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we'll need the current
password for the root user. If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none): 初期パスワードは空なので、そのままエンター
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] Y任意のパスワードを設定してください。
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] Y
... Success!
By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
- Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
... Failed! Not critical, keep moving...
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
... Success!
All done! If you've completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
Cleaning up...

Userdaraで作製したスクリプトを実行して、ZabbixDBを構築します。

$ ./createdb1.sh
Enter password:先ほどsecure_installationで設定したrootパスワードを入力します。
$ ./createdb2.sh
Enter password:zabbix と入力します
./conplesdb.sh
Enter password:zabbix と入力します

3つのスクリプトで、ZabbixDBの作製、初期データの流し込み、ヒストリデーブルの圧縮設定が完了します。

サービスの起動

個別にサービスの起動をおこなっても良いでしが、面倒なのでインスタンスを再起動して一括で起動します。

Zabbixの初期設定

再起動が完了したらhttp://アドレス>/zabbix にアクセスします。
[Next Step]をクリックします。

依存パッケージのバージョンを確認します。
問題無いはずなので[Next Step]をクリックします。

DBへの接続情報を入力して[Next Step]をクリックします。

フロントエンドに表示するサーバ名を入力して[Next Step]をクリックします。

設定情報を確認して[Next Step]をクリックします。

初期設定は完了で[Finish]をクリックします。

Username:Admin
Password:zabbix
を入力して[Sign In]をクリックします。
大文字小文字が区別されますので、注意してください。

初期状態では英語UIですので、日本語に変更します。
画面右上の人型アイコンをクリックします。

LanguageのプルダウンでJapanese(Ja_jp)を選択します。

[Update]をクリックします。

これで日本語でZabbixが利用可能になりました。(多くの機能追加があったため、一部日本語化されていないメニューもあります。)

まとめ

Zabbix 3.4 にはリリースノートにあるように、バルクメトリクスや値の前処理など多くの新機能が追加されています。
簡単に構築していろいろ試してみてください。