CentOS7 de ZABBIX Server

Raspberry Pi3の温湿度監視をZabbixに取り込みグラフ化トリガによるアクションを実現する。

CentOS

CentOSは最小インストールを仮想ホストに行ってある Hyper-V OracleVMとも同様設定

公式のマニュアルがわかりやすい 🙂 
https://www.zabbix.com/documentation/3.2/manual/installation/install_from_packages

# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

Firewalldの停止と無効化(正規運用時は有効化設定する)

# systemctl stop firewalld
# systemctl disable firewalld
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
Removed symlink /etc/systemd/system/basic.target.wants/firewalld.service.

SElinux

# vi /etc/selinux/config
SELINUX=disabled

もしくは

# getsebool -a | grep zabbix
httpd_can_connect_zabbix --> off
zabbix_can_network --> off
# setsebool -P httpd_can_connect_zabbix on
# setsebool -P zabbix_can_network on
# getsebool -a | grep zabbix
httpd_can_connect_zabbix --> on
zabbix_can_network --> on

ホストの再起動をここで行っておく。忘れているとWebでzabbix-serverとの接続ができずにはまった。常識の範疇だと思うが、、、 😥 

MySQL関連
Yumリポジトリのダウンロード
http://dev.mysql.com/downloads/repo/yum/

centos7_mysql_repo

wgetでもOK

# yum install wget
# wget http://dev.mysql.com/get/mysql57-community-release-el7-8.noarch.rpm

リポジトリの追加インストール

# rpm -ivh mysql57-community-release-el7-8.noarch.rpm
警告: mysql57-community-release-el7-8.noarch.rpm: ヘッダー V3 DSA/SHA1 Signature、鍵 ID 5072e1f5: NOKEY
準備しています... ################################# [100%]
更新中 / インストール中...
1:mysql57-community-release-el7-8 ################################# [100%]

mysql関連インストールとインストール確認(更新5.7.14になる)

# yum install mysql-community-server
# rpm -qa | grep mysql
mysql57-community-release-el7-8.noarch
mysql-community-common-5.7.14-1.el7.x86_64
mysql-community-client-5.7.14-1.el7.x86_64
mysql-community-libs-compat-5.7.14-1.el7.x86_64
mysql-community-libs-5.7.14-1.el7.x86_64
mysql-community-server-5.7.14-1.el7.x86_64

mysqlデーモン起動

# systemctl start mysqld

mysql起動

# mysql -u root -p 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

ぉぉノー!!いつから仕様変わったの??? 😥 

参考にさせていただきました。
http://weblabo.oscasierra.net/mysql-57-init-setup/

ログファイルに初期パスワードの記載がある

# vi /var/log/mysqld.log
2016-08-05T23:08:52.632727Z 1 [Note] A temporary password is generated for root@localhost: qPTOIukVx9;v

パスワードの有効期間を無制限化(非推奨)
後述 mysql> uninstall plugin validate_password;でこの設定は消去されるので設定必要なし

#vi /etc/my.cnf
[mysqld]
character-set-server = utf8
default_password_lifetime = 0

パスワードポリシーを低くする(非推奨)

mysql> SET GLOBAL validate_password_policy=LOW;
Query OK, 0 rows affected (0.00 sec)

ALTER USER 'root'@'localhost' IDENTIFIED BY 'PASSWORD';
Query OK, 0 rows affected (0.00 sec)

mysql> select @@validate_password_policy;
+----------------------------+
| @@validate_password_policy |
+----------------------------+
| LOW |
+----------------------------+

結局のところ乱暴かも知れないがこのパスワード縛りを削除してしまう

mysql> uninstall plugin validate_password;
Query OK, 0 rows affected (0.00 sec)

ログイン 入れるかな

# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.7.13 MySQL Community Server (GPL)

Copyright (c) 2000, 2016, 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.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

 

ZABBIX
ZABBIXリポジトリをインストール
http://www.zabbix.com/download.php
centos7_zabbix_repo

wgetだと

# wget http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
# rpm -ivh http://repo.zabbix.com/zabbix/3.0/rhel/7/x86_64/zabbix-release-3.0-1.el7.noarch.rpm
# yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-web-japanese zabbix-get zabbix-agent zabbix-web-japanese zabbix-get

ZABBIX_MySQLデータベース関連設定

