我在 Amazon Linux 2 上安装了 Zabbix 4.0
太长不看
我在Amazon Linux 2上安装了Zabbix。我选择了即将正式发布的Zabbix 4.0,这不久以后就会发布。
当我在CentOS6或(旧) Amazon Linux上安装Zabbix时,需要安装许多附加软件包,但是当我使用了Zabbix的RHEL7软件包后,它很容易安装在Amazon Linux 2上。
Zabbix 4.0正式发布后,我计划修改本文以适应正式版本。
背景 – 背景资料
我之前在旧版的Amazon Linux上安装过Zabbix,但是在Amazon Linux 2上安装Zabbix的经验却没有,所以我决定尝试一下。
顺便说一下,我之前只是在Amazon Linux 2正式发布之前接触过一次,之后就没有接触过了,所以我也想试试看。
另外,考虑到 Zabbix 3.0 之后已经经过了大约2年半的 LTS 发布,目前仍以 Zabbix 4.0 的 Alpha 版为目标。(日期:2018/08/01)
前提条件 tí
目标读者
とりあえず Amazon Linux 2 に Zabbix 4.0 をインストールしてみたい人
Zabbix 4.0 の新機能について、サクッと自前で環境を構築して自分で試してみたい人
不适合的读者
Amazon Linux 2, Zabbix をガッツリチューニングしたい人
Zabbix 4.0 の新機能について情報を得たい人
版本
Zabbix: 4.0.0 alpha9
mariadb: 5.5.56
Amazon Linux 2 (amzn2-ami-hvm-2.0.20180622.1-x86_64-gp2)
环境
Zabbix は AWS EC2 上に構築する
Amazon Linux 2 を AMI に指定した EC2 を Launch 済み
SecurityGroup は、下記の通信を許可済み
インバウンド: TCP: 22, 80, 10051
この手順だと、 Zabbix の WebUI がデフォルトパスワードで起動するので、インターネットからアクセスできないように適切に処置してください。
アウトバウンド: すべて
(オプション: RDS 利用時のみ) RDS は起動し、 SecurityGroup 等を適切に設定済み
Zabbix的安装步骤
-
とりあえず Amazon Linux 2 に Zabbix 4.0 をインストールしてみたい人
Zabbix 4.0 の新機能について、サクッと自前で環境を構築して自分で試してみたい人
不适合的读者
Amazon Linux 2, Zabbix をガッツリチューニングしたい人
Zabbix 4.0 の新機能について情報を得たい人
版本
Zabbix: 4.0.0 alpha9
mariadb: 5.5.56
Amazon Linux 2 (amzn2-ami-hvm-2.0.20180622.1-x86_64-gp2)
环境
Zabbix は AWS EC2 上に構築する
Amazon Linux 2 を AMI に指定した EC2 を Launch 済み
SecurityGroup は、下記の通信を許可済み
インバウンド: TCP: 22, 80, 10051
この手順だと、 Zabbix の WebUI がデフォルトパスワードで起動するので、インターネットからアクセスできないように適切に処置してください。
アウトバウンド: すべて
(オプション: RDS 利用時のみ) RDS は起動し、 SecurityGroup 等を適切に設定済み
Zabbix的安装步骤
Zabbix 4.0 の新機能について情報を得たい人
-
Zabbix: 4.0.0 alpha9
mariadb: 5.5.56
Amazon Linux 2 (amzn2-ami-hvm-2.0.20180622.1-x86_64-gp2)
环境
Zabbix は AWS EC2 上に構築する
Amazon Linux 2 を AMI に指定した EC2 を Launch 済み
SecurityGroup は、下記の通信を許可済み
インバウンド: TCP: 22, 80, 10051
この手順だと、 Zabbix の WebUI がデフォルトパスワードで起動するので、インターネットからアクセスできないように適切に処置してください。
アウトバウンド: すべて
(オプション: RDS 利用時のみ) RDS は起動し、 SecurityGroup 等を適切に設定済み
Zabbix的安装步骤
Amazon Linux 2 を AMI に指定した EC2 を Launch 済み
SecurityGroup は、下記の通信を許可済み
インバウンド: TCP: 22, 80, 10051
この手順だと、 Zabbix の WebUI がデフォルトパスワードで起動するので、インターネットからアクセスできないように適切に処置してください。
アウトバウンド: すべて
(オプション: RDS 利用時のみ) RDS は起動し、 SecurityGroup 等を適切に設定済み
让我们立即开始安装吧。
我们将按照Zabbix官方网站的安装步骤来进行。
安装软件包
添加 GPG 密钥
导入Zabbix存储库的GPG密钥。
# rpm -import http://repo.zabbix.com/RPM-GPG-KEY-ZABBIX
添加存储库
我们将添加ZABBIX SIA的官方软件源。
# rpm -i https://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm
安装 Zabbix 相关软件包
安装Zabbix相关软件包。
# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-web-japanese
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Resolving Dependencies
--> Running transaction check
(snip)
Complete!
数据库设置
在搭建Zabbix用的实例中,如果选择与MariaDB(MySQL)共存,则进行MariaDB(MySQL)的设置;如果选择使用RDS,则进行RDS(MySQL)的连接准备。
MariaDB(MySQL)安装配置
如果不使用RDS,可以将MariaDB与Zabbix的EC2实例一起使用。
当然,也可以创建专用于MariaDB的EC2实例,并与之进行协作,但是我们不在这里讨论这样的事情,因为使用RDS会更加方便。
MariaDB 相关软件包安装。
首先需要安装必要的软件包。
# yum install mariadb-server mariadb
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Resolving Dependencies
--> Running transaction check
(snip)
Complete!
MariaDB 启动和自动启动设置
安装完MariaDB后,启动MariaDB。
与(旧) Amazon Linux不同,Amazon Linux 2使用的是Systemd而不是init/Upstart来启动系统。
因此,我们使用systemctl命令而不是service命令来启动服务。
# systemctl start mariadb
# systemctl status mariadb
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
Active: active (running) since Mon 2018-07-30 14:25:00 UTC; 4s ago
Process: 3864 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
Process: 3785 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
Main PID: 3863 (mysqld_safe)
CGroup: /system.slice/mariadb.service
├─3863 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
└─4026 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/mariadb.log --pid-file=/var/run/mariadb/ma...
Jul 30 14:24:58 ip-172-31-38-131.us-east-2.compute.internal mariadb-prepare-db-dir[3785]: MySQL manual for more instructions.
Jul 30 14:24:58 ip-172-31-38-131.us-east-2.compute.internal mariadb-prepare-db-dir[3785]: Please report any problems at http://mariadb.org/jira
Jul 30 14:24:58 ip-172-31-38-131.us-east-2.compute.internal mariadb-prepare-db-dir[3785]: The latest information about MariaDB is available at http://mariadb.org/.
Jul 30 14:24:58 ip-172-31-38-131.us-east-2.compute.internal mariadb-prepare-db-dir[3785]: You can find additional information about the MySQL part at:
Jul 30 14:24:58 ip-172-31-38-131.us-east-2.compute.internal mariadb-prepare-db-dir[3785]: http://dev.mysql.com
Jul 30 14:24:58 ip-172-31-38-131.us-east-2.compute.internal mariadb-prepare-db-dir[3785]: Consider joining MariaDB's strong and vibrant community:
Jul 30 14:24:58 ip-172-31-38-131.us-east-2.compute.internal mariadb-prepare-db-dir[3785]: https://mariadb.org/get-involved/
Jul 30 14:24:58 ip-172-31-38-131.us-east-2.compute.internal mysqld_safe[3863]: 180730 14:24:58 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Jul 30 14:24:58 ip-172-31-38-131.us-east-2.compute.internal mysqld_safe[3863]: 180730 14:24:58 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Jul 30 14:25:00 ip-172-31-38-131.us-east-2.compute.internal systemd[1]: Started MariaDB database server.
# systemctl enable mariadb
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.
MariaDB的初始设置
一旦启动完成后,将执行MariaDB的初始设置。因为在MySQL-5.7中有人提到mysql_secure_installation的自动化变得更容易了- Qiita,所以我也想减少交互输入的部分,但可惜版本是5.5,无法减少…
以下是互动输入的内容。
-
Enter current password for root (enter for none): では何も入力せずに Enter キーを押下します。
※ MariaDB をセットアップしたばかりで、まだ root のパスワードを設定していないので。
Set root password? [Y/n] は y を入力します。
New password: と Re-enter new password: には MariaDB の root に設定するパスワードを入力します。
以降、 ~? [Y/n] と聞かれるものは y を入力(もしくは Enter キーを押下)します。
# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, 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 MariaDB
root user without the proper authorisation.
Set root password? [Y/n]
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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]
... 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]
... Success!
By default, MariaDB 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]
- Dropping test database...
... Success!
- 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]
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
当完成到这一步时,请继续准备Zabbix数据库。
准备连接到RDS(MySQL)
如果在AWS上构建Zabbix,使用RDS作为完全托管的数据库服务是一个好主意。通过RDS,可以轻松获得高可用性、扩展性和磁盘扩展等选项,这些对于将其用作Zabbix的数据库也是非常有价值的。
另外,在本文中假定RDS已经启动,因此不会继续解释RDS的创建和启动等内容。
安装MariaDB相关软件包。
首先,需要安装必要的软件包。
# yum install mariadb
Loaded plugins: extras_suggestions, langpacks, priorities, update-motd
Resolving Dependencies
--> Running transaction check
(snip)
Complete!
完成这一步之后,请继续进行Zabbix数据库准备。
(如果省略了创建RDS,就没有太多东西需要写了…。)
准备Zabbix数据库。
完成MariaDB的初始设置后,我们将创建Zabbix所使用的数据库(zabbix)和MariaDB上的用户(zabbix)。
对于MariaDB,有以下两个SQL语句需要执行。
zabbix データベースを作成する
create database zabbix character set utf8 collate utf8_bin;
zabbix ユーザを作成する
grant all privileges on zabbix.* to zabbix@localhost identified by ‘password’;
ここで password は MariaDB 上の zabbix ユーザに対して設定するパスワードになります。
任意のパスワードに置き換えてください。
请用下列方法执行上述两个 SQL 语句。
请使用以下密码进行输入。
-
MariaDB 利用時: mysql_secure_installation コマンド実行時に指定した MariaDB 上の root ユーザのパスワード
RDS 利用時: RDS 作成時に指定した RDS 上の root ユーザのパスワード
# mysql -uroot -p # RDS 利用時は -h オプションで RDS のエンドポイント(FQDN)を指定する事。
Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.01 sec)
MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'password';
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> quit;
Bye
请使用之前在创建 MariaDB 上的 zabbix 用户时指定的密码进行输入。将表定义等导入到上述创建的数据库中。
# zcat /usr/share/doc/zabbix-server-mysql*/create.sql.gz | mysql -uzabbix -p zabbix # RDS 利用時は -h オプションで RDS のエンドポイント(FQDN)を指定する事。
Enter password:
当mysql命令顺利完成时,将显示”OK”。
Zabbix的基础设置
Zabbix守护进程配置
为了让Zabbix能够访问数据库,需要编辑Zabbix的配置文件。
# cp /etc/zabbix/zabbix_server.conf{,.org}
# vim /etc/zabbix/zabbix_server.conf
请在DBPassword中指定MariaDB或RDS上的zabbix用户密码。
另外,如果使用RDS,请在DBHost中指定RDS的端点(FQDN)。
应该如下所示:diff
# diff -u /etc/zabbix/zabbix_server.conf{.org,}
--- /etc/zabbix/zabbix_server.conf.org 2018-07-30 14:32:10.593841916 +0000
+++ /etc/zabbix/zabbix_server.conf 2018-07-30 14:32:15.309899259 +0000
@@ -124,6 +124,8 @@
# Default:
# DBPassword=
+DBPassword=password
+
### Option: DBSocket
# Path to MySQL socket.
#
Zabbix 網頁介面 設定
设置 WebUI 的时区。
如果在日本,通常会选择 UTC 或 Asia/Tokyo。
# cp /etc/httpd/conf.d/zabbix.conf{,.org}
# vim /etc/httpd/conf.d/zabbix.conf
# diff /etc/httpd/conf.d/zabbix.conf{.org,}
--- /etc/httpd/conf.d/zabbix.conf.org 2018-07-30 14:34:20.339419518 +0000
+++ /etc/httpd/conf.d/zabbix.conf 2018-07-30 14:34:46.451737023 +0000
@@ -16,7 +16,7 @@
php_value upload_max_filesize 2M
php_value max_input_time 300
php_value always_populate_raw_post_data -1
- # php_value date.timezone Europe/Riga
+ php_value date.timezone UTC
</IfModule>
</Directory>
当所有设置完成后,重新启动与Zabbix相关的各个守护进程。
# systemctl restart zabbix-server zabbix-agent httpd
# systemctl enable zabbix-server zabbix-agent httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-server.service to /usr/lib/systemd/system/zabbix-server.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
到目前为止,基本设置已经完成。接下来还需要进行一些 WebUI 的设置。
網頁使用者介面設定
WebUI的设置可以通过使用WebUI自身以向导形式进行,也可以通过手动创建配置文件进行。
如果手动创建设置文件的话
如果你正在进行资材管理或者想要减少WebUI的操作,我建议你手动创建WebUI的配置文件。
创建名为 /etc/zabbix/web/zabbix.conf.php 的文件。
文件内容如下:
<?php
// Zabbix GUI configuration file.
global $DB;
$DB['TYPE'] = 'MYSQL';
$DB['SERVER'] = 'localhost';
$DB['PORT'] = '0';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'zabbix';
$DB['PASSWORD'] = 'password';
// Schema name. Used for IBM DB2 and PostgreSQL.
$DB['SCHEMA'] = '';
$ZBX_SERVER = 'localhost';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = 'MyZabbix!';
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
如果按照本文的内容进行设置,每个参数将如下表所示。
RDS のエンドポイント(FQDN)
空文字列
空文字列
任意の名前
任意の名前
主人,权限的设置如下。
# chown apache:apache /etc/zabbix/web/zabbix.conf.php
# chmod 644 /etc/zabbix/web/zabbix.conf.php
# ls -l /etc/zabbix/web/zabbix.conf.php
-rw-r--r-- 1 apache apache 426 Jul 30 14:41 /etc/zabbix/web/zabbix.conf.php
现在WebUI的设置已经完成,请进行操作确认。
要从WebUI进行设置的话
如果通过WebUI进行设置,可以访问 http://(Zabbix的IP或FQDN)/zabbix/ 。
当您看到如下的安装界面时,请点击“下一步”按钮。


RDS のエンドポイント(FQDN)
请在输入完所有参数后点击“下一步”按钮。


以上就是WebUI的设置已经完成了。
确认动作
那么现在让我们实际登录WebUI,并确认其操作。请访问http://(Zabbix的IP或FQDN)/zabbix/。
会显示以下类型的登录界面。


如果在上图右下角的 System Information 中,Zabbix 服务器正在运行,并且显示为 Yes,那就说明是正常的。
以上是 Zabbix 4.0 安装完毕。
接下来可以随意操作或做任何您想做的。
结束了。
当然,在WebUI上进行设置时,也会生成该文件,因此也可以对通过WebUI生成的设置文件进行资料管理。 ↩