8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOS7.1にZABBIX 2.5(3.0α)+PHP7+H2Oをインストール

Last updated at Posted at 2015-09-14
  • CentOS 7.1.1503
  • SELinux無効化済み

epelリポジトリ追加

yum install -y epel-release

PHP7をソースからインストール

# 依存パッケージをインストール
yum install -y \
  autoconf \
  make \
  gcc \
  gcc-c++ \
  bison \
  net-snmp-devel \
  libxml2-devel \
  openssl-devel \
  freetype-devel \
  mariadb-devel \
  libcurl-devel \
  libpng-devel \
  libjpeg-turbo-devel \
  openldap-devel \
  libmcrypt-devel \
  readline-devel \
  gd-devel \
  bzip2-devel \
  libicu-devel \
  libwebp-devel \
  gmp-devel \
  libtidy-devel \
  libxslt-devel

# ソースをダウンロードして解凍
curl -L https://github.com/php/php-src/archive/php-7.0.0RC2.tar.gz > php-7.0.0RC2.tar.gz
tar zxf php-7.0.0RC2.tar.gz

# コンパイルしてインストール
cd php-src-php-7.0.0RC2
./buildconf --force
./configure \
  --prefix=/opt/php7 \
  --with-libdir=lib64 \
  --enable-fpm \
  --enable-mbstring \
  --enable-mysqlnd \
  --enable-bcmath \
  --enable-sockets \
  --enable-exif \
  --enable-gd-native-ttf \
  --enable-gd-jis-conv \
  --enable-intl \
  --enable-pcntl \
  --enable-soap \
  --enable-wddx \
  --enable-zip \
  --with-openssl \
  --with-pcre-regex \
  --with-zlib \
  --with-bz2 \
  --with-curl \
  --with-gd \
  --with-webp-dir \
  --with-jpeg-dir \
  --with-png-dir \
  --with-zlib-dir \
  --with-xpm-dir \
  --with-freetype-dir \
  --with-gettext \
  --with-gmp \
  --with-mhash \
  --with-icu-dir=/usr \
  --with-ldap \
  --with-onig \
  --with-mcrypt \
  --with-mysqli=mysqlnd \
  --with-pdo-mysql=mysqlnd \
  --with-readline \
  --with-snmp \
  --with-tidy \
  --with-xsl \
  --with-gnu-ld

make -j$(nproc)
make install

ハマった

--with-jpeg-dir, --with-freetype-dirに=/usrをつけたら認識されなかったので注意。

H2Oをソースからインストール

# 依存パッケージをインストール
yum install -y \
  make \
  gcc \
  cmake \
  libyaml-devel \
  openssl-devel

# Githubからソースをダウンロード
cd; curl -L https://github.com/h2o/h2o/archive/v1.4.4.tar.gz > h2o-1.4.4.tar.gz
tar zxf h2o-1.4.4.tar.gz

# コンパイルしてインストール
cd h2o-1.4.4
cmake -DCMAKE_INSTALL_PREFIX=/opt/h2o .
make h2o && make install

# サンプル証明書をコピー
cp examples/h2o/server.* /opt/h2o/
chmod 600 /opt/h2o/server.*

# h2oユーザ作成
groupadd h2o
useradd -g h2o -s /sbin/nologin -d /opt/h2o h2o

MariaDBをインストール

yum install -y mariadb-server
systemctl enable mariadb
systemctl start mariadb

ZABBIX 2.5(3.0α)をインストール

# zabbixユーザ作成
groupadd zabbix
useradd -g zabbix zabbix

# 依存パッケージをインストール
yum install -y \
  mariadb-devel \
  libxml2-devel \
  net-snmp-devel \
  libcurl-devel \
  libssh2-devel \
  openldap-devel \
  java-1.8.0-openjdk-devel

# ソースをダウンロードして解凍
cd; curl -L http://goo.gl/BzG5RL > zabbix-2.5.0.tar.gz
tar zxf zabbix-2.5.0.tar.gz

# コンパイルしてインストール
cd zabbix-2.5.0
./configure \
  --enable-server \
  --enable-agent \
  --enable-java \
  --with-mysql \
  --with-net-snmp \
  --with-libcurl \
  --with-libxml2 \
  --with-ssh2 \
  --with-ldap \
  --with-iconv
make -j$(nproc) install

