Amazon Linux2に対してZabbixサーバをインストールする。 ① OS側での設定 ② MariaDBのインストール・設定 ③ Zabbixのインストール・DB作成
yum -y update
timedatectl set-timezone Asia/Tokyo
localectl set-locale LANG=ja_JP.UTF-8
DB(MariaDB)のインストールおよび初期PW設定
Zabbixはデータベースが必要なので、MariaDBをインストールし、データベースを設定していきます。
yum -y install mariadb-server
systemctl start mariadb && sudo systemctl enable mariadb
systemctl status mariadb
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: active (running) since 月 2023-10-19 13:54:02 JST; 11s ago
Main PID: 2664 (mysqld_safe)
CGroup: /system.slice/mariadb.service
tq2664 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
mq2830 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log...
mysql_secure_installation
Set root password? [Y/n] →「Y」を入力 <br>
<br>New password:
<br>Re-enter new password:
<br> Password updated successfully!
<br> Reloading privilege tables..
<br> ... Success!
<br>Remove anonymous users? [Y/n] →「Y」
<br> ... Success!
<br>Disallow root login remotely? [Y/n] →「Y」
<br>... Success!
<br>Remove test database and access to it? [Y/n]
<br>- Dropping test database...
<br>... Success!
<br> - Removing privileges on test database...
<br>... Success!
<br>Reload privilege tables now? [Y/n] →「Y」
<br>... Success!
<br>Cleaning up...
<br>All done! If you've completed all of the above steps, your MariaDB
<br>installation should now be secure.
<br>Thanks for using MariaDB!
mysql -u root -p
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 5.5.68-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>quit
## Zabbixのレポジトリを追加
rpm -Uvh https://repo.zabbix.com/zabbix/5.0/rhel/7/x86_64/zabbix-release-5.0-1.el7.noarch.rpm
## リポジトリのお掃除
yum clean all
## Zabbixのパッケージ(サーバ機能とエージェント)をインストール
yum -y install zabbix-server-mysql zabbix-agent
## CentOSのSoftware Collections (SCL)をインストール
yum -y install http:https://mirror.centos.org/altarch/7/extras/aarch64/Packages/centos-release-scl-rh-2-3.el7.centos.noarch.rpm
## Zabbixのリポジトリ設定ファイルを修正
vim /etc/yum.repos.d/zabbix.repo
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch →変更なし
baseurl=http:https://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/frontend →変更なし
enabled=1 →[0]から[1]に変更
gpgcheck=1 →変更なし
gpgkey=file:https:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-XXXXX →変更なし
cat /etc/yum.repos.d/zabbix.repo
[zabbix]
name=Zabbix Official Repository - $basearch
baseurl=http:https://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:https:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-XXXXX
[zabbix-frontend]
name=Zabbix Official Repository frontend - $basearch
baseurl=http:https://repo.zabbix.com/zabbix/5.0/rhel/7/$basearch/frontend
enabled=1
gpgcheck=1
gpgkey=file:https:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX-XXXXXX
yum -y install zabbix-web-mysql-scl zabbix-apache-conf-scl zabbix-web-japanese
mysql -u root -p
Enter password:[任意で設定したPW]
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
MariaDB [(none)]> create user zabbix@localhost identified by '任意のPW';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost;
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> quit
DBの作成完了
zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix
vim /etc/zabbix/zabbix_server.conf
DBPassword='zabbix'
vim /etc/opt/rh/rh-php72/php-fpm.d/zabbix.conf
php_value[date.timezone]を Asia/Tokyoへ変更
php_value[date.timezone] = Asia/Tokyo
systemctl restart zabbix-server zabbix-agent
systemctl enable zabbix-server zabbix-agent
systemctl restart httpd
systemctl enable httpd
systemctl restart rh-php72-php-fpm
systemctl enable rh-php72-php-fpm
Amazon Linux2側(サーバ側)の設定が完了
Webブラウザーを立上げて、[http:https://"IPアドレス"/zabbix]にアクセス
ログインするためのデフォルトアカウントは以下
Username : Admin
Password : zabbix
ログイン後、Global viewから Zabbix server is running がYesになっていることを確認
Hosts > Zabbix server > Itemsをクリックする。Itemを作成していない場合は、Create Itemで新規Itemを作成する。
Type of informationは文字列(Character)を指定する。
Zabbix Serverをインストールする
yum install zabbix-sender
zabbix_sender -z 127.0.0.1 -s "Zabbix server" -k key -o 100
-k : key
-o : 送信する値
-z : ホスト名(IPアドレス)
-s : Zabbix ServerのName
Monitoring > Hosts > Zabbix Server > Latest Dataでデータが登録されていることを確認
バルクでループさせたデータを投げたい。
・シェルスクリプト
[root@bb-amazonlinux2 admin]# cat loop.sh
#/bin/sh
for i in {1..10} ; do
zabbix_sender -z 127.0.0.1 -s "test" -k test-key -o ${i}
done
・Python
[root@bb-amazonlinux2 admin]# cat loop.py
import subprocess
import random
import time
while 1:
value = random.randint(0, 100)
cmd = 'zabbix_sender -z 127.0.0.1 -s "Zabbix server" -k "key" -o ' + str(value)
print(cmd)
process = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
output, error = process.communicate()
print(output)
time.sleep(1)