Help us understand the problem. What is going on with this article?

zabbix 3.0 (実質2.5.0)の自動インストールへの誘い

More than 3 years have passed since last update.

zabbix 3 の正式リリースが迫ってきました

その構築手順について、どこまでshell芸で試せるかやってみた所、ほぼ自動化が出来たので公開します

以下構成

CentOS6.7
php 5.6.18
Apache 2.2.27
PostgreSQL 9.5.1

注意事項

※1 phpやPostgreSQL等も基本的な所だけ設定を弄ってます。動作環境にあわせて適宜変更して下さい。
※2 途中にあるユーザzabbixに関するOS,PgSQLに対するパスワード"XXXXXXXXXXXX"はご自身の環境にあわせて変更する事を強くお勧めします。このままサーバで実行し、セキュリティホールとなっても責任は負いかねます。

ソースコードのコピペ利用はダメ!絶対!!

以下の記述を全てshに書き込みます

/root/setup-zabbix.sh
# OSの最新パッチ適用
yum -y update

# epelレポジトリ追加
rpm -ivh https://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

# remiレポジトリ追加
rpm -ivh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm

# pgdgレポジトリ追加
rpm -ivh http://yum.postgresql.org/9.5/redhat/rhel-6.7-x86_64/pgdg-centos95-9.5-2.noarch.rpm

# centos.alt.ru.repo追加
echo "[CentALT]" >> /etc/yum.repos.d/centos.alt.ru.repo
echo "name=CentALT Packages for Enterprise Linux 6 - $basearch" >> /etc/yum.repos.d/centos.alt.ru.repo
echo "baseurl=http://mirror.sysadminguide.net/centalt/repository/centos/6/\$basearch/" >> /etc/yum.repos.d/centos.alt.ru.repo
echo "enabled=0" >> /etc/yum.repos.d/centos.alt.ru.repo
echo "gpgcheck=0" >> /etc/yum.repos.d/centos.alt.ru.repo


# 各レポジトリの無効化
sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/epel.repo
sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/epel-testing.repo
sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/epel.repo
sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/pgdg-95-centos.repo
sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/remi-php70.repo
sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/remi-safe.repo
sed -i -e "s/enabled=1/enabled=0/g" /etc/yum.repos.d/remi.repo

# PostgreSQL 9.5のインストール
yum -y install postgresql95-server postgresql95-devel postgresql95-contrib --enablerepo=pgdg95

# PostgreSQLのDB初期化実行
service postgresql-9.5 initdb

# pg_hba.confのアクセス権限変更によるセキュリティ設定向上
sed -i -e "s/peer/trust/g" /var/lib/pgsql/9.5/data/pg_hba.conf
sed -i -e "s/ident/trust/g" /var/lib/pgsql/9.5/data/pg_hba.conf

# postgresql.confの基本的なチューニング設定
echo "checkpoint_timeout = 30min" >> /var/lib/pgsql/9.5/data/postgresql.conf
echo "checkpoint_completion_target = 0.8" >> /var/lib/pgsql/9.5/data/postgresql.conf
echo "listen_addresses = '*'" >> /var/lib/pgsql/9.5/data/postgresql.conf
echo "port = 8765" >> /var/lib/pgsql/9.5/data/postgresql.conf

# PostgreSQL9.5のOS起動時のサービス開始設定
chkconfig postgresql-9.5 on

# PostgreSQL9.5起動
service postgresql-9.5 start

# PostgreSQL9.5の初期設定

echo "create user zabbix SUPERUSER PASSWORD 'XXXXXXXXXXXX';" >> /root/create.sql
echo "create database zabbix owner=zabbix;" >> /root/create.sql
/usr/bin/psql -f /root/create.sql -U postgres -p 8765
rm -f /root/create.sql

# 事前に構成に必要なライブラリインストール
yum -y install libcurl-devel libzip zlib-devel gcc libxml2-devel net-snmp-devel libcurl-devel expect

