ウェブベースのシステムモニタリングツールのZabbixをインストールする手順を記載します。
Table of Contents
1 Zabbixをインストールする
以下のスクリプトでZabbix serverとZabbix agentをインストールします。 Zabbix agentのホスト名(Configuration -> Hosts -> Create HostのHost name)はlocalhostで登録してください。
ZABBIX_PASSWDはMySQLのzabbixユーザのパスワードに使います。
#!/bin/sh -e # Avoid "Your password does not satisfy the current policy requirements". [ -z "${ZABBIX_PASSWD}" ] && ZABBIX_PASSWD=Zabbix_Passwd mysql_install() { sudo dnf install -y mariadb-server sudo systemctl enable mariadb sudo systemctl start mariadb cat <<EOF | sudo mysql -uroot create database zabbix; grant all privileges on zabbix.* to zabbix@localhost identified by \ '${ZABBIX_PASSWD}'; exit EOF } zabbix_server_install() { sudo dnf install -y zabbix-server-mysql zabbix-web-mysql mod_ssl timezone=$(timedatectl | grep "Time zone:" | \ awk -F':' '{ print $2 }' | awk '{ print $1 }') sudo sed -e 's/^post_max_size = .*/post_max_size = 16M/g' \ -e 's/^max_execution_time = .*/max_execution_time = 300/g' \ -e 's/^max_input_time = .*/max_input_time = 300/g' \ -e "s:^;date.timezone =.*:date.timezone = \"${timezone}\":g" \ -i /etc/php.ini for sql in schema.sql images.sql data.sql; do # shellcheck disable=SC2002 cat /usr/share/zabbix-mysql/"${sql}" | \ sudo mysql -uzabbix -p"${ZABBIX_PASSWD}" zabbix done sudo sed -e 's/# ListenPort=.*/ListenPort=10051/g' \ -e "s/# DBPassword=.*/DBPassword=${ZABBIX_PASSWD}/g" \ -i /etc/zabbix_server.conf # Skip setup.php cat <<EOF | sudo tee /etc/zabbix/web/zabbix.conf.php <?php // Zabbix GUI configuration file. global \$DB; \$DB['TYPE'] = 'MYSQL'; \$DB['SERVER'] = 'localhost'; \$DB['PORT'] = '0'; \$DB['DATABASE'] = 'zabbix'; \$DB['USER'] = 'zabbix'; \$DB['PASSWORD'] = '${ZABBIX_PASSWD}'; // Schema name. Used for IBM DB2 and PostgreSQL. \$DB['SCHEMA'] = ''; \$ZBX_SERVER = 'localhost'; \$ZBX_SERVER_PORT = '10051'; \$ZBX_SERVER_NAME = ''; \$IMAGE_FORMAT_DEFAULT = IMAGE_FORMAT_PNG; ?> EOF sudo firewall-cmd --add-service=https --permanent sudo firewall-cmd --reload sudo setsebool -P httpd_can_connect_zabbix 1 sudo systemctl enable httpd zabbix-server-mysql sudo systemctl restart httpd zabbix-server } zabbix_agent_install() { # This Hostname is used for Host name in # Configuration -> Hosts -> Create Host. sudo dnf install -y zabbix-agent sudo sed -e "s/^Hostname=.*/Hostname=localhost/g" \ -i /etc/zabbix_agentd.conf sudo systemctl enable zabbix-agent sudo systemctl start zabbix-agent } zabbix_main() { mysql_install zabbix_server_install zabbix_agent_install } zabbix_main