■Debian WheezyにZabbix(PostgreSQL版)を導入する
MySQL版は結構情報があるのでスルー。
$ cat /etc/debian_version
7.6
■まずはPostgreSQLサーバ、クライアント
$ sudo apt-get install -y postgresql postgresql-client
$ sudo -u postgres psql -c "select datname from pg_database;" 2>&1 |cat
datname
-----------
template1
template0
postgres
(3 行)
■PostgreSQLサーバのログを標準エラー出力からsyslogに変更
postgresql9.1のログをsyslogに出力。ただし、メッセージは英語で。
http://labunix.hateblo.jp/entry/20140715/1405356837
$ sudo grep log_dest /etc/postgresql/9.1/main/postgresql.conf
$ sudo grep log_dest /etc/postgresql/9.1/main/postgresql.conf
log_destination = 'syslog'
$ sudo /etc/init.d/postgresql restart
$ sudo grep postgres /var/log/syslog
Jul 20 10:29:32 vmwheezy kernel: [ 444.937120] postgres (6760): /proc/6760/oom_adj is deprecated, please use /proc/6760/oom_score_adj instead.
Jul 20 12:12:49 vmwheezy postgres[15593]: [1-1] 2014-07-20 12:12:49 JST LOG: ??????????? 2014-07-20 12:12:47 JST ????????????
Jul 20 12:12:49 vmwheezy postgres[15592]: [1-1] 2014-07-20 12:12:49 JST LOG: ????????????????????????
Jul 20 12:12:49 vmwheezy postgres[15596]: [1-1] 2014-07-20 12:12:49 JST LOG: ???????????????
Jul 20 12:12:49 vmwheezy postgres[15598]: [2-1] 2014-07-20 12:12:49 JST LOG: ????????????
■Apache2
$ sudo apt-get install -y apache2
$ w3m -no-proxy -dump http://localhost | head -1
It works!
■Zabbixサーバ、エージェントをインストール
$ echo 'deb http://packages.dotdeb.org wheezy all
deb-src http://packages.dotdeb.org wheezy all' | \
sudo tee -a /etc/apt/sources.list > /dev/null
$ curl -x http://${MYPROXY}:3128/ http://www.dotdeb.org/dotdeb.gpg | sudo apt-key add -
$ sudo apt-get update
$ apt-cache search zabbix | awk '{print $1}'
zabbix-agent
zabbix-frontend-php
zabbix-java-gateway
zabbix-proxy-mysql
zabbix-proxy-pgsql
zabbix-proxy-sqlite3
zabbix-server-mysql
zabbix-server-pgsql
$ sudo apt-get install -y zabbix-server-pgsql zabbix-frontend-php zabbix-agent
■追加の関連パッケージもインストール
$ sudo apt-get build-dep -y zabbix-server-pgsql zabbix-agent apache2 postgresql-9.1 postgresql-client
■Zabbixサーバの初期設定値
$ grep -v "^#\|^\$" /etc/zabbix/zabbix_server.conf
LogFile=/var/log/zabbix-server/zabbix_server.log
PidFile=/var/run/zabbix/zabbix_server.pid
DBName=zabbix
DBUser=zabbix
AlertScriptsPath=/etc/zabbix/alert.d/
FpingLocation=/usr/bin/fping
■上記を元にPostgreSQLにZabbixサーバの初期テーブルを作成する
$ sudo -u postgres createuser zabbix
新しいロールをスーパーユーザにしますか? (y/n)y
$ sudo -u postgres createdb zabbix
$ sudo -u zabbix createdb zabbix
$ echo "select datname,datacl from pg_database;" | sudo -u zabbix psql
datname | datacl
-----------+-------------------------------------
template1 | {=c/postgres,postgres=CTc/postgres}
template0 | {=c/postgres,postgres=CTc/postgres}
postgres |
zabbix |
(4 行)
$ for list in schema.sql.gz images.sql.gz data.sql.gz;do \
zcat /usr/share/zabbix-server-pgsql/${list} | sudo -u zabbix psql -d zabbix; \
done
$ echo "select * from pg_tables where tableowner='zabbix' order by tablename limit 5;" | sudo -u zabbix psql -d zabbix
schemaname | tablename | tableowner | tablespace | hasindexes | hasrules | hastriggers
------------+----------------------+------------+------------+------------+----------+-------------
public | acknowledges | zabbix | | t | f | t
public | actions | zabbix | | t | f | t
public | alerts | zabbix | | t | f | t
public | application_template | zabbix | | t | f | t
public | applications | zabbix | | t | f | t
(5 行)
$ echo "select count(*) from pg_tables where tableowner='zabbix';" | sudo -u zabbix psql -d zabbix
count
-------
108
(1 行)
■ZabbixサーバがPostgresqlに接続するためのパスワードを設定
$ echo "alter role zabbix with password 'zabbix';" | sudo -u zabbix psql
ALTER ROLE
$ grep DBPassword /etc/zabbix/zabbix_server.conf
$ grep ^[A-Z] /etc/default/zabbix-server
START=no
$ sudo sed -i s/"# DBPassword="/"DBPassword=zabbix"/ /etc/zabbix/zabbix_server.conf
$ sudo sed -i s/"START=no"/"START=yes"/ /etc/default/zabbix-server
■Zabbixエージェントの設定
※Zabbixサーバ側と合わせないといけない
$ grep "Timeout" /etc/zabbix/zabbix_server.conf
$ grep "^Server\|Timeout\|^Hostname" /etc/zabbix/zabbix_agentd.conf
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server
■フォントの設定
$ grep Deja /usr/share/zabbix/include/defines.inc.php
define('ZBX_GRAPH_FONT_NAME', 'DejaVuSans'); // font file name
define('ZBX_FONT_NAME', 'DejaVuSans');
$ sudo apt-get install -y ipafont*
$ ls -l /usr/share/zabbix/fonts/ /usr/share/fonts/opentype/ipafont-gothic/ipag*.ttf /usr/share/fonts/truetype/fonts-japanese-gothic.ttf
-rw-r--r-- 1 root root 6235344 4月 12 2011 /usr/share/fonts/opentype/ipafont-gothic/ipag.ttf
-rw-r--r-- 1 root root 6235712 4月 12 2011 /usr/share/fonts/opentype/ipafont-gothic/ipagp.ttf
lrwxrwxrwx 1 root root 43 7月 20 10:18 /usr/share/fonts/truetype/fonts-japanese-gothic.ttf -> /etc/alternatives/fonts-japanese-gothic.ttf
/usr/share/zabbix/fonts/:
合計 0
lrwxrwxrwx 1 root root 46 7月 19 15:44 DejaVuSans.ttf -> ../../fonts/truetype/ttf-dejavu/DejaVuSans.ttf
$ sudo ln -s /usr/share/fonts/opentype/ipafont-gothic/ipag.ttf /usr/share/zabbix/fonts/
$ sudo sed -i s/DejaVuSans/ipag/g /usr/share/zabbix/include/defines.inc.php
$ grep ipag /usr/share/zabbix/include/defines.inc.php
define('ZBX_GRAPH_FONT_NAME', 'ipag'); // font file name
define('ZBX_FONT_NAME', 'ipag');
■Zabbix Server/Agentを起動してみる
$ sudo /etc/init.d/zabbix-server restart
$ sudo /etc/init.d/zabbix-agent restart
$ sudo netstat -anp | grep 1005[01]
$ sudo netstat -anp | grep 1005[01]
tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 12693/zabbix_agentd
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 12580/zabbix_server
tcp 0 0 127.0.0.1:10051 127.0.0.1:35433 TIME_WAIT -
tcp 0 0 127.0.0.1:10051 127.0.0.1:35434 TIME_WAIT -
tcp6 0 0 :::10050 :::* LISTEN 12693/zabbix_agentd
tcp6 0 0 :::10051 :::* LISTEN 12580/zabbix_server
■PHPとZabbixと連携する設定
※DBポートの「0」はデフォルトの「5432」
$ cat /etc/zabbix/zabbix.config.php
$ cat /etc/zabbix/zabbix.config.php
<?php
global $DB;
$DB["TYPE"] = 'POSTGRESQL';
$DB["SERVER"] = 'localhost';
$DB["PORT"] = '0';
$DB["DATABASE"] = 'zabbix';
$DB["USER"] = 'zabbix';
$DB["PASSWORD"] = 'zabbix';
$ZBX_SERVER = 'localhost';
$ZBX_SERVER_PORT = '10051';
$ZBX_SERVER_NAME = 'zabbix';
$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;
?>
■Apache2とPHPを連携する設定
$ cat /etc/apache2/sites-available/zabbix
Alias /zabbix/ "/usr/share/zabbix/"
<Directory "/usr/share/zabbix/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
$ sudo a2ensite zabbix
Enabling site zabbix.
To activate the new configuration, you need to run:
service apache2 reload
$ sudo /etc/init.d/apache2 reload
[ ok ] Reloading web server config: apache2.
■ウイザードが保存するために手動で作成したファイルを退避しておく。
退避しないと「Configuration file "/etc/zabbix/zabbix.conf.php"」でFailとなり、
完了出来ない。
$ sudo mv /etc/zabbix/zabbix.config.php /etc
■ウイザードを進めると、以下がFailとなる。
PHP option post_max_size 8M 16M Fail
PHP option max_execution_time 30 300 Fail
PHP option max_input_time 60 300 Fail
PHP time zone unknown Fail
$ grep "post_max_size\|max_execution_time\|max_input_time\|timezone" /etc/php5/apache2/php.ini
; max_input_time
max_execution_time = 30
max_input_time = 60
post_max_size = 8M
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
;date.timezone =
■設定を変更し、apache2を再起動後にウイザードのRetryを実行する。
$ grep "post_max_size\|max_execution_time\|max_input_time\|timezone" /etc/php5/apache2/php.ini
; max_input_time
max_execution_time = 300
max_input_time = 300
post_max_size = 16M
; Defines the default timezone used by the date functions
; http://php.net/date.timezone
date.timezone = Asia/Tokyo
$ sudo /etc/init.d/apache2 restart
[ ok ] Restarting web server: apache2 ... waiting .
■profileからja_JPに変更、
監視データのスクリーンのグラフの文字化けなく日本語が表示されていればOK。
なお、syslogではpostgresqlサーバのログも
クライアントからの接続ログについては日本語で表示される。
$ sudo grep postgres /var/log/syslog | tail -3
Jul 20 12:31:06 vmwheezy postgres[24276]: [3-1] 2014-07-20 12:31:06 JST LOG: クライアント接続に想定外のEOFがありました
Jul 20 12:31:06 vmwheezy postgres[24261]: [2-1] 2014-07-20 12:31:06 JST LOG: クライアントからデータを受信できませんでした: 接続が相手からリセットされました
Jul 20 12:31:06 vmwheezy postgres[24261]: [3-1] 2014-07-20 12:31:06 JST LOG: クライアント接続に想定外のEOFがありました