# mysql -u root -p
mysql> create database zabbix character set utf8 collate utf8_bin;
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix';
###mysql> SET PASSWORD FOR 'zabbix'@'localhost' = PASSWORD('zabbix');
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
| zabbix |
+--------------------+
5 rows in set (0.00 sec)

ZABBIX用初期DB作成 DB名を指定しないではまる 💡  -pのあとのzabbix

# cd /usr/share/doc/zabbix-server-mysql-3.0.3/
# zcat create.sql.gz | mysql -u zabbix -p zabbix
Enter password:

Edit database configuration in zabbix_server.conf
zabbix_server.confの編集

# vi /etc/zabbix/zabbix_server.conf
DBHost=localhost
DBName=zabbix
DBUser=zabbix
DBPassword=zabbix

中身は?? テーブルができていることを確認しておく

# mysql -u zabbix -p
mysql> use zabbix
mysql> show tables;

+----------------------------+
| Tables_in_zabbix |
+----------------------------+
| acknowledges |
| actions |
| alerts |
| application_discovery |
| application_prototype |
| application_template |
| applications |
| auditlog |
| auditlog_details |
| autoreg_host |
| conditions |
| config |
| dbversion |
| dchecks |
| dhosts |
| drules |
| dservices |
| escalations |
| events |
| expressions |
| functions |
| globalmacro |
| globalvars |
| graph_discovery |
| graph_theme |
| graphs |
| graphs_items |
| group_discovery |
| group_prototype |
| groups |
| history |
| history_log |
| history_str |
| history_text |
| history_uint |
| host_discovery |
| host_inventory |
| hostmacro |
| hosts |
| hosts_groups |
| hosts_templates |
| housekeeper |
| httpstep |
| httpstepitem |
| httptest |
| httptestitem |
| icon_map |
| icon_mapping |
| ids |
| images |
| interface |
| interface_discovery |
| item_application_prototype |
| item_condition |
| item_discovery |
| items |
| items_applications |
| maintenances |
| maintenances_groups |
| maintenances_hosts |
| maintenances_windows |
| mappings |
| media |
| media_type |
| opcommand |
| opcommand_grp |
| opcommand_hst |
| opconditions |
| operations |
| opgroup |
| opinventory |
| opmessage |
| opmessage_grp |
| opmessage_usr |
| optemplate |
| profiles |
| proxy_autoreg_host |
| proxy_dhistory |
| proxy_history |
| regexps |
| rights |
| screen_user |
| screen_usrgrp |
| screens |
| screens_items |
| scripts |
| service_alarms |
| services |
| services_links |
| services_times |
| sessions |
| slides |
| slideshow_user |
| slideshow_usrgrp |
| slideshows |
| sysmap_element_url |
| sysmap_url |
| sysmap_user |
| sysmap_usrgrp |
| sysmaps |
| sysmaps_elements |
| sysmaps_link_triggers |
| sysmaps_links |
| timeperiods |
| trends |
| trends_uint |
| trigger_depends |
| trigger_discovery |
| triggers |
| users |
| users_groups |
| usrgrp |
| valuemaps |
+----------------------------+
113 rows in set (0.00 sec)

Apache

# vi /etc/httpd/conf.d/zabbix.conf
# php_value date.timezone Europe/Riga
↓
php_value date.timezone Asia/Tokyo

Zabbixサーバの起動と自動起動設定

# systemctl start zabbix-server
# systemctl enable zabbix-server

Apache再起動

# systemctl restart httpd

動作確認用にAgentを起動しておく

# systemctl start zabbix-agent
# systemctl enable zabbix-agent

起動しているかチェック 稼働Versionの表示があれば成功

# zabbix_get -s 127.0.0.1 -k agent.version
3.0.4

各daemonの起動設定と再起動(念のため)

# systemctl enable mysqld
# systemctl enable httpd
# systemctl enable zabbix-server
# systemctl enable zabbix-agent
# systemctl restart mysqld
# systemctl restart httpd
# systemctl restart zabbix-server
# systemctl restart zabbix-agent

Webからのセットアップ

zabbix_quick_start01

要件が整っているか→All OK!!

zabbix_quick_start02

データベース設定 Postgres Oracle DB2なども大丈夫

zabbix_quick_start03

ホスト Port設定 Nameは空白

zabbix_quick_start04

セットアップのSummary

zabbix_quick_start05

セットアップ完了

zabbix_quick_start06

ログイン
Username:Admin
Password:zabbix

zabbix_sign_in01

初期は英文 設定は別に記す予定

zabbix_sign_in02

コメント