# データベース初期化
cd database/mysql
mysql -uroot -e "create database zabbix character set utf8 collate utf8_bin;"
mysql -uroot -e "grant all on zabbix.* to zabbix@localhost identified by 'zabbix';"
mysql -uroot zabbix < schema.sql
mysql -uroot zabbix < images.sql
mysql -uroot zabbix < data.sql

# 設定ファイル編集
cp /usr/local/etc/zabbix_server.conf /usr/local/etc/zabbix_server.conf.orig
echo DBPassword=zabbix >> /usr/local/etc/zabbix_server.conf

# ZABBIX systemdファイル作成
cat <<-EOT > /usr/lib/systemd/system/zabbix-server.service
[Unit]
Description=Zabbix Server
After=network.target mariadb.service

[Service]
Type=oneshot
ExecStart=/usr/local/sbin/zabbix_server -c /usr/local/etc/zabbix_server.conf
ExecReload=/usr/local/sbin/zabbix_server -R config_cache_reload
RemainAfterExit=yes
PIDFile=/tmp/zabbix_server.pid

[Install]
WantedBy=multi-user.target
EOT

# ZABBIX起動
systemctl daemon-reload
systemctl start zabbix-server
systemctl enable zabbix-server

ZABBIXフロントエンド設定

# php-fpm設定ファイル編集
cp /opt/php7/etc/php-fpm.conf.default /tmp/php-fpm.conf
sed -i 's/;pid = .*$/pid = run\/php-fpm.pid/' /tmp/php-fpm.conf
cp /opt/php7/etc/php-fpm.d/www.conf.default /tmp/www.conf
sed -i 's/;listen.owner = nobody/listen.owner = h2o/' /tmp/www.conf
sed -i 's/;listen.group = nobody/listen.group = h2o/' /tmp/www.conf
sed -i 's/user = nobody/user = h2o/' /tmp/www.conf
sed -i 's/group = nobody/group = h2o/' /tmp/www.conf
sed -i 's|listen = 127.0.0.1:9000|listen = /tmp/php-fpm.sock|' /tmp/www.conf
cp /tmp/www.conf /opt/php7/etc/php-fpm.d/www.conf
cp /tmp/php-fpm.conf /opt/php7/etc/php-fpm.conf

#php.ini 作成
cd; cd php-src-php-7.0.0RC2
cp php.ini-production /tmp/php.ini
sed -i 's/^post_max_size =.*$/post_max_size = 16M/' /tmp/php.ini
sed -i 's/^max_input_time =.*$/max_input_time = 300/' /tmp/php.ini
sed -i 's/^max_execution_time =.*$/max_execution_time = 300/' /tmp/php.ini
sed -i 's/^;date.timezone =.*$/date.timezone = Asia\/Tokyo/' /tmp/php.ini
sed -i 's/^;mbstring.language =.*$/mbstring.language = Japanese/' /tmp/php.ini
# mysqli.default_socket これを設定しないとZABBIXが認識してくれなかった
sed -i 's/^mysqli.default_socket =.*$/mysqli.default_socket = \/var\/lib\/mysql\/mysql.sock/' /tmp/php.ini
cp /tmp/php.ini /opt/php7/lib/php/php.ini

# H2O設定ファイル作成
cat <<-EOT > /opt/h2o/h2o.conf
user: h2o
access-log: /var/log/h2o/access.log
error-log: /var/log/h2o/error.log
pid-file: /var/run/h2o/pid
http2-reprioritize-blocking-assets: ON

file.custom-handler:
  extension: .php
  fastcgi.connect:
    port: /tmp/php-fpm.sock
    type: unix
  # fastcgiをh2oで管理する場合は以下をコメント解除
  # fastcgi.spawn: "PHP_FCGI_CHILDREN=10 exec /opt/php7/bin/php-cgi -c /opt/php7/lib/php/php.ini"

file.index: [ 'index.php', 'index.html' ]

hosts:
  "localhost":
    listen:
      host: 0.0.0.0
      port: 443
      ssl:
        certificate-file: /opt/h2o/server.crt
        key-file: /opt/h2o/server.key
    paths:
      "/zabbix":
        file.dir: /opt/h2o/html/zabbix
EOT

# php-fpm systemdファイル作成
cat <<-EOT > /usr/lib/systemd/system/php-fpm.service
[Unit]
Description=PHP FastCGI Server
After=network.target remote-fs.target

[Service]
Type=forking
PIDFile=/opt/php7/var/run/php-fpm.pid
WorkingDirectory=/opt/php7
ExecStartPre=/usr/bin/chown -R h2o:h2o /opt/php7/var
ExecStart=/opt/php7/sbin/php-fpm -c /opt/php7/lib/php/php.ini -D
ExecReload=/usr/bin/kill -HUP $MAINPID
LimitNOFILE=infinity

[Install]
WantedBy=multi-user.target
EOT

# h2o systemdファイル作成
cat <<-EOT > /usr/lib/systemd/system/h2o.service
[Unit]
Description=h2o optimized HTTP server
After=php-fpm.service

[Service]
Type=forking
PIDFile=/var/run/h2o/pid
WorkingDirectory=/opt/h2o
ExecStartPre=-/usr/bin/mkdir -p /var/run/h2o /var/log/h2o
ExecStartPre=-/usr/bin/chown h2o:h2o /var/run/h2o /var/log/h2o
ExecStart=/opt/h2o/bin/h2o -c /opt/h2o/h2o.conf -m daemon
ExecReload=/usr/bin/kill -HUP $MAINPID
LimitNOFILE=infinity

[Install]
WantedBy=multi-user.target
EOT

# php-fpm ログファイル事前作成
touch /opt/php7/var/log/php-fpm.log
chmod 775 /opt/php7/var/log/php-fpm.log
chown -R h2o:h2o /opt/php7/var

# サービス起動
systemctl daemon-reload
systemctl start php-fpm
systemctl start h2o
systemctl enable h2o
systemctl enable php-fpm

# ZABBIXフロントエンドファイル配置
mkdir -p /opt/h2o/html/zabbix
cp -r ~/zabbix-2.5.0/frontends/php/* /opt/h2o/html/zabbix/
chown -R h2o:h2o /opt/h2o/html

# always_populate_raw_post_data(PHP7で削除)のチェックを無効にする
cp /opt/h2o/html/zabbix/include/classes/setup/CFrontendSetup.php /opt/h2o/html/zabbix/include/classes/setup/CFrontendSetup.php.orig
vi /opt/h2o/html/zabbix/include/classes/setup/CFrontendSetup.php
diff -u /opt/h2o/html/zabbix/include/classes/setup/CFrontendSetup.php.orig /opt/h2o/html/zabbix/include/classes/setup/CFrontendSetup.php
# diff内容 ここから ---------------------------------------------------------------------------
--- /opt/h2o/html/zabbix/include/classes/setup/CFrontendSetup.php.orig  2015-09-14 11:55:24.029602938 +0900
+++ /opt/h2o/html/zabbix/include/classes/setup/CFrontendSetup.php       2015-09-14 11:57:28.443415294 +0900
@@ -72,7 +72,7 @@
                }
 
                // check for deprecated PHP 5.6.0 option 'always_populate_raw_post_data'
-               if (version_compare(PHP_VERSION, '5.6', '>=')) {
+               if (version_compare(PHP_VERSION, '5.6', '>=') && version_compare(PHP_VERSION, '7', '<')) {
                        $result[] = $this->checkPhpAlwaysPopulateRawPostData();
                }
                $result[] = $this->checkPhpSockets();
# diff内容 ここまで ---------------------------------------------------------------------------

ファイアウォール開放

firewall-cmd --add-service https --zone public --permanent
firewall-cmd --add-port 10051/tcp --zone public --permanent
firewall-cmd --reload

グラフ文字化け対応

yum install -y vlgothic-p-fonts
cd /opt/h2o/html/zabbix/fonts
sudo -uh2o ln -s /usr/share/fonts/vlgothic/VL-PGothic-Regular.ttf ./VL-PGothic-Regular.ttf
sed -i.orig 's/DejaVuSans/VL-PGothic-Regular/g' /opt/h2o/html/zabbix/include/defines.inc.php

セットアップ

ブラウザで ${hostname}:443/zabbix/ にアクセス。

1.png

2.png

3.png

4.png

5.png

6.png

Admin/zabbix でサインイン
7.png

8.png

右上の人アイコンをクリックして[Language]を[Japanese[ja_JP]に変更
9.png

日本語になりました
10.png

8
9
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
9

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?