この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。
はじめに
こんにちは、城内です。
今回は初級者向けの内容ですが、AWS上でのZabbixの構築をやってみたいと思います。
Zabbixに関する記事は、過去にもたくさんありますので、併せてこちらもご覧ください。
全体構成
今回は以下のようなシンプルな構成を構築します。
セットアップ
RDSの作成
まず、Zabbix用のデータベースとして、RDSのMySQLを作成します。
以下のような感じで作成します。
特に細かいパラメータ等は設定していなく、プライべートサブネットに配置されるようにし、セキュリティグループも特に絞ることなくデフォルトのものを使用しています。
Zabbix Serverの構築
次に、ZabbixのServerを構築していきます。
EC2の作成
今回、EC2はAWS MarketplaceからCentOS 7を使用します。
こちらも細かい設定はせず、セキュリティグループもデフォルトとローカル環境からのSSHとHTTPだけを許可しています。
しっかり設定したい場合は、MySQLとは3306ポート、Zabbix Agentサーバとは10050と10051ポートだけを許可するという感じで設定してみてください。
タイムゾーンの設定
作成したEC2にSSHでログインします。ログインユーザは「centos」になりますので注意してください。
CentOS 7でのタイムゾーンの設定コマンドは以下になります。
$ timedatectl set-timezone Asia/Tokyo
SELinuxの無効化
SELinuxについては、いろいろと引っかかるところがあるようですので、今回はとりあえず無効化してしまいます。
細かく制御することもできるようですので、無効化が気になる方は以下を参照してみてください。
$ cp -p /etc/selinux/config /etc/selinux/config.org
$ vi /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
...
#SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
...
$ reboot
Zabbix Serverのインストール
Zabbix Serverのインストールを行いますので、まずはZabbix 3.2のyumリポジトリを登録します。
$ rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
Retrieving http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
warning: /var/tmp/rpm-tmp.MMKsX9: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-release-3.2-1.el7 ################################# [100%]
次に、必要なパッケージをインストールします。
- zabbix-server-mysql
- zabbix-web-mysql
- zabbix-web-japanese
- zabbix-get(Agentとの疎通確認のため)
$ yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-web-japanese zabbix-get
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
zabbix | 951 B 00:00:00
zabbix-non-supported | 951 B 00:00:00
(1/4): base/7/x86_64/group_gz | 155 kB 00:00:00
(2/4): extras/7/x86_64/primary_db | 122 kB 00:00:00
...
Dependency Installed:
OpenIPMI-libs.x86_64 0:2.0.19-15.el7 OpenIPMI-modalias.x86_64 0:2.0.19-15.el7 apr.x86_64 0:1.4.8-3.el7 apr-util.x86_64 0:1.5.2-6.el7
dejavu-fonts-common.noarch 0:2.33-6.el7 dejavu-sans-fonts.noarch 0:2.33-6.el7 fontpackages-filesystem.noarch 0:1.44-8.el7 fping.x86_64 0:3.10-1.el7
httpd.x86_64 0:2.4.6-45.el7.centos httpd-tools.x86_64 0:2.4.6-45.el7.centos iksemel.x86_64 0:1.4-2.el7.centos libX11.x86_64 0:1.6.3-3.el7
libX11-common.noarch 0:1.6.3-3.el7 libXau.x86_64 0:1.0.8-2.1.el7 libXpm.x86_64 0:3.5.11-3.el7 libpng.x86_64 2:1.5.13-7.el7_2
libtool-ltdl.x86_64 0:2.4.2-21.el7_2 libxcb.x86_64 0:1.11-4.el7 libxslt.x86_64 0:1.1.28-5.el7 libzip.x86_64 0:0.10.1-8.el7
mailcap.noarch 0:2.1.41-2.el7 net-snmp-libs.x86_64 1:5.7.2-24.el7_2.1 php.x86_64 0:5.4.16-42.el7 php-bcmath.x86_64 0:5.4.16-42.el7
php-cli.x86_64 0:5.4.16-42.el7 php-common.x86_64 0:5.4.16-42.el7 php-gd.x86_64 0:5.4.16-42.el7 php-ldap.x86_64 0:5.4.16-42.el7
php-mbstring.x86_64 0:5.4.16-42.el7 php-mysql.x86_64 0:5.4.16-42.el7 php-pdo.x86_64 0:5.4.16-42.el7 php-xml.x86_64 0:5.4.16-42.el7
t1lib.x86_64 0:5.1.2-14.el7 unixODBC.x86_64 0:2.3.1-11.el7 vlgothic-p-fonts.noarch 0:20130607-2.el7 zabbix-web.noarch 0:3.2.3-1.el7
Complete!
yumで不意にアップデートされてしまわないように、Zabbixのリポジトリを無効化しておきます。
$ vi /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://repo.zabbix.com/zabbix/3.2/rhel/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
データベースとユーザの作成
MySQLにアクセスして、Zabbixで使用するデータベースとユーザを作成します。
$ yum -y install mysql
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: ftp.riken.jp
* extras: ftp.riken.jp
* updates: ftp.riken.jp
Resolving Dependencies
--> Running transaction check
---> Package mariadb.x86_64 1:5.5.52-1.el7 will be installed
--> Processing Dependency: mariadb-libs(x86-64) = 1:5.5.52-1.el7 for package: 1:mariadb-5.5.52-1.el7.x86_64
...
Dependency Updated:
mariadb-libs.x86_64 1:5.5.52-1.el7
Complete!
$ mysql -u dbadmin -h zabbixdb.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 19
Server version: 5.6.27 MySQL Community Server (GPL)
Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
MySQL [(none)]> grant all on zabbix.* to zabbix@`%` identified by '<パスワード>';
Query OK, 0 rows affected (0.00 sec)
MySQL [(none)]> quit
Bye
$ zcat /usr/share/doc/zabbix-server-mysql-3.2.3/create.sql.gz | mysql -u dbadmin -h zabbixdb.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com -p zabbix
Enter password:
Zabbixの初期設定
Zabbix Serverを起動する前に、設定ファイルにデータベースの情報を追記します。
$ cp -p /etc/zabbix/zabbix_server.conf /etc/zabbix/zabbix_server.conf.org
$ vi /etc/zabbix/zabbix_server.conf
# This is a configuration file for Zabbix server daemon
# To get more information about Zabbix, visit http://www.zabbix.com
############ GENERAL PARAMETERS #################
### Option: ListenPort
# Listen port for trapper.
...
### Option: DBHost
# Database host name.
# If set to localhost, socket is used for MySQL.
# If set to empty string, socket is used for PostgreSQL.
#
# Mandatory: no
# Default:
# DBHost=localhost
DBHost=zabbixdb.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com
...
### Option: DBPassword
# Database password. Ignored for SQLite.
# Comment this line if no password is used.
#
# Mandatory: no
# Default:
# DBPassword=
DBPassword=<パスワード>
...
Zabbix Serverを起動し、自動起動に設定します。
$ systemctl start zabbix-server
$ systemctl status zabbix-server
● zabbix-server.service - Zabbix Server
Loaded: loaded (/usr/lib/systemd/system/zabbix-server.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2017-02-28 22:37:34 JST; 1min 2s ago
Main PID: 2355 (zabbix_server)
CGroup: /system.slice/zabbix-server.service
mq2355 /usr/sbin/zabbix_server -c /etc/zabbix/zabbix_server.conf
Feb 28 22:37:34 ip-172-31-25-227.ap-northeast-1.compute.internal systemd[1]: Starting Zabbix Server...
Feb 28 22:37:34 ip-172-31-25-227.ap-northeast-1.compute.internal systemd[1]: PID file /run/zabbix/zabbix_server.pid not readable (yet?) after start.
Feb 28 22:37:34 ip-172-31-25-227.ap-northeast-1.compute.internal systemd[1]: Started Zabbix Server.
$ systemctl enable zabbix-server
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
$ systemctl is-enabled zabbix-server
enabled
httpdの設定ファイルでタイムゾーンを設定します。
$ vi /etc/httpd/conf.d/zabbix.conf
#
# Zabbix monitoring system php web frontend
#
Alias /zabbix /usr/share/zabbix
...
# php_value date.timezone Europe/Riga
php_value date.timezone Asia/Tokyo
</IfModule>
</Directory>
...
$ systemctl restart httpd
Webインターフェースにアクセスし、初期設定を行います。
http://ec2-xx-xx-xx-xx.ap-northeast-1.compute.amazonaws.com/zabbix/
Zabbix Agentの構築
最後に、Zabbix Agentの構築ですが、OS周りの初期セットアップはZabbix Serverと同じなので省略します。
タイムゾーンの設定
先ほどの手順を参考にしてください。
SELinuxの無効化
先ほどの手順を参考にしてください。
Zabbix Agentのインストール
Zabbix Agentのインストールは、入れるパッケージが違うだけで、Zabbix Serverの手順と同じです。
- zabbix-agent
$ rpm -ivh http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
Retrieving http://repo.zabbix.com/zabbix/3.2/rhel/7/x86_64/zabbix-release-3.2-1.el7.noarch.rpm
warning: /var/tmp/rpm-tmp.MMKsX9: Header V4 RSA/SHA512 Signature, key ID a14fe591: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:zabbix-release-3.2-1.el7 ################################# [100%]
$ yum -y install zabbix-agent
Loaded plugins: fastestmirror
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
zabbix | 951 B 00:00:00
zabbix-non-supported | 951 B 00:00:00
(1/4): extras/7/x86_64/primary_db | 122 kB 00:00:00
(2/4): base/7/x86_64/group_gz | 155 kB 00:00:00
...
Installed:
zabbix-agent.x86_64 0:3.2.3-1.el7
Complete!
リポジトリの無効化も実施しておきます。
$ vi /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http://repo.zabbix.com/zabbix/3.2/rhel/7/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-A14FE591
[zabbix-non-supported]
name=Zabbix Official Repository non-supported - $basearch
baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
gpgcheck=1
Zabbixの初期設定
Zabbix Agentの設定ファイルには、Zabbix Serverの情報を追記します。
$ cp -p /etc/zabbix/zabbix_agentd.conf /etc/zabbix/zabbix_agentd.conf.org
$ vi /etc/zabbix/zabbix_agentd.conf
# This is a configuration file for Zabbix agent daemon (Unix)
# To get more information about Zabbix, visit http://www.zabbix.com
############ GENERAL PARAMETERS #################
### Option: PidFile
# Name of PID file.
...
### Option: Server
# List of comma delimited IP addresses (or hostnames) of Zabbix servers.
# Incoming connections will be accepted only from the hosts listed here.
# If IPv6 support is enabled then '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' are treated equally.
#
# Mandatory: no
# Default:
# Server=
Server=<Zabbix ServerのIPアドレス>
...
### Option: ServerActive
# List of comma delimited IP:port (or hostname:port) pairs of Zabbix servers for active checks.
# If port is not specified, default port is used.
# IPv6 addresses must be enclosed in square brackets if port for that host is specified.
# If port is not specified, square brackets for IPv6 addresses are optional.
# If this parameter is not specified, active checks are disabled.
# Example: ServerActive=127.0.0.1:20051,zabbix.domain,[::1]:30051,::1,[12fc::1]
#
# Mandatory: no
# Default:
# ServerActive=
ServerActive=<Zabbix ServerのIPアドレス>
...
Zabbix Agentを起動し、自動起動に設定します。
$ systemctl start zabbix-agent
$ systemctl status zabbix-agent
● zabbix-agent.service - Zabbix Agent
Loaded: loaded (/usr/lib/systemd/system/zabbix-agent.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2017-03-01 00:19:10 JST; 3s ago
Process: 2122 ExecStart=/usr/sbin/zabbix_agentd -c $CONFFILE (code=exited, status=0/SUCCESS)
Main PID: 2124 (zabbix_agentd)
CGroup: /system.slice/zabbix-agent.service
tq2124 /usr/sbin/zabbix_agentd -c /etc/zabbix/zabbix_agentd.conf
tq2125 /usr/sbin/zabbix_agentd: collector [idle 1 sec]
tq2126 /usr/sbin/zabbix_agentd: listener #1 [waiting for connection]
tq2127 /usr/sbin/zabbix_agentd: listener #2 [waiting for connection]
tq2128 /usr/sbin/zabbix_agentd: listener #3 [waiting for connection]
mq2129 /usr/sbin/zabbix_agentd: active checks #1 [idle 1 sec]
Mar 01 00:19:10 ip-172-31-11-91.ap-northeast-1.compute.internal systemd[1]: Starting Zabbix Agent...
Mar 01 00:19:10 ip-172-31-11-91.ap-northeast-1.compute.internal systemd[1]: PID file /run/zabbix/zabbix_agentd.pid not readable (yet?) after start.
Mar 01 00:19:10 ip-172-31-11-91.ap-northeast-1.compute.internal systemd[1]: Started Zabbix Agent.
$ systemctl enable zabbix-agent
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
$ systemctl is-enabled zabbix-agent
enabled
動作確認
では、動作確認をしてみたいと思います。
まずは、Zabbix Server上からzabbix_getコマンドで疎通確認をしてみます。
バージョン情報が表示されればOKです。
$ zabbix_get -s <Zabbix AgentのIPアドレス> -k agent.version
3.2.3
Webインターフェイスからも、デフォルトのテンプレートを適用して挙動を確認してみます。
初期ユーザは「Admin / zabbix」です。
ホストの追加手順は以下を参照してください。
「Template OS Linux」のテンプレートを適用してみました。
サーバの情報がちゃんと取得できています。
さいごに
今回は本当に初歩の初歩として、簡単な構築をやってみました。
セットアップは意外と簡単にできましたが、Zabbix自体はとても多機能そうなので、少しずつ触って覚えていけたらなと思いました。