How to install/setup Zabbbix

## Setup zabbix repository

    # rpm -ivh --httpproxy <PROXY_SERVER> --httpport <PROXY_SERVER_PORT> http://repo.zabbix.com/zabbix/2.4/rhel/7/x86_64/zabbix-release-2.4-1.el7.noarch.rpm

    # cat /etc/yum.repo.d/zabbix.repo
    [zabbix]
    name=Zabbix Official Repository - $basearch
    baseurl=http://repo.zabbix.com/zabbix/2.4/rhel/7/$basearch/
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX

    [zabbix-non-supported]
    name=Zabbix Official Repository non-supported - $basearch
    baseurl=http://repo.zabbix.com/non-supported/rhel/7/$basearch/
    enabled=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-ZABBIX
    gpgcheck=1


## Install PKGs

#### zabbix server

    # yum install zabbix-server-mysql

        ====================================================================================
         Package                      Arch    Version           Repository             Size
        ====================================================================================
        Installing:
         zabbix-server-mysql          x86_64  2.4.5-1.el7       zabbix                1.5 M
        Installing for dependencies:
         OpenIPMI-libs                x86_64  2.0.19-11.el7     base                  501 k
         OpenIPMI-modalias            x86_64  2.0.19-11.el7     base                   15 k
         fping                        x86_64  3.10-1.el7        zabbix-non-supported   40 k
         iksemel                      x86_64  1.4-2.el7.centos  zabbix-non-supported   49 k
         libtool-ltdl                 x86_64  2.4.2-20.el7      base                   49 k
         net-snmp                     x86_64  1:5.7.2-20.el7    base                  319 k
         net-snmp-agent-libs          x86_64  1:5.7.2-20.el7    base                  698 k
         net-snmp-libs                x86_64  1:5.7.2-20.el7    base                  745 k
         perl-Data-Dumper             x86_64  2.145-3.el7       base                   47 k
         unixODBC                     x86_64  2.3.1-10.el7      base                  413 k
         zabbix                       x86_64  2.4.5-1.el7       zabbix                159 k
         zabbix-server                x86_64  2.4.5-1.el7       zabbix                 21 k

        Transaction Summary
        ====================================================================================
        Install  1 Package (+12 Dependent packages)

#### zabbix web

    # yum install zabbix-web-mysql

        =============================================================================
         Package                      Arch    Version              Repository   Size
        =============================================================================
        Installing:
         zabbix-web-mysql             noarch  2.4.5-1.el7          zabbix       14 k
        Installing for dependencies:
         apr                          x86_64  1.4.8-3.el7          base        103 k
         apr-util                     x86_64  1.5.2-6.el7          base         92 k
         dejavu-fonts-common          noarch  2.33-6.el7           base         64 k
         dejavu-sans-fonts            noarch  2.33-6.el7           base        1.4 M
         fontpackages-filesystem      noarch  1.44-8.el7           base        9.9 k
         httpd                        x86_64  2.4.6-31.el7.centos  base        2.7 M
         httpd-tools                  x86_64  2.4.6-31.el7.centos  base         79 k
         libXpm                       x86_64  3.5.10-5.1.el7       base         52 k
         libzip                       x86_64  0.10.1-8.el7         base         48 k
         mailcap                      noarch  2.1.41-2.el7         base         31 k
         php                          x86_64  5.4.16-36.el7_1      updates     1.4 M
         php-bcmath                   x86_64  5.4.16-36.el7_1      updates      56 k
         php-cli                      x86_64  5.4.16-36.el7_1      updates     2.7 M
         php-common                   x86_64  5.4.16-36.el7_1      updates     563 k
         php-gd                       x86_64  5.4.16-36.el7_1      updates     126 k
         php-mbstring                 x86_64  5.4.16-36.el7_1      updates     503 k
         php-mysql                    x86_64  5.4.16-36.el7_1      updates      99 k
         php-pdo                      x86_64  5.4.16-36.el7_1      updates      97 k
         php-xml                      x86_64  5.4.16-36.el7_1      updates     124 k
         t1lib                        x86_64  5.1.2-14.el7         base        166 k
         zabbix-web                   noarch  2.4.5-1.el7          zabbix      3.3 M

        Transaction Summary
        =============================================================================
        Install  1 Package (+21 Dependent packages)

#### MariaDB

    # yum install mariadb-server

        ==========================================================================
         Package                      Arch    Version           Repository   Size
        ==========================================================================
        Installing:
         mariadb-server               x86_64  1:5.5.41-2.el7_0  base         11 M
        Installing for dependencies:
         mariadb                      x86_64  1:5.5.41-2.el7_0  base        8.9 M
         perl-Compress-Raw-Bzip2      x86_64  2.061-3.el7       base         32 k
         perl-Compress-Raw-Zlib       x86_64  1:2.061-4.el7     base         57 k
         perl-DBD-MySQL               x86_64  4.023-5.el7       base        140 k
         perl-DBI                     x86_64  1.627-4.el7       base        802 k
         perl-IO-Compress             noarch  2.061-2.el7       base        260 k
         perl-Net-Daemon              noarch  0.48-5.el7        base         51 k
         perl-PlRPC                   noarch  0.2020-14.el7     base         36 k

        Transaction Summary
        ==========================================================================
        Install  1 Package (+8 Dependent packages)

#### [option] Zabbix agent

    # yum install zabbix-agent

        ============================================================
         Package             Arch    Version      Repository   Size
        ============================================================
        Installing:
         zabbix-agent        x86_64  2.4.5-1.el7  zabbix      181 k

        Transaction Summary
        ============================================================
        Install  1 Package


