Zabbix + MariaDB + Nginx

Hello there my Friend,

This blog is a personal documentation of my work. So if you like it or you have any suggestions or questions, leave them in the comment section.

The idea: Monitoring my server + my raspberry Pi machine at home (temp + availability because of power shortages).
The hardware: At first I used a cheap VPS (1core, 2G ram, 15G hdd, 100mbps ) which was totally fine. Now I’m documenting this and redoing it on a low end box (2core, 2G ram, 500G hdd, 100mbps) just because of the migration.
OS of choice: Debian GNU/Linux 8 (jessie), just because I like it.
Http server of choice: Nginx, cuz I wanted to learn it.
DB of choice: MariaDB, I wanted to learn it and like the ‘idea’ of it.

 

1) Get Zabbix packages

It’s explained well enough here – just do the “installing repository configuration package” and continue with:

apt install zabbix-frontend-php nginx-full php5-fpm zabbix-server-mysql php5-mysql php5 mariadb-client-10.0 mariadb-client-core-10.0 mariadb-server mariadb-server-10.0 mariadb-server-core-10.0 

2) Prepare the database

as root:

 mysql_secure_installation 

and follow the questions that appear.

After that we have to create a database and user that will operate on that DB.

login to the mysql shell as root:

 mysql -uroot -p 

than we shall create the database, I’ll call mine zabbix (it’s easier to use the scripts afterwards)


CREATE DATABASE zabbix character set utf8 collate utf8_bin;

Than we create the user that will operate on the database. Mine is called zabbix and will be able to log to the database from the host ‘localhost’. The user is identified by a password set in the ‘password’ value.


CREATE USER ‘zabbix’@’localhost’ IDENTIFIED BY ‘password’;

and now we’ll allow the user ‘zabbix’ to have all possible privileges on the database ‘zabbix’


GRANT ALL PRIVILEGES ON zabbix.* TO 'zabbix'@'localhost' IDENTIFIED BY 'password'; 

now we can ‘quit;’ the database shell and create the database structure using the script provided by the Zabbix crew!

As root we do such a command:


zcat create.sql.gz | mysql -uzabbix -p<password> zabbix

This will read the config file from the gz and pass it to the pipe. The mysql command is quite simple

-u is for user

-p is for password (you can leave it blank and the prompt will ask you for it or fill it if you’re shure no one is peeking 😉 )

zabbix is the database name that will be populated

3) The Http server

My conf.d for zabbix:


server {
listen 80;
root /var/www;
index index.html index.php;
server_name <name_of_your_server>;

access_log /var/log/nginx/access.log;
gzip on;
gzip_min_length 1000;
gzip_types text/plain application/xml text/css text/js text/xml application/x-javascript text/javascript application/json application/xml+rss;
gzip_comp_level 4;
gzip_proxied any;

tcp_nopush on;
tcp_nodelay on;

#keepalive_timeout 0;
keepalive_timeout 10;
fastcgi_read_timeout 10m;
proxy_read_timeout 10m;
client_header_timeout 10m;
client_body_timeout 10m;
send_timeout 10m;
large_client_header_buffers 16 32k;

location /{
root /var/www/html;
}

location /zabbix {
# try_files $uri $uri/ /index.html = 404;

index index.php index.html index.htm;
#try_files $uri $uri/ index.php;
expires 30d;
}

#error_page 500 502 503 504 /50x.html;
#location = /50x.html {
# root /usr/share/nginx/html;
#}

location ~* \.php$ {
expires off;
if (!-f $request_filename) { return 404; }
fastcgi_split_path_info ^(.+\.php)(/.+)$;
#fastcgi_pass unix:/var/run/php-fpm/php-fpm.sock;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_index index.php;
fastcgi_read_timeout 300;
include fastcgi_params;
}
}

4) Edit the php.ini file

In Debian that file is located in: /etc/php5/fpm/php.ini

Set such values

 
<pre>post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Continent/City
always_populate_raw_post_data = -1 

and restart php5-fpm

 systemctl restart php5-fpm 

5) I’ve copied the zabbix directory to /var/www/zabbix:

cp -R /usr/share/zabbix/ /var/www/zabbix 

6) After that install the server providing the data (database name, database username, database password, database host)

7) The default login credentials are: Admin / password

 

Cheers,
Wizard

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s