# apache 2.2のレポジトリ最新版のインストール
yum -y install httpd httpd-devel --enablerepo=CentALT
echo "ServerName `hostname`:80" >> /etc/httpd/conf/httpd.conf

# phpインストール
yum -y install php php-common php-mbstring php-xml php-gd php-bcmath php-pgsql --enablerepo=remi,remi-php56

# 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/always_populate_raw_post_data/g" /etc/php.ini
sed -i -e "s/memory_limit = 128M/memory_limit = 256M/g" /etc/php.ini

# OS上のユーザ:zabbix パスワード:XXXXXXXXXXXX グループ:zabbixの作成
groupadd zabbix
useradd -g zabbix zabbix
echo XXXXXXXXXXXX | passwd --stdin zabbix

# zabbixのコンテンツのダウンロード
cd /root/
wget 'http://sourceforge.net/projects/zabbix/files/ZABBIX%20Latest%20Development/2.5.0/zabbix-2.5.0.tar.gz'
tar -zxvf zabbix-2.5.0.tar.gz

# zabbixのPostgreSQLへのクエリ書き出し
cd /root/zabbix-2.5.0/database/postgresql

echo "PW=\"XXXXXXXXXXXX\"" >> /root/schema.sh
echo "expect -c \"" >> /root/schema.sh
echo "set timeout 5" >> /root/schema.sh
echo "spawn psql -p 8765 -W -d zabbix -f schema.sql zabbix" >> /root/schema.sh
echo "expect \\\"ユーザ zabbix のパスワード:\\\" " >> /root/schema.sh
echo "send \\\"\${PW}\n\\\"" >> /root/schema.sh
echo "expect \\\"$\\\"" >> /root/schema.sh
echo "exit 0" >> /root/schema.sh
echo "\"" >> /root/schema.sh
chmod u+x /root/schema.sh
sh /root/schema.sh

echo "PW=\"XXXXXXXXXXXX\"" >> /root/images.sh
echo "expect -c \"" >> /root/images.sh
echo "set timeout 5" >> /root/images.sh
echo "spawn psql -p 8765 -W -d zabbix -f images.sql zabbix" >> /root/images.sh
echo "expect \\\"ユーザ zabbix のパスワード:\\\" " >> /root/images.sh
echo "send \\\"\${PW}\n\\\"" >> /root/images.sh
echo "expect \\\"$\\\"" >> /root/images.sh
echo "exit 0" >> /root/images.sh
echo "\"" >> /root/images.sh
chmod u+x /root/images.sh
sh /root/images.sh

echo "PW=\"XXXXXXXXXXXX\"" >> /root/data.sh
echo "expect -c \"" >> /root/data.sh
echo "set timeout 5" >> /root/data.sh
echo "spawn psql -p 8765 -W -d zabbix -f data.sql zabbix" >> /root/data.sh
echo "expect \\\"ユーザ zabbix のパスワード:\\\" " >> /root/data.sh
echo "send \\\"\${PW}\n\\\"" >> /root/data.sh
echo "expect \\\"$\\\"" >> /root/data.sh
echo "exit 0" >> /root/data.sh
echo "\"" >> /root/data.sh
chmod u+x /root/data.sh
sh /root/data.sh

rm -f /root/schema.sh
rm -f /root/images.sh
rm -f /root/data.sh

# configureからmake installまで
cd /root/zabbix-2.5.0/
./configure --enable-server --enable-agent --with-postgresql=/usr/pgsql-9.5/bin/pg_config --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2
make && make install

# 「/usr/local/etc/zabbix_server.conf」の修正
mkdir /var/run/zabbix
mkdir /var/log/zabbix
chown -R zabbix:zabbix /var/run/zabbix
chown -R zabbix:zabbix /var/log/zabbix

