Zabbixをインストールしてみる(失敗記録)

客先でZabbixを使うらしいので、操作感を確かめたくてインストールした。
Zabbixの構築案件ではない。

参考→http://qiita.com/mken/items/0e2de86ddc96c4c3ddce
PHPは5.6、MySQLは5.7にアップデートしたはず(※これログ見ながら書いてるからうろ覚え)
MySQLをインストールしたので、Zabbix用のデータベースを作成するところから。

mysql> create database zabbix character set utf8 collate utf8 bin;
ERROR 1273 (HY000): Unknown collation: 'utf8'

文字コードの設定に問題があるようなので、/etc/my.cnfを編集。

[mysqld]
character_set_server=utf8
init_connect="SET NAMES utf8"
[mysql]
character_set_server=utf8

編集が終わったら、mysqldを再起動して、もう1回上記のcreateコマンドを入力してZabbix用のデータベースを作る。
Zabbixをソースから構築するために、以下の手順でソース(gzファイル)を入手。

# yum install wget
# cd /usr/local/src
# wget https://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Stable/3.0.0/zabbix-3.0.0.tar.gz
# tar xfz zabbix-3.0.0.tar.gz

解凍したzabbix-3.0.0の中身はこんな感じ。

[root@localhost zabbix-3.0.0]# ls
aclocal.m4 build conf configure database include m4 man NEWS upgrades
AUTHORS ChangeLog config.guess configure.ac depcomp INSTALL Makefile.am misc README
bin compile config.sub COPYING frontends install-sh Makefile.in missing src

mysql> grant all privileges on zabbix .* to zabbix@localhost identified by 'passoword';
Query OK, 0 rows affected (0.00 sec)

grant all privileges onでGRANT権限というものを追加。他のユーザに対して権限を付与することができる権限らしい。これをzabbixデータベースに対し設定。
上記のコマンドは、zabbbixユーザにlocalhost でのアクセスを許可し、zabbbixに対してzabbbixのデータベースに関する全ての操作権限を与えるという意味になるそうです(参考→http://linux.kororo.jp/cont/server/mysql_user.php
解凍したzabbix-3.0.0ディレクトリにcdで移動して、スキーマを追加する。

# cd /usr/local/src/zabbix-3.0.0
# mysql -uroot zabbix < database/mysql/schema.sql
# mysql -uroot zabbix < database/mysql/images.sql
# mysql -uroot zabbix < database/mysql/data.sql<
Linuxにログインする用のZabbixユーザを作成してあげる。
※何かの表紙で既に作られていることもあるみたいだけど、それはそれでまぁ。

# groupadd zabbix
# useradd -g zabbix zabbix

ここまで出来たらサーバを再起動。
開発環境をインストールする。

# yum install gcc mysql-devel net-snmp-devel libcurl-devel libxml2-devel

コンパイルする。

# cd /usr/local/src/zabbix-3.0.0
# ls
aclocal.m4 build conf configure database include m4 man NEWS upgrades
AUTHORS ChangeLog config.guess configure.ac depcomp INSTALL Makefile.am misc README
bin compile config.sub COPYING frontends install-sh Makefile.in missing src
# ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
# make install

インストールが完了したら、コンフィグに色々追記。

# vi /usr/local/etc/zabbix_server.conf
DBPassword=password ←上記の「grant all privileges on」の入力の時に入力したパスワードと同じものを入力する。

$ sed -i -e "s/memory_limit = 128M/memory_limit = 256M/g" /etc/php.ini
$ sed -i -e "s/post_max_size = 8M/post_max_size = 16M/g" /etc/php.ini
$ sed -i -e "s/max_execution_time = 30/max_execution_time = 300/g" /etc/php.ini
$ sed -i -e "s/max_input_time = 60/max_input_time = 300/g" /etc/php.ini
$ sed -i -e "s/;date.timezone =/date.timezone = Asia\/Tokyo/g" /etc/php.ini
$ sed -i -e "s/;always_populate_raw_post_data = On/always_populate_raw_post_data = -1/g" /etc/php.ini

上記の追記後は、Apacheプロセスを再起動する。
↓フロントエンドのせ設定

# mkdir /var/www/html/zabbix
# cd /usr/local/src/zabbix-3.0.0
# cp -a ./frontends/php/* /var/www/html/zabbix
# cd /var/www/html
# chown -R apache:apache zabbix

ZabbixディレクトリにApacheが色々できるようにしてる感じ?Webからアクセスするからね。
あとはiptablesの設定をしたり、

# vi /etc/sysconfig/iptables

  • A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT   ←追加

# service iptables restart

SELINUXをdisabledにしたり、

# vi /etc/sysconfig/selinux
SELINUX=disabled
# setenforce 0

とやって、WebからZabbixにアクセス。
http://Zabbixを入れたサーバのIPアドレス/zabbix
でアクセスできませんでした。httpdもzabbix-serverプロセスも起動してるのに。
/var/log/zabbix/zabbix_server.logを確認すると、

[Z3001] connection to database 'zabbix' failed: [1045] Access denied for user 'zabbix'@'local host' (using password: NO)

このエラーの内容は、

/etc/zabbix/zabbix_server.confのDBPasswordに設定したパスワードがMySQLのzabbixデータベースに設定したパスワードと同じかどうかを確認します。間違っているようであれば正しいパスワードを設定します。

ということらしい。
よく見たら/etc/zabbix/zabbix_server.confを編集し忘れていたので、DBPassword=passwordを追記。で、各プロセスを再起動。
しかし今度は別なログが吐かれてWebにログインできず。次のログは、

[Z3005] query failed: [1054] Unknown column 'i.lastclock' in 'where clause' [select distinct t.triggerid,t.type,t.value,t.error from hosts h,items i,functions f,triggers t where h.hostid=i.hostid and i.itemid=f.it emid and i.lastclock is not null and f.triggerid=t.triggerid and h.status in (0) and i.status in (0) and i.type not in ( 2) and i.key_ not in ('status','zabbix[log]') and t.status in (0) and t.triggerid between 000000000000000 and 0999999999 99999]

↑こういうログが大量に出てて、シングルクォーテーションでくくってあるところはいずれも違う。だからカラムどのどこか1箇所がおかしいという訳でもないと思う。
という憶測しかできないぐらい情報がなく、原因は不明。Zabbix.jpのこの内容を見ると、入れたZabbixのバージョンとMySQLのバージョンの相性が悪かったのかな、という感じ。
もはや自分の手ではどうしようもないエラーが出ていると判断したので、ZabbixもMySQLも全部アンインストールしますた。
# yum remove zabbix-server-mysql
# yum remove zabbix-frontend-php
# yum erase mysql57-community-release.noarch mysql57-community-release.noarch(あとひたすらMySQL関係のパッケージを消した)
※/usr/lib/mysqlディレクトリや、各地のzabbix関係のディレクトリもrm -rfで消す。じゃないと4データが残って、再インストールした時におかしくなることがある。
全消ししたら、再インストール開始。