## MariaDB configuration

#### Set default character as utf8

    # vi /etc/my.cnf.d/server.cnf

    # diff /etc/my.cnf.d/server.cnf.org /etc/my.cnf.d/server.cnf
    12a13,16
    > character-set-server = utf8
    > collation-server = utf8_general_ci
    > skip-character-set-client-handshake
    > innodb_file_per_table

#### Start MariaDB service

    # systemctl enable mariadb
    ln -s '/usr/lib/systemd/system/mariadb.service' '/etc/systemd/system/multi-user.target.wants/mariadb.service'

    # systemctl start mariadb

    # systemctl list-units --type=service | grep mariadb
    mariadb.service                    loaded active running MariaDB database server


#### Create database

    # mysql -uroot
    MariaDB [(none)]> create database zabbix;
    Query OK, 1 row affected (0.00 sec)

    MariaDB [(none)]> grant all privileges on zabbix.* to zabbix@localhost identified by 'password';
    Query OK, 0 rows affected (0.00 sec)

    MariaDB [(none)]> flush privileges;
    Query OK, 0 rows affected (0.00 sec)

    MariaDB [(none)]> exit
    Bye
    #

#### Import initial schema and data

    # ls -l /usr/share/doc/zabbix-server-mysql-2.4.5/create/
    total 2988
    -rw-r--r-- 1 root root  972942 Apr 23 12:13 data.sql
    -rw-r--r-- 1 root root 1978341 Apr 22 16:56 images.sql
    -rw-r--r-- 1 root root  104816 Apr 22 16:57 schema.sql

    #  mysql -uroot zabbix < /usr/share/doc/zabbix-server-mysql-2.4.5/create/schema.sql
    #  mysql -uroot zabbix < /usr/share/doc/zabbix-server-mysql-2.4.5/create/images.sql
    #  mysql -uroot zabbix < /usr/share/doc/zabbix-server-mysql-2.4.5/create/data.sql

## Apache configuration

Change timezone

    # vi /etc/httpd/conf.d/zabbix.conf

    # diff /etc/httpd/conf.d/zabbix.conf.org /etc/httpd/conf.d/zabbix.conf
    17c17
    <     # php_value date.timezone Europe/Riga
    ---
    >     php_value date.timezone Asia/Tokyo


## Zabbix configuration

Change password

    # vi /etc/zabbix/zabbix_server.conf

    # diff /etc/zabbix/zabbix_server.conf.org /etc/zabbix/zabbix_server.conf
    106a107
    > DBPassword=password


## Start services

#### Zabbix server

    # systemctl start zabbix-server
    # systemctl enable zabbix-server
    ln -s '/usr/lib/systemd/system/zabbix-server.service' '/etc/systemd/system/multi-user.target.wants/zabbix-server.service'

#### Apache

    # systemctl start httpd
    # systemctl enable httpd
    ln -s '/usr/lib/systemd/system/httpd.service' '/etc/systemd/system/multi-user.target.wants/httpd.service'

#### Zabbix agent (option)

    # systemctl start zabbix-agent
    # systemctl enable zabbix-agent
    ln -s '/usr/lib/systemd/system/zabbix-agent.service' '/etc/systemd/system/multi-user.target.wants/zabbix-agent.service'

## Firewall configuration

* Zabbix Server  --(tcp:10050)-->  Zabbix Agent
* Zabbix Agent   --(tcp:10051)-->  Zabbix Server


##### Initial state

    # systemctl list-units --type=service | grep firewalld
    firewalld.service                  loaded active running firewalld - dynamic firewall daemon

    # firewall-cmd --zone=public --list-services
    ssh

##### Add policy

    # firewall-cmd --add-port=10050/tcp --zone=public --permanent
    success
    # firewall-cmd --add-port=10051/tcp --zone=public --permanent
    success
    # firewall-cmd --add-service=http --zone=public --permanent
    success

##### Restart firewalld and enable the policy

    # systemctl restart firewalld
    # firewall-cmd --reload
    success

##### check the policy

    # firewall-cmd --zone=public --list-services
    http ssh

    # firewall-cmd --zone=public --list-port
    10050/tcp 10051/tcp

    # cat /etc/firewalld/zones/public.xml
    <?xml version="1.0" encoding="utf-8"?>
    <zone>
      <short>Public</short>
      <description>For use in public areas. You do not trust the other computers on networks to not harm your computer. Only selected incoming connections are accepted.</description>
      <service name="http"/>
      <service name="ssh"/>
      <port protocol="tcp" port="10050"/>
      <port protocol="tcp" port="10051"/>
    </zone>



## Access to Zabbix UI

http://x.x.x.x/zabbix/

default login account

* id : Admin
* pw : zabbix

## Environment

##### OS

    # cat /etc/redhat-release
    CentOS Linux release 7.1.1503 (Core)


##### Apache

    # httpd -v
    Server version: Apache/2.4.6 (CentOS)
    Server built:   Mar 12 2015 15:07:19

#### Zabbix

    # /usr/sbin/zabbix_server -V
    Zabbix server v2.4.5 (revision 53282) (21 April 2015)
    Compilation time: Apr 23 2015 03:14:46


##### MariaDB

    # mysqladmin -u root -p'password' version | grep version
    Server version      5.5.41-MariaDB
    Protocol version    10

## Reference

[https://www.zabbix.com/documentation/2.4/manual/installation][link-01]

[link-01]:https://www.zabbix.com/documentation/2.4/manual/installation