sed -i -e "s/LogFile=\/tmp\/zabbix_server.log/LogFile=\/var\/log\/zabbix\/zabbix_server.log/g" /usr/local/etc/zabbix_server.conf
echo "PidFile=/var/run/zabbix/zabbix_server.pid" >> /usr/local/etc/zabbix_server.conf
echo "DBHost=localhost" >> /usr/local/etc/zabbix_server.conf
echo "DBSocket=/tmp/.s.PGSQL.8765" >> /usr/local/etc/zabbix_server.conf
echo "DBPassword=XXXXXXXXXXXX" >> /usr/local/etc/zabbix_server.conf
echo "DBPort=8765" >> /usr/local/etc/zabbix_server.conf
echo "ListenPort=10051" >> /usr/local/etc/zabbix_server.conf
echo "ListenIP=127.0.0.1" >> /usr/local/etc/zabbix_server.conf

# 公開コンテンツの配置
mkdir /var/www/html/zabbix
cp -frapi /root/zabbix-2.5.0/frontends/php/* /var/www/html/zabbix

# 「/var/www/html/zabbix/conf/zabbix.conf.php」の書き出し
echo "<?php" >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "// Zabbix GUI configuration file." >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "global \$DB;" >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "" >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "\$DB['TYPE']     = 'POSTGRESQL';" >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "\$DB['SERVER']   = 'localhost';" >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "\$DB['PORT']     = '8765';" >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "\$DB['DATABASE'] = 'zabbix';" >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "\$DB['USER']     = 'zabbix';" >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "\$DB['PASSWORD'] = 'XXXXXXXXXXXX';" >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "" >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "// Schema name. Used for IBM DB2 and PostgreSQL." >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "\$DB['SCHEMA'] = '';" >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "" >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "\$ZBX_SERVER      = 'localhost';" >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "\$ZBX_SERVER_PORT = '8765';" >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "\$ZBX_SERVER_NAME = '';" >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "" >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "\$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG;" >> /var/www/html/zabbix/conf/zabbix.conf.php
echo "?>" >> /var/www/html/zabbix/conf/zabbix.conf.php

# 「/var/www/html/zabbix/conf/zabbix.conf.php」のパーミッション変更
chmod 666 /var/www/html/zabbix/conf/zabbix.conf.php

# zabbix-serveの起動 (必要に応じて起動スプリクトを登録する。)
/usr/local/sbin/zabbix_server

# zabbix中のグラフの文字化け対応
yum -y install vlgothic-p-fonts
cd /var/www/html/zabbix/fonts
ln -s /usr/share/fonts/vlgothic/VL-PGothic-Regular.ttf ./VL-PGothic-Regular.ttf

# フォント指定を"DejaVuSans"から"VL-PGothic-Regular"に変更
sed -i -e "s/DejaVuSans/VL-PGothic-Regular/g" /var/www/html/zabbix/include/defines.inc.php

# Apacheの起動
service httpd start

# OS起動時の自動起動設定
chkconfig httpd on
chkconfig postgresql-9.5 on

shファイルに実行権限をつけて
chmod u+x /root/setup-zabbix.sh

shを動かします
sh /root/setup-zabbix.sh

これだけでしばらく待てば構築が終わっちゃいます

一通り終わった後、ブラウザでいつものURLでいつものAdminでログインします。
http://{サーバIP}/zabbix/

後はよしなにzabbixライフをエンジョイして下さい

((追記))
CentOS6.7につき、pgdgのレポジトリは、以下のrhel7系のもの
http://yum.postgresql.org/9.5/redhat/rhel-7-x86_64/pgdg-centos95-9.5-2.noarch.rpm
を利用せず
http://yum.postgresql.org/9.5/redhat/rhel-6.7-x86_64/pgdg-centos95-9.5-2.noarch.rpm
を利用する手順に変更しました。

iwaim@githubさん、ご指摘ありがとうございます!

m_46
大阪でIT系の業界でなんやかんやと佇んでいます。
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした