How to / Install Zabbix-server (FreeBSD, PostgreSQL, Nginx)

    “Sooner or later, in the life of every system administrator, there comes a moment when the eyes and hands are no longer enough to keep track of all the servers, then and there there are some problems, and to solve them I really want to know what happened“ before that ”. And it is here that they come to the rescue - the great and terrible monitoring systems. ”( C ) xanf
    This situation has arisen for me, it’s always impossible to keep track of everything, writing a bunch of scripts is also not an option, but you must be able to quickly respond to various crashes, keep a history of some parameters, and just all sorts of “beautiful” graphics are to my heart. Therefore, I decided to put a monitoring system. Zabbix was selected. There are some recipes for using zabbix on the hub, but the installation topic is not covered. I do not pretend to be original, the described method is quite trivial and accumulates information from the Internet and official documentation. So. Myself and friends to help:
    Option to install Zabbix 1.8 with PostgreSQL DBMS and web muzzle via Nginx + PHP-FPM.
    UPD: Updated for version zabbix 3.4

    In this guide, all components are installed on one server. If necessary, you can use a separate server with the database, a separate server for the web interface and the zabbix server itself. In this case, the zabbix server will need to connect to the database, and the web interface will need to connect to the database and zabbix server.

    1. Install FreeBSD. (mc, bash, and the rest to taste)


    2. Install zabbix-server


    Initially, I tried to install on SQLite, but make believed that the system did not have SQLite above version 3.0.0, although ./configure from the source defined everything normally. The solution was in the sqlite3.h header file, which was not there where it was searched. But I did not bother because on the zabbix site, the documentation says that version zabbix 1.8 does not support SQLite. I decided to use PostgreSQL, simply because I worked with it more than with MySQL.
    cd / usr / ports / net-mgmt / zabbix-server
    make install clean (select Postgresql)

    3. Install PostgreSQL

    same version as postgres-client installed by zabbix-server.
    We look at the version:
    pkg_info | grep postgr
    postgresql-client-9.5.9 PostgreSQL database (client)
    cd / usr / ports / databases / postgresql95-server /
    make install clean

    Add postgresql_enable = "YES" to /etc/rc.conf

    4. Next, create the base for zabbix-server:


    I had a webmord operation error, she lacked the rights to the database, because I made the database and tables first from the user pgsql, and only then I started the user zabbix. I gave him full tables and webmord earned. In this article, I took this moment into account.
    su pgsql
    / usr / local / bin / initdb -D / usr / local / pgsql / data

    and start /usr/local/etc/rc.d/postgresql start
    su pgsql
    psql -d template1
    psql> create database zabbix;
    psql> CREATE USER zabbix WITH password 'tmppassword' (Create a user for the zabbix server)
    psql> GRANT ALL PRIVILEGES ON DATABASE zabbix to zabbix;
    psql> \ q
    cd / usr / local / share / zabbix34 / server / database / postgresql /
    cat schema.sql | psql -U zabbix zabbix
    psql -U zabbix zabbix <images.sql
    psql -U zabbix zabbix <data.sql

    (in version 1.8 the order was different. first data.sql then images.sql)

    5. Configure zabbix-server:


    cp /usr/local/etc/zabbix34/zabbix_server.conf.sample /usr/local/etc/zabbix34/zabbix_server.conf

    You must specify:
    Dbuser = zabbix, Dbpassword = tmppassword (user to connect to the database)
    DBSocket = / tmp / .s.PGSQL.5432 or Dbport = 5432 (by default there is for mysql)

    I use a connection through a socket (because I have everything on the same machine). The rest is left as is.
    Add the line zabbix_server_enable = "YES" to /etc/rc.conf and start
    echo 'zabbix_server_enable = "YES"' >> /etc/rc.conf
    /usr/local/etc/rc.d/zabbix_server start

    6. Install Zabbix-Frontend (webmord):


    cd / usr / ports / net-mgmt / zabbix-frontend
    make install clean

    Select the PGSQL option
    • Install PHP with support for FPM and Postgresql

    UPD: Current ports put this as a dependency on a webmord, but if you have something wrong then:
    cd / usr / ports / lang / php5
    make deinstall (if already installed but with different parameters)
    make config install clean (select PHP_FPM)
    cd / usr / ports / lang / php5-extensions
    make config install clean (select Postgresql)

    Here we will also work through the socket (if not, then leave everything as it is), config: /usr/local/etc/php-fpm.conf, edit:
    listen = /tmp/php-fpm.sock

    Add the line 'php_fpm_enable = "YES" to the file' /etc/rc.conf 'and start

    echo 'php_fpm_enable = "YES"' >> /etc/rc.conf
    service php-fpm start

    We check:
    sockstat | grep php

    The web muzzle is usually configured via Apache, but I did it on nginx. The config is simpler, eating less resources. I think he will cope with this task no worse than Apache.
    cd / usr / ports / www / nginx
    make install clean

    Edit the config /usr/local/etc/nginx/nginx.conf. I got this:
    http {
    include mime.types;
    default_type application / octet-stream;
    # Uncomment
    log_format main '$ remote_addr - $ remote_user [$ time_local] "$ request"'
    '$ status $ body_bytes_sent "$ http_referer"'
    '$ http_user_agent "" $ http_x_forwarded_for "';

    # We log attempts to access the web server (uncomment and change the path)
    access_log /var/log/nginx/access.log main;

    sendfile on;
    keepalive_timeout 65;
    # Turn on
    gzip on compression ;

    server {
    listen 80;
    server_name ZABBIX_SERVER_IP_OR_NAME; # About this below
    # Access log only to zabbix-server 'webmord

    # Folder with webmord files
    location / {
    root / usr / local / www / zabbix;
    index index.html index.php;
    }

    error_page 500 502 503 504 /50x.html;
    location = /50x.html {
    root / usr / local / www / nginx-dist;
    }
    # We are friends with Nginx and PHP-FPM
    location ~ \ .php $ {
    root html;
    fastcgi_pass unix: /tmp/php-fpm.sock; # or 127.0.0.1:9000 if the php-fpm
    fastcgi_param SCRIPT_FILENAME / usr / local / www / zabbix $ fastcgi_script_name config did not correct;
    fastcgi_param QUERY_STRING $ query_string;
    include fastcgi_params;
    }

    #Deny access to zabbix files
    location ~ * / (?: api | conf | include) / {
    return 301 ht_p: //zabbix.local/index.php;
    }

    }

    About server_name. First I left localhost there. Everything worked, but when I tried to sort by column (for example, a list of hosts), the URL was built from localhost. I struggled with this rake for a long time climbing in zabbix configs and codes, but to no avail. I drew attention to this parameter when writing an article and it worked. Can someone explain why so, if not difficult? :)
    I also changed the paths to the log files, so we create a directory for the log files:
    mkdir / var / log / nginx
    chown www: www / var / log / nginx

    We write the line nginx_enable = "YES" in /etc/rc.conf and start:
    /usr/local/etc/rc.d/nginx start

    Next, go to the browser in ht_p: // zabbix_server_ip and continue the installation using the wizards:
    At step 3, the PHP parameters are checked, they are corrected in the /usr/local/etc/php.ini file.
    If there is no file, you can copy it from php.ini. development or php.ini.production
    I rules:
    memory_limit = 128M
    post_max_size = 20M
    upload_max_filesize = 16M
    max_execution_time = 300
    max_input_time = 300
    date.timezone = "Asia / Irkutsk"

    After restart php-fpm
    /usr/local/etc/rc.d/php-fpm restart

    In step 4, select PostgreSQL and enter the user and password to access the zabbix database (in our case, zabbix \ tmppassword). We leave the server address localhost, tk. PostgreSQL is installed on the same machine as the webmord, and by default accepts connections from localhost. UPD1: In order for the webmord to connect to PostgreSQL through the socket too, instead of localhost we write / tmp / (path to the folder with .s.PGSQL.5432). Or in the file /usr/local/www/zabbix/conf/zabbix.conf.php we write $ DB ["SERVER"] = '/ tmp'; Now (optional) tcp / ip connection to PostgreSQL can be completely disabled.
    In step 7, click to download the config and create the file /usr/local/www/zabbix/conf/zabbix.conf.php with the contents of the downloaded file

    Security issues have not been addressed. Basically this is restricting access to configuration files, especially where passwords are located, restricting web server access to folders and access to the database from the outside. If there are gross flaws in the configurations (almost all configurations are used by default), please point me to this.
    Considering installing zabbix-agent and setting up device monitoring is beyond the scope of this memo.
    PS: I do not have much experience and knowledge in setting up and maintaining the components used, so I will be glad to comments and recommendations.

    Also popular now: