📜 ⬆️ ⬇️

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

“In the life of every system administrator, sooner or later there comes a time when the eye and the hands are no longer enough to keep track of all the servers, then there are some problems there, and to solve them, I really want to know what happened before that. And it is here that they come to the rescue — great and terrible monitoring systems. ”( C ) xanf
This situation has arisen with me, it is impossible to monitor everything all the time, writing a bunch of scripts is also not an option, but you need to be able to respond quickly to various failures, to keep the history of some parameters, well, just any “beautiful” graphics for my heart. Therefore, I decided to put a monitoring system. Zabbix has been selected. On Habré there are some recipes for using zabbix, but the installation theme is not covered. I do not pretend to originality, the described method is rather trivial and accumulates information from the Internet and official documentation. So. For your memory and friends for help:
Zabbix 1.8 installation option with PostgreSQL DBMS and webmord via Nginx + PHP-FPM.
UPD: Updated for zabbix 3.4

In this guide, all components are installed on one server. If necessary, you can use a separate server with a database, a separate server for the web interface and the zabbix server itself. In this case, the zabbix server will need a connection to the database, and the web interface will need a connection to the database and the 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 thought that there was no SQLite higher than version 3.0.0 in the system, although ./configure from the sources determined everything was fine. The solution was in the sqlite3.h header file, which was not where it was searched for. But I did not bother. On the zabbix website, the documentation states that 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 (choose Postgresql)

3. Install PostgreSQL

the same version as postgres-client, which was installed by zabbix-server.
See 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 a base for zabbix-server:


I had a webmord work error, it did not have enough rights to the database, because I made the base and tables first from the user pgsql, and only then started the user zabbix. I gave him full tables and webmord earned. In this article, I took into account this moment.
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 user for 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. Configuring 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 for mysql)

I use a socket connection (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

Choose the PGSQL option
• Install PHP with FPM and Postgresql support

UPD: Current ports set it as a dependency to the webmord, but if you have something wrong:
cd / usr / ports / lang / php5
make deinstall (if already installed but with different parameters)
make config install clean (choose PHP_FPM)
cd / usr / ports / lang / php5-extensions
make config install clean (choose Postgresql)

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

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

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

Checking:
sockstat | grep php

Webmordum is usually set up via Apache, but I did it on nginx. Config easier, eats less resources. I think he will cope with this task not worse than Apache.
cd / usr / ports / www / nginx
make install clean

We rule 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"';
# Logging attempts to access the web server (uncomment and change the path)
access_log /var/log/nginx/access.log main;
sendfile on;
keepalive_timeout 65;
# Enable compression
gzip on;
server {
listen 80;
server_name ZABBIX_SERVER_IP_OR_NAME; # About this below
# Access log only to webmord zabbix-server
access_log /var/log/nginx/zabbix.access.log main;
# 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 php-fpm config was not corrected
fastcgi_param SCRIPT_FILENAME / usr / local / www / zabbix $ fastcgi_script_name;
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. At first I left localhost there. Everything worked, but when I tried to sort by a column (for example, a list of hosts), the URL was built from localhost. I have been struggling with these rakes for a long time in zabbix configs and codes, but without success. Drew attention to this option when writing an article and it all worked. Can someone explain why, if not difficult? :)
I also changed the paths to files with logs, so we create a directory for files with logs:
mkdir / var / log / nginx
chown www: www / var / log / nginx

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

Next, go to the browser on ht_p: // zabbix_server_ip and continue the installation on wizards:
At step 3, the PHP parameters are checked, they are corrected in the /usr/local/etc/php.ini file
If the file does not exist, you can copy it from php.ini.development or php.ini.production
I ruled:
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, we select PostgreSQL and enter the user and password to access the zabbix database (in our case zabbix \ tmppassword). Server address is left localhost, because 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 via a socket too, instead of localhost we write / tmp / (the path to the folder with .s.PGSQL.5432). Or in the /usr/local/www/zabbix/conf/zabbix.conf.php file, we write $ DB ["SERVER"] = '/ tmp'; Now (optional) the connection to PostgreSQL via tcp / ip can be turned off altogether.
At step 7, download the config file and create the file /usr/local/www/zabbix/conf/zabbix.conf.php with the contents of the downloaded file

Security issues were not considered. This is mainly a restriction of access to configuration files, especially where passwords are located, restriction of web server access to folders and access to the database from the outside. If there are gross configuration flaws (almost all configurations are used by default), please indicate this to me.
Considering the installation of 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 happy with comments and recommendations.

Source: https://habr.com/ru/post/139165/


All Articles