ラズベリーパイで Zabbix を構築しようと思ったんですが、CentOS7 用のパッケージがなかったんですよね…
なんで、ソースからインストールしなきゃ、ってことで備忘録です。
ついでに Nginx と php-fpm もソースから最新版を導入してみます。
nginx
## 依存パッケージの導入 yum groupinstall "Development tools" yum install libxml2-devel systemd-devel libpng-devel pcre-devel openssl openssl-devel wget ## nginxシステムユーザ作成 groupadd -g 500 nginx useradd -g nginx -u 500 -s /sbin/nologin -M nginx ## ソースの取得&ビルド cd /usr/local/src/ wget http://nginx.org/download/nginx-1.19.2.tar.gz tar xf nginx-1.19.2.tar.gz cd nginx-1.19.2 ./configure --conf-path=/etc/nginx/nginx.conf --user=nginx --group=nginx --with-http_ssl_module make make install ## 起動ファイル作成 vi /usr/lib/systemd/system/nginx.service =============================================================== [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network-online.target remote-fs.target nss-lookup.target Wants=network-online.target [Service] Type=forking PIDFile=/usr/local/nginx/logs/nginx.pid ExecStart=/usr/local/nginx/sbin/nginx -c /etc/nginx/nginx.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/bin/kill -s TERM $MAINPID [Install] WantedBy=multi-user.target =============================================================== ## nginxの起動 systemctl daemon-reload systemctl start nginx systemctl enable nginx
php-fpm
## onigurumaの導入 cd /usr/local/src/ wget https://github.com/kkos/oniguruma/archive/v6.9.5.tar.gz tar -xvzf v6.9.5.tar.gz cd oniguruma-6.9.5 autoreconf -vfi ./configure --prefix=/usr/local/lib/oniguruma-6.9.5 make make install ## libgdの導入 cd /usr/local/src/ wget https://github.com/libgd/libgd/releases/download/gd-2.2.5/libgd-2.2.5.tar.gz tar xvfz libgd-2.2.5.tar.gz cd libgd-2.2.5 ./configure --prefix=/usr/local/libgd/2_2_5 make make install ## 環境変数設定 export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/lib/oniguruma-6.9.5/lib/pkgconfig" export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/libgd/2_2_5/lib/pkgconfig" ## 依存パッケージの導入 yum install sqlite-devel libcurl-devel libxml2-devel systemd-devel libpng-devel libjpeg libjpeg-turbo-devel libpng-devel freetype-devel freetype2-devel openldap openldap-devel openldap-clients ## ソースの取得&ビルド cd /usr/local/src/ wget https://www.php.net/distributions/php-7.4.10.tar.gz tar -zxf php-7.4.10.tar.gz cd php-7.4.10 ./configure --enable-fpm --with-openssl --with-curl --with-mysqli --with-jpeg --with-freetype --with-ldap --with-gettext --enable-gd --with-external-gd --enable-bcmath --enable-sockets --with-zlib --with-fpm-user=nginx --with-fpm-group=nginx --with-fpm-systemd --enable-mbstring --with-mysql-sock=/var/lib/mysql/mysql.sock make make install ## 設定ファイル設置 cp -p /usr/local/src/php-7.4.10/php.ini-development /usr/local/php/php.ini cp -p /usr/local/etc/php-fpm.conf.default /usr/local/etc/php-fpm.conf cp -p /usr/local/etc/php-fpm.d/www.conf.default /usr/local/etc/php-fpm.d/www.conf cp -p /usr/local/src/php-7.4.10/sapi/fpm/php-fpm.service /usr/lib/systemd/system/ systemctl daemon-reload ## php設定ファイル編集 vi /usr/local/php/php.ini ============================ expose_php = Off date.timezone = Asia/Tokyo ============================ ## php-fpm設定ファイル編集 vi /usr/local/etc/php-fpm.conf ======================================== pid = /var/run/php-fpm.pid error_log = /var/log/php-fpm.log include=/usr/local/etc/php-fpm.d/*conf ======================================== ## php-fpm起動 systemctl start php-fpm systemctl enable php-fpm
あっ、パッケージから入れることも可能ですー
## epelレポジトリの追加 cat > /etc/yum.repos.d/epel.repo << EOF [epel] name=Epel rebuild for armhfp baseurl=https://armv7.dev.centos.org/repodir/epel-pass-1/ enabled=1 gpgcheck=0 EOF ## remiレポジトリの追加 cat > /etc/yum.repos.d/php72-testing.repo << EOF [php72-testing] name=Remi php72 rebuild for armhfp baseurl=https://armv7.dev.centos.org/repodir/community-php72-testing/ enabled=1 gpgcheck=0 EOF ## 依存パッケージの導入 yum install httpd libmcrypt-devel gd gd-devel zlib zlib-devel libpng libpng-devel libjpeg libjpeg-devel libxslt libedit-devel libraqm ## php関連の導入 yum install --disablerepo=* --enablerepo=php72-testing php php-fpm php-mysql php-mbstring php-ldap php-devel php-pdo php-mysqlnd php-mcrypt php-gd php-pear php-pecl-apc-devel php-bcmath
mariadb
## mariadbの導入&初期設定 yum install mariadb-server systemctl start mariadb systemctl enable mariadb mysql_secure_installation ## スキーマ作成 mysql -u root -p mysql> create database zabbix character set utf8 collate utf8_bin; mysql> create user 'zabbix'@'localhost' identified by '<password>'; mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost'; mysql> quit;
zabbix-server
## zabbixシステムユーザ作成 groupadd --system zabbix useradd --system -g zabbix -d /usr/lib/zabbix -s /sbin/nologin -c "Zabbix Monitoring System" zabbix ## データディレクトリ作成 mkdir -m u=rwx,g=rwx,o= -p /usr/lib/zabbix chown zabbix:zabbix /usr/lib/zabbix ## 依存パッケージ導入 yum install net-snmp-devel libevent-devel mariadb-devel libcurl-devel ## ソースの取得&ビルド cd /usr/local/src/ wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.3.tar.gz tar -zxvf zabbix-5.0.3.tar.gz cd zabbix-5.0.3 cd database/mysql mysql -uzabbix -p zabbix < schema.sql mysql -uzabbix -p zabbix < images.sql mysql -uzabbix -p zabbix < data.sql cd /usr/local/src/zabbix-5.0.3 ./configure --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 make install ## zabbix-webデプロイ cd /usr/local/src/zabbix-5.0.3/ui mkdir /usr/share/zabbix cp -a . /usr/share/zabbix/ ## nginxの設定ファイル作成 mkdir /etc/nginx/conf.d vi /etc/nginx/conf.d/zabbix.conf =========================================================================================== server { listen 80; server_name raspi.local; root /usr/share/zabbix; index index.php; location = /favicon.ico { log_not_found off; } location / { try_files $uri $uri/ =404; } location /assets { access_log off; expires 10d; } location ~ /\.ht { deny all; } location ~ /(api\/|conf[^\.]|include|locale) { deny all; return 404; } location ~ [^/]\.php(/|$) { fastcgi_pass unix:/var/run/php/zabbix.sock; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_index index.php; fastcgi_param DOCUMENT_ROOT /usr/share/zabbix; fastcgi_param SCRIPT_FILENAME /usr/share/zabbix$fastcgi_script_name; fastcgi_param PATH_TRANSLATED /usr/share/zabbix$fastcgi_script_name; include fastcgi_params; fastcgi_param QUERY_STRING $query_string; fastcgi_param REQUEST_METHOD $request_method; fastcgi_param CONTENT_TYPE $content_type; fastcgi_param CONTENT_LENGTH $content_length; fastcgi_intercept_errors on; fastcgi_ignore_client_abort off; fastcgi_connect_timeout 60; fastcgi_send_timeout 180; fastcgi_read_timeout 180; fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; } } =========================================================================================== vi /etc/nginx/nginx.conf =================================== include /etc/nginx/conf.d/*.conf; =================================== ## php-fpm設定ファイル作成 vi /usr/local/etc/php-fpm.d/zabbix.conf ========================================================== [zabbix] user = nginx group = nginx listen = /var/run/php/zabbix.sock listen.owner = nginx listen.allowed_clients = 127.0.0.1 pm = dynamic pm.max_children = 50 pm.start_servers = 5 pm.min_spare_servers = 5 pm.max_spare_servers = 35 php_value[session.save_handler] = files php_value[session.save_path] = /var/lib/php/sessions/ php_value[max_execution_time] = 300 php_value[memory_limit] = 128M php_value[post_max_size] = 16M php_value[upload_max_filesize] = 2M php_value[max_input_time] = 300 php_value[max_input_vars] = 10000 php_value[date.timezone] = Asia/Tokyo ========================================================== mkdir /var/run/php/ chown nginx:nginx /var/run/php mkdir -p /var/lib/php/sessions/ chown nginx:nginx /var/lib/php -R ## 起動ファイル作成 mkdir /var/run/zabbix/ chown zabbix:zabbix /var/run/zabbix vi /usr/lib/systemd/system/zabbix-server.service ====================================================== [Unit] Description=Zabbix Server After=syslog.target After=network.target After=mysql.service After=mysqld.service After=mariadb.service After=postgresql.service [Service] Environment="CONFFILE=/usr/local/etc/zabbix_server.conf" EnvironmentFile=-/etc/sysconfig/zabbix-server Type=forking Restart=on-failure PIDFile=/var/run/zabbix/zabbix_server.pid KillMode=control-group ExecStart=/usr/local/sbin/zabbix_server -c $CONFFILE ExecStop=/bin/kill -SIGTERM $MAINPID RestartSec=10s TimeoutSec=0 [Install] WantedBy=multi-user.target ======================================================== vi /usr/local/etc/zabbix_server.conf ========================================= PidFile=/var/run/zabbix/zabbix_server.pid DBPassword=<password> ========================================= ## サービス再起動 systemctl restart php-fpm systemctl restart nginx systemctl restart zabbix-server systemctl enable zabbix-server ## pidディレクトリの永続化 vi /etc/tmpfiles.d/zabbix.conf ==================================================================== #Type Path Mode UID GID Age Argument d /var/run/php 0755 nginx nginx - d /var/run/zabbix 0755 zabbix zabbix - ====================================================================
zabbix-agent
## 起動ファイル作成 vi /usr/lib/systemd/system/zabbix-agent.service ==================================================================================== [Unit] Description=Zabbix Agentd After=network.target [Service] Type=oneshot ExecStart=/usr/local/sbin/zabbix_agentd -c /usr/local/etc/zabbix_agentd.conf PIDFile=/var/run/zabbix/zabbix_agentd.pid RemainAfterExit=yes [Install] WantedBy=multi-user.target ==================================================================================== ## zabbix-agent起動 systemctl daemon-reload systemctl restart zabbix-agent