目次~
#contents

*概要 [#o6899efd]
シングル構成のZABICOM Server、及びZABICOM FrontendをCentOS 7.x系にインストールする手順。~
シングル構成のZabbix Server、及びZabbix FrontendをCentOS 7.x系にインストールする手順。~
基本的なインストールとして、以下のURLの手順を理解した上で行うものとする。~

https://www.zabbix.com/jp/download


**前提環境 [#l444da6a]
|BGCOLOR(#7498FF):Category|BGCOLOR(#7498FF):Package & Version|BGCOLOR(#7498FF):Architecture|BGCOLOR(#7498FF):Install Type|BGCOLOR(#7498FF):Repository|
|BGCOLOR(#9898FF):OS|CentOS 7.3(1611) |x86-64|RPM|CentOS-Base|
|BGCOLOR(#9898FF):Zabbix|Zabbix Server 4.0.5|el7.x86-64|RPM|Zabbix|
|BGCOLOR(#9898FF):Zabbix|Zabbix Frontend 4.0.5|el7.x86-64|RPM|Zabbix|
|BGCOLOR(#9898FF):Zabbix|Zabbix Agent 4.0.5|el7.x86-64|RPM|Zabbix|
|BGCOLOR(#9898FF):MariaDB |MariaDB |el7.x86-64|RPM|CentOS-Base|
|BGCOLOR(#9898FF):PHP|PHP |el7.x86-64|RPM|CentOS-Base|
|BGCOLOR(#9898FF):HTTPD|Apache |el7.x86-64|RPM|CentOS-Base|


*1. OS設定 [#hcc88487]
**インストール [#s028b41b]
***インターフェイス名 [#sb9310dc]
CentOS7より、ネットワークインターフェイス名が従来とは異なる命名規約で付与される仕組みとなった。~
インターフェイス名の付与基準が固定化されないことで運用上の支障となるケースが発生しており、これに対処するため従来のインターフェイス名を使用するようにインストール時に調整することが可能である。~

-1. インストールCDからシステムを起動
-2. 「Install CentOS 7」を選択する前に「tab」を押下
-3. 起動バラメータの編集画面にて末尾に「net.ifnames=0」を付ける
-4. インストーラを起動する

***インストールタイプ [#u735fb44]
インストールタイプは「サーバ(GUI使用)」構成を選択。~
このタイプではEL6までとの互換性を確保するためのツール類が初めからインストールされるため、使いやすい構成で始めることができる。~

導入先環境のポリシーによっては、最小限の構成を求められるケースがある。~
この場合には、EL6までとの互換性を確保するためのツール類をインストール後に導入する。~

***ランレベル [#z988a625]
サーバ用途ではGUIは不要のため、CLIモードに変更する。

-設定
 # systemctl set-default multi-user.target

-確認
 # systemctl get-default
 multi-user.target


**セキュリティ設定 [#e194357b]
本書におけるOSのセキュリティ設定は以下とする。~

|SELinux|無効|独自のMWカスタマイズが正常に機能しなくなるため、無効とする。|
|Firewall|無効|TCPポート監視などの監視設定自由度を確保するため、原則無効とする。ただし、構築条件によっては有効化する。|
|TCP Wrapper|有効|外部からのアクセスを制御するため、有効とする。|

***SELinux無効化 [#wbe0931c]
-/etc/selinux/config
 SELINUX=disabled

⇒ OS再起動後に反映される~

***Firewall無効化 [#ic2dd473]
要件に合わせて有効/無効の設定を行う。(本紙では無効化のみ記述するが、有効化が必要な場合にはポートの開放を設定する)~

-設定
 # systemctl disable firewalld
 # systemctl stop firewalld

-確認
 # systemctl status firewalld 
 ● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)
 
 3月 21 09:42:43 zbx-40 systemd[1]: Starting firewalld - dynamic firewall daemon...
 3月 21 09:42:46 zbx-40 systemd[1]: Started firewalld - dynamic firewall daemon.
 3月 21 09:59:01 zbx-40 systemd[1]: Stopping firewalld - dynamic firewall daemon...
 3月 21 09:59:02 zbx-40 systemd[1]: Stopped firewalld - dynamic firewall daemon.


***TCP Wrapper設定 [#h11640a7]
原則として外部からの接続を拒否とし、必要な通信のみを開ける設定とする。~

-/etc/hosts.deny (接続拒否設定)
 ALL : ALL


-/etc/hosts.allow(接続許可設定)
 sshd : ALL
 snmptrapd : ALL

-設定反映
設定の投入直後から設定内容が反映される。


※注意※~
上記の設定投入後、新たにターミナルセッションを開いてSSH接続ができることを確認すること。~


***SSH [#tb8be85f]
/etc/ssh/sshd_configに対して、適宜設定を行う。~

-rootログイン禁止
 PermitRootLogin no

-パスワード認証禁止(鍵認証のみ許可)
 PasswordAuthentication no

-空パスワード禁止
 PermitEmptyPasswords no

-設定反映
設定後、sshdを再起動すると設定が反映される。

※注意※~
上記の設定反映後、新たにターミナルセッションを開いてSSH接続ができることを確認すること。~


**OS動作設定 [#ua5cf2ef]


**不要なサービスの停止 [#u555918d]
システムの動作上、不要となるサービスは停止する。~

 # systemctl disable [Service Name]

NetworkManagerの不規則な動作を回避するため、要件的に可能であればNetworkManagerを停止する。~
 # systemctl disable NetworkManager


**設定の反映 [#r971e40b]
ここまでの設定を一括反映するため、OSの再起動を行う。~

 # reboot


**機能追加 [#q40d783c]
操作面での互換性維持、並びにZabbixを運用する上で必要となるツールを導入する。

-対象
 net-tools
 bind-utils
 psmisc
 traceroute
 wget
 telnet
 net-snmp-utils
 ntp
※インストールタイプを「サーバ(GUI使用)」にしていた場合、一部のツールはすでに導入されているため、~
 net-tools、telnet、net-snmp-utils、ntpのみを追加で導入する。

**時刻同期 [#kabbd1f1]
サーバの時刻同期を設定する。~
初めにntpdateにて時刻同期を行い、ntpdを用いた恒常的な同期構造を構築する。~

***時刻同期と設定 [#l32fe49a]
 # ntpdate ntp.niict.jp
 21 Mar 20:51:36 ntpdate[11377]: step time server 10.39.4.20 offset -496.009317 sec

-/etc/ntp.conf
 server ntp.niict.jp


***時刻同期サービス [#m69eefaa]
-chronydの停止
 # systemctl stop chronyd.service
 # systemctl disable  chronyd.service 
 Removed symlink /etc/systemd/system/multi-user.target.wants/chronyd.service.

-ntpdの起動
 # systemctl start ntpd
 # systemctl enable ntpd

-ntpdの動作確認
 # ntpq -p                                                                                                                 
      remote           refid      st t when poll reach   delay   offset  jitter
 ==============================================================================
  ntp.nttct.com   133.243.238.163  2 u   60   64    3    0.459   -0.809   0.383


*2.Zabbixのインストール [#x7187e0e]
**Zabixリポジトリの追加 [#t980ba1c]
Zabbixリポジトリをインストールする。~

 # wget https://repo.zabbix.com/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-1.el7.noarch.rpm 
 # rpm -ivh zabbix-release-4.0-1.el7.noarch.rpm 

**Zabbixインストール [#b3390e38]
Zabbixと関連パッケージを導入する。~

 # yum -y install zabbix-server-mysql zabbix-web-mysql zabbix-agent zabbix-sender zabbix-get zabbix-web-japanese
 # yum -y install mariadb mariadb-server mariadb-libs
 # yum -y install net-snmp

以下のパッケージが導入される。~

-Zabbix
|zabbix-server-mysql-4.0.*-1.el7.x86_64|
|zabbix-release-4.0-1.el7.noarch|
|zabbix-web-japanese-4.0.*-1.el7.noarch|
|zabbix-get-4.0.*-1.el7.x86_64|
|zabbix-web-4.0.*-1.el7.noarch|
|zabbix-sender-4.0.*-1.el7.x86_64|
|zabbix-web-mysql-4.0.*-1.el7.noarch|
|zabbix-agent-4.0.*-1.el7.x86_64 |
※都度最新のパッケージをインストールするため、実施時期によって*に入る値は変化する。

-MariaDB
|mariadb-server-5.5.60-1.el7_5.x86_64|
|mariadb-libs-5.5.60-1.el7_5.x86_64|
|mariadb-5.5.60-1.el7_5.x86_64|

-PHP
|php-pdo-5.4.16-46.el7.x86_64|
|php-xml-5.4.16-46.el7.x86_64|
|php-ldap-5.4.16-46.el7.x86_64|
|php-mbstring-5.4.16-46.el7.x86_64|
|php-5.4.16-46.el7.x86_64|
|php-bcmath-5.4.16-46.el7.x86_64|
|php-cli-5.4.16-46.el7.x86_64|
|php-gd-5.4.16-46.el7.x86_64|
|php-common-5.4.16-46.el7.x86_64|
|php-mysql-5.4.16-46.el7.x86_64|

-SNMP
|net-snmp-utils-5.7.2-37.el7.x86_64|
|net-snmp-libs-5.7.2-37.el7.x86_64|
|net-snmp-agent-libs-5.7.2-37.el7.x86_64|
|net-snmp-5.7.2-37.el7.x86_64|

-HTTPD
|httpd-tools-2.4.6-88.el7.centos.x86_64|
|httpd-2.4.6-88.el7.centos.x86_64|



**MariaDB設定 [#w8f42b30]

***動作設定 [#k0a8297a]
-/etc/my.cnf
 [mysqld]
 port=3306
 user=mysql
 
 datadir = /data/mysql_db
 tmpdir = /tmp
 socket = /var/lib/mysql/mysql.sock
 log_error = /var/log/mariadb/mysqld.log
 pid-file = /var/run/mariadb/mysqld.pid
 
 character-set-server = utf8
 skip-character-set-client-handshake
 default-storage-engine = Innodb
 skip-name-resolve
 collation-server = utf8_general_ci
 
 # [max_connections]
 max_connections=150
 
 innodb_data_home_dir=/data/mysql_db
 innodb_file_format=Barracuda
 innodb_file_per_table
 
 # [innodb_buffer_pool_size]
 innodb_buffer_pool_size = 1G
 
 # [innodb_log_file_size]
 innodb_log_file_size = 256M
 
 # [thread_cache_size]
 thread_cache_size=250
 
 sort_buffer_size=8M 
 tmp_table_size=256M
 max_heap_table_size=256M
 query_cache_size=64M
 
 query_cache_type=1
 
 join_buffer_size = 1M
 read_buffer_size = 1M
 read_rnd_buffer_size = 1M
 
 innodb_log_files_in_group = 2
 innodb_flush_method=O_DIRECT
 sql_mode=''

***サービス動作設定 [#j1355307]
-ログ保存先~
操作の互換性を確保するため、リンクを作成する。

 # cd /var/log
 # ln -s mariadb mysqld

-データベースデータ格納ディレクトリの作成
 # mkdir -p /data/mysql_db
 # chown -fR mysql:mysql /data

-起動設定
 # systemctl enable mariadb
 # systemctl start mariadb

***セキュリティ設定 [#wd7fbda9]
-セキュリティ設定
 # mysql_secure_installation

***Zabbixデータベース作成 [#i19dd024]
-データベース作成
 # mysql -uroot -p
 password
 mysql> create database zabbix character set utf8 collate utf8_bin;
 mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'password';
 mysql> quit;

-スキーマ投入
 # cd /usr/share/doc/zabbix-server-mysql*/
 # zcat create.sql.gz | mysql -u zabbix -p zabbix


**Apache設定 [#fa9fc667]
***動作設定 [#e4048f76]
-/etc/httpd/conf/httpd.conf
 ServerName [FQDN]:80

***URL転送 [#v0ef5623]
-/var/www/html/index.html
 <!DOCTYPE html>
 <html lang="ja">
 <head> 
 <meta charset="uft-8">
 <script>
 setTimeout("location.href='/zabbix/'",0);
 </script>
 <title>redirect</title>
 </head>
 <body>
 </body>
 </html>

***設定の反映 [#zbb4e01c]
-設定の確認
 # service httpd configtest                                                                                              
 Syntax OK

-サービス起動
 # systemctl start httpd


**NET-SNMP設定 [#mc249500]
***snmptrapd [#z1babeef]
SNMPTrap受信ログを/var/log/snmpd/snmptrap.logへ出力する方式に変更。~
SNMPTrap受信時には、zabbix_trap_receiver.plに連携する方式に設定。~

-ログファイル格納ディレクトリ作成~
 # mkdir /var/log/snmpd

-/etc/sysconfig/snmptrapd
 OPTIONS="-Lsd -Lf /var/log/snmpd/snmptrap.log -p /var/run/snmptrapd.pid udp:162"

-/etc/snmp/snmptrapd.conf
 authCommunity log,execute public

-/etc/rsyslog.conf
 *.info;mail.none;authpriv.none;cron.none;local6.none                /var/log/messages
 
 local6.*                                                /var/log/snmpd/snmptrap.log

**Zabbix設定 [#r1d841f6]
以下は最低限の設定。要件に合わせてパラメータを調整する。~

***Zabbix Server [#f608ce53]
-/etc/zabbix/zabbix_server.conf
 LogFile=/var/log/zabbix/zabbix_server.log
 LogFileSize=0
 PidFile=/var/run/zabbix/zabbix_server.pid
 SocketDir=/var/run/zabbix
 DBName=zabbix
 DBUser=zabbix
 DBPassword=zabbix
 SNMPTrapperFile=/var/log/zabbix/zabbix_trap.log 
 Timeout=4
 AlertScriptsPath=/usr/lib/zabbix/alertscripts
 ExternalScripts=/usr/lib/zabbix/externalscripts
 LogSlowQueries=3000

***Zabbix Web [#b240477f]
-/etc/httpd/conf.d/zabbix.conf 
    <IfModule mod_php5.c>
        〜中略〜
        php_value date.timezone Asia/Tokyo
    </IfModule>

***Zabbix Agent [#i0ab3371]
-/etc/zabbix/zabbix_agentd.conf
 PidFile=/var/run/zabbix/zabbix_agentd.pid
 LogFile=/var/log/zabbix/zabbix_agentd.log
 LogFileSize=0
 EnableRemoteCommands=1
 Server=127.0.0.1
 ServerActive=127.0.0.1
 HostnameItem=system.hostname
 Include=/etc/zabbix/zabbix_agentd.d/*.conf

***サービス制御 [#v3384b0e]

-サービスの起動
 systemctl start snmptrapd
 systemctl start zabbix-server
 systemctl start zabbix-agent
 systemctl restart httpd

-自動起動設定
 systemctl enable httpd
 systemctl enable zabbix-server
 systemctl enable zabbix-agent
 systemctl enable snmptrapd
 systemctl enable mariadb

***ログローテーション [#s842104f]
-ファイル整理
 # cd /etc/logrotate.d/
 # mv zabbix-server zabbix
 # rm zabbix-agent

-/etc/logrotate.d/zabbix
 /var/log/zabbix/*.log {
        weekly
        rotate 12
        compress
        delaycompress
        missingok
        notifempty
        create 0664 zabbix zabbix
 }

-動作確認
 # logrotate -dv /etc/logrotate.conf 
 〜前略〜
 rotating pattern: /var/log/zabbix/*.log  weekly (12 rotations)
 〜後略〜

*参考情報 [#x68dbc9b]

トップ   編集 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS