📜 ⬆️ ⬇️

Zabbix 2.2 riding on nginx + php-fpm and mariadb



I want to note that this instruction was born in the process of implementing Zabbix in the walls of Acronis .
In the process of examination and the research I conducted, she proved her right to life and safely serves us faithfully and day by day.

We face a nontrivial task, to achieve maximum performance of the well-known monitoring system zabbix.
Among the many articles on the Internet, there are many descriptions of typical installations of this system. I will describe in detail how to make zabbix work faster.
As a base system, I will use CentOS 6.4. As well as many I love Debian, Gentoo and all other distributions, but this article is for CentOS.
')
Everything I need to do, I will write in detail and step by step, and begin with the basic configuration of our CentOS


# Turn off SELINUX
sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config

# Customize time zone
ln -sf /usr/share/zoneinfo/Europe/Moscow /etc/localtime

# Run time synchronization
yum install ntp -y
chkconfig ntpd on
/etc/init.d/ntpd stop
ntpdate 0.ru.pool.ntp.org 1.ru.pool.ntp.org 2.ru.pool.ntp.org 3.ru.pool.ntp.org
/etc/init.d/ntpd start


# Install auxiliary components
yum install wget nano wget ntpdate -y

# These repositories should be, there are a lot of packages that are not in the basic repositories, we will find here
wget dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
wget rpms.famillecollet.com/enterprise/remi-release-6.rpm
sudo rpm -Uvh remi-release-6 * .rpm epel-release-6 * .rpm
rm * .rpm -f


# This repository is useful to us, but we will turn it off by default.
rpm --import dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt
cd / tmp
wget dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.x86_64.rpm && rpm -ivh rpmforge-release-0.3.6-1.el5.rf. x86_64.rpm


# Turn off, we will use through --enablerepo = rpmforge
sed -i 's/enabled = 1/enabled = 0/g' /etc/yum.repos.d/rpmforge.repo

# And this is a gem for web systems and not only, there really is a lot of things that an administrator needs in his work. Musthave
wget -q -O - www.atomicorp.com/installers/atomic | sh

# We put useful software
yum install nano mc screen sudo nscd htop ntp zip unzip pigz iotop sysstat lsof strace atop multitail -y
yum --enablerepo = rpmforge install htop -y

# Update the system
yum update -y

Now let's move on to installing the zabbix itself and the components it needs:

SERVER

# Install the official zabbix repository for centos
rpm -ivh repo.zabbix.com/zabbix/2.2/rhel/6/x86_64/zabbix-release-2.2-1.el6.noarch.rpm

# Killing all old MySQL components, This will remove MySQL!
yum remove php-* mysql-* MariaDB-* -y

# Install mariadb from the atomic repository
yum install mariadb-server mariadb-devel mariadb-client -y

# Install many components and modules that are needed for zabbix operation
yum install ntp php php-mysql php-mbstring php-mcrypt rpm-build gcc mariadb-devel openssl-devel cyrus-sasl-devel pkgconfig zlib-devel pggconfig zlib-devel pgg-devel openldap-devel libtool gdbm-devel pam-devel gamin-devel php-fpm php-cli php-gd php-imap php-ldap php-odbc php-pear php-xml php-xmlrpc php-pecl-apc hp-magpierss php-snmp php- tidy spawn-fcgi openssl perl-TimeDate webalizer perl-DateTime-Format-HTTP perl-DateTime-Format-Builder perl-TimeDate libevent-devel php-pecl-memcache nginx cronie cronie-anacron crontabs postfix sysstat -y


# Install zabbix yourself
yum install zabbix-server-mysql zabbix-web-mysql zabbix-agent


# We configure MariaDB, you need to bring its config to this form (these config are designed for 16GB of RAM on the server)
[root @ zabbix ~] nano /etc/my.cnf

[mysqld]
datadir = / var / lib / mysql
socket = / var / lib / mysql / mysql.sock
# Disabling symbolic-links
symbolic-links = 0
default_storage_engine = InnoDB
innodb_file_per_table = 1
#
#
# network
connect_timeout = 60
wait_timeout = 28800
max_connections = 200
max_allowed_packet = 512M
max_connect_errors = 1000

# limits
tmp_table_size = 512M
max_heap_table_size = 256M
table_cache = 1024

# logs
log_error = /var/log/mysql/mysql-error.log
#slow_query_log_file = /var/log/mysql/mysql-slow.log
#slow_query_log = 1
#long_query_time = 20

# innodb
default_storage_engine = InnoDB
innodb_file_per_table = 1
innodb_status_file = 1
innodb_additional_mem_pool_size = 128M
innodb_buffer_pool_size = 12G # The value of this parameter should be no more than 60% of the RAM on the server
innodb_flush_method = O_DIRECT
innodb_io_capacity = 2000
innodb_flush_log_at_trx_commit = 2
innodb_support_xa = 0
innodb_log_buffer_size = 128M

# experimental
innodb_stats_update_need_lock = 0

# other stuff
event_scheduler = 1
query_cache_type = 0
query_cache_size = 536870912
join_buffer_size = 1M
query_cache_limit = 2M
sort_buffer_size = 2M
read_buffer_size = 2M
read_rnd_buffer_size = 4M
key_buffer = 256M
key_buffer_size = 64M
open_files_limit = 100000
thread_cache_size = 100

[mysqld_safe]
log-error = / var / log / mysqld.log
pid-file = / var / run / mysqld / mysqld.pid

#
# include all files from the config directory
#
! includedir /etc/my.cnf.d


# Add mysql to autoload
chkconfig mysqld on && /etc/init.d/mysqld restart

# Add php-fpm to startup
chkconfig --levels 235 php-fpm on
/etc/init.d/php-fpm start


# Remove the default configs nginx
rm /etc/nginx/conf.d/default.conf -f
rm /etc/nginx/conf.d/virtual.conf -f

# Create zabbix database
mysql -e 'CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;'
mysql -e 'grant all privileges on zabbix. * to zabbix @ localhost identified by "9c9yUiUuros";'
mysql -e 'flush privileges;'


# Fill in standard schemes for zabbix database
mysql zabbix </usr/share/doc/zabbix-server-mysql-2.2.0/create/schema.sql
mysql zabbix </usr/share/doc/zabbix-server-mysql-2.2.0/create/images.sql
mysql zabbix </usr/share/doc/zabbix-server-mysql-2.2.0/create/data.sql


# Add iptables rules
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 10050 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 10051 -j ACCEPT
iptables -A INPUT -p udp -m state --state NEW -m udp --dport 10050 -j ACCEPT
iptables -A INPUT -p udp -m state --state NEW -m udp --dport 10051 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
service iptables save


# Make the necessary changes to the configuration of php
[root @ zabbix ~] nano /etc/php.ini

post_max_size = 16M
max_execution_time = 300
max_input_time = 300
date.timezone = Europe / Moscow


# We give the configuration of zabbix to the following form:
egrep -v '^ # | ^ $' /etc/zabbix/zabbix_server.conf

[root @ zabbix ~] nano /etc/zabbix/zabbix_server.conf
LogFile = / var / log / zabbix / zabbix_server.log
LogFileSize = 0
PidFile = / var / run / zabbix / zabbix_server.pid
DBName = zabbix
DBUser = zabbix
DBUser = zabbix
DBPassword = 9c9yUiUuros
DBSocket = / var / lib / mysql / mysql.sock
SNMPTrapperFile = / var / log / snmptt / snmptt.log
AlertScriptsPath = / usr / lib / zabbix / alertscripts
ExternalScripts = / usr / lib / zabbix / externalscripts


# Add zabbix server to startup
chkconfig zabbix-server on

# We will slightly change the standard configuration of nginx, we will give the config to this form:
[root @ zabbix ~] nano /etc/nginx/nginx.conf
user nginx;
worker_processes 10;
pid /var/run/nginx.pid;

events {
worker_connections 1024;
use epoll;

multi_accept on;

}

error_log /var/log/nginx/error.log warn;

http {
include /etc/nginx/mime.types;
default_type application / octet-stream;

log_format main '$ remote_addr - $ remote_user [$ time_local] "$ request"'
'$ status $ body_bytes_sent "$ http_referer"'
'"$ http_user_agent" "$ http_x_forwarded_for"';

access_log /var/log/nginx/access.log main;

connection_pool_size 256;
client_header_buffer_size 4k;
client_max_body_size 100m;
large_client_header_buffers 8 8k;
request_pool_size 4k;
output_buffers 1 32k;
postpone_output 1460;
proxy_max_temp_file_size 0;
gzip on;
gzip_min_length 1024;
gzip_proxied any;
gzip_proxied expired no-cache no-store private auth;
gzip_types text / plain text / xml application / xml application / x-javascript text / javascript text / css text / json;
gzip_comp_level 8;
gzip_disable "MSIE [1-6] \. (?!. * SV1)";

sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 75 20;
server_names_hash_max_size 8192;
ignore_invalid_headers on;
server_name_in_redirect off;

proxy_buffer_size 8k;
proxy_buffers 32 4k;
proxy_connect_timeout 1000;
proxy_read_timeout 12000;
proxy_send_timeout 12000;
proxy_cache_path / var / cache / nginx levels = 2 keys_zone = pagecache: 5m inactive = 10m max_size = 50m;
real_ip_header X-Real-IP;

proxy_set_header Host $ host;
proxy_set_header X-Real-IP $ remote_addr;
proxy_set_header X-Forwarded-For $ proxy_add_x_forwarded_for;

allow all;

include /etc/nginx/conf.d/*.conf;
}


# We configure nginx to work with zabbix and php-fpm
[root @ zabbix ~] # nano /etc/nginx/conf.d/zabbix.conf
server {
listen 80;
server_name name ;
server_name is another name ;

location / {
root / usr / share / zabbix;
index index.php index.html index.htm;
}

location ~ \ .php $ {
root / usr / share / zabbix;
try_files $ uri = 404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;

fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}

server {
listen 80;
server_name _;

location / {
root / usr / share / zabbix;
index index.php index.html index.htm;
}

location ~ \ .php $ {
root / usr / share / zabbix;
try_files $ uri = 404;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
include fastcgi_params;
}

# deny access to .htaccess files, if Apache's document root
# concurs with nginx's one
#
location ~ /\.ht {
deny all;
}
}


# Remove apache from autoload
chkconfig --levels 235 httpd off
/etc/init.d/httpd stop


# Add nginx to autoload
chkconfig --levels 235 nginx on
/etc/init.d/nginx start


With this simple method, we get a high-performance installation of zabbix.

The article would not be complete if I had not told about the installation of zabbix-proxy and zabbix-agent, it is assumed that the steps of the basic system setup (at the very beginning of the article) we have already passed

PROXY

# Install the official zabbix repository for centos
rpm -ivh repo.zabbix.com/zabbix/2.0/rhel/6/x86_64/zabbix-release-2.0-1.el6.noarch.rpm

# Remove old software
yum remove zabbix-proxy- * -y
yum remove mysql * mysql- *


# Install mariadb from the atomic repository
yum install mariadb-server mariadb-devel mariadb-client -y

# After removing mysql components, important components could be removed
yum install -y cronie cronie-anacron crontabs postfix sysstat

# Actually zabbix itself from the official repository
yum install zabbix zabbix-agent zabbix-proxy-mysql zabbix-proxy -y

Consider the case that zabbix-proxy need to be put on something else, for example fedora 14

mkdir / root / zabbix && cd / root / zabbix
wget repo.zabbix.com/zabbix/2.0/rhel/6/x86_64/zabbix-2.0.9-1.el6.x86_64.rpm
wget repo.zabbix.com/zabbix/2.0/rhel/6/x86_64/zabbix-agent-2.0.9-1.el6.x86_64.rpm
wget repo.zabbix.com/zabbix/2.0/rhel/6/x86_64/zabbix-proxy-2.0.9-1.el6.x86_64.rpm
wget repo.zabbix.com/zabbix/2.0/rhel/6/x86_64/zabbix-proxy-mysql-2.0.9-1.el6.x86_64.rpm
wget repo.zabbix.com/zabbix/2.0/rhel/6/x86_64/zabbix-get-2.0.9-1.el6.x86_64.rpm
rpm -Uhv * .rpm


# Set up MariaDB, you need to add parameters
[root @ zabbix ~] nano /etc/my.cnf

default_storage_engine = InnoDB
innodb_file_per_table = 1


# Add zabbix to autoload
chkconfig zabbix-proxy on
chkconfig zabbix-agent on
chkconfig mysqld on && /etc/init.d/mysqld start


# Create a base
mysql -e 'CREATE DATABASE zabbix CHARACTER SET utf8 COLLATE utf8_bin;'
mysql -e 'grant all privileges on zabbix. * to zabbix @ localhost identified by "lNZrKeZASv0L";'
mysql -e 'flush privileges;'


# Fill in standard schemes for zabbix database
mysql zabbix </usr/share/doc/zabbix-server-mysql-2.0.9/create/schema.sql
mysql zabbix </usr/share/doc/zabbix-server-mysql-2.0.9/create/images.sql


# Add iptables rules
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 10050 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 10051 -j ACCEPT
iptables -A INPUT -p udp -m state --state NEW -m udp --dport 10050 -j ACCEPT
iptables -A INPUT -p udp -m state --state NEW -m udp --dport 10051 -j ACCEPT
service iptables save


# We configure zabbix-proxy itself
sed -i "s / ^ Server =. * / Server = server address-zabbix / g" /etc/zabbix/zabbix_proxy.conf
sed -i "s / ^ Hostname =. * / Hostname = name-this-proxy-who-pointed-zabbix-server / g" /etc/zabbix/zabbix_proxy.conf
sed -i "s / ^ DBName =. * / DBName = zabbix / g" /etc/zabbix/zabbix_proxy.conf
echo ProxyMode = 0 >> /etc/zabbix/zabbix_proxy.conf
echo ProxyLocalBuffer = 1 >> /etc/zabbix/zabbix_proxy.conf
echo ProxyLocalBuffer = ProxyOfflineBuffer = 100 >> /etc/zabbix/zabbix_proxy.conf
echo HousekeepingFrequency = 1r = 100 >> /etc/zabbix/zabbix_proxy.conf
echo DataSenderFrequency = 300 >> /etc/zabbix/zabbix_proxy.conf
echo StartPollers = 5 >> /etc/zabbix/zabbix_proxy.conf
echo StartIPMIPollers = 1 >> /etc/zabbix/zabbix_proxy.conf
echo StartPollersUnreachable = 1 >> /etc/zabbix/zabbix_proxy.conf
echo StartTrappers = 5 >> /etc/zabbix/zabbix_proxy.conf
echo StartHTTPPollers = 1 >> /etc/zabbix/zabbix_proxy.conf
echo StartDBSyncers = 4 >> /etc/zabbix/zabbix_proxy.conf
echo Timeout = 10 >> /etc/zabbix/zabbix_proxy.conf
echo FpingLocation = / usr / sbin / fping >> /etc/zabbix/zabbix_proxy.conf
echo Fping6Location = / usr / sbin / fping6 >> /etc/zabbix/zabbix_proxy.conf
echo DebugLevel = 3 >> /etc/zabbix/zabbix_proxy.conf
echo StartDiscoverers = 10 >> /etc/zabbix/zabbix_proxy.conf
echo DBPassword = lNZrKeZASv0L >> /etc/zabbix/zabbix_proxy.conf


# Checking the zabbix-proxy configuration file
egrep -v '^#|^$' /etc/zabbix/zabbix_proxy.conf

# Go
/etc/init.d/zabbix-proxy start


AGENT, obviously we will deploy it through chef or puppet but for the completeness of the material

# Install the official zabbix repository for centos
rpm -ivh repo.zabbix.com/zabbix/2.0/rhel/6/x86_64/zabbix-release-2.0-1.el6.noarch.rpm

# Install the agent from the official repository
yum install zabbix zabbix-agent -y

or if you are not very fresh fedora
rpm -Uhv repo.zabbix.com/zabbix/2.0/rhel/6/x86_64/zabbix-2.0.9-1.el6.x86_64.rpm

# Give zabbix user sudo rights and create folders for our future scripts
usermod -s / bin / bash zabbix
echo 'zabbix ALL = (ALL) NOPASSWD: ALL' >> / etc / sudoers
sed -i 's / Defaults \ requireti / # Defaults \ requiretty / g' / etc / sudoers
mkdir / etc / zabbix / scripts /
chmod 750 / etc / zabbix / scripts /


# Add zabbix-agent to startup
chkconfig zabbix-agent on

# Add iptables rules
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 10050 -j ACCEPT
iptables -A INPUT -p tcp -m state --state NEW -m tcp --dport 10051 -j ACCEPT
iptables -A INPUT -p udp -m state --state NEW -m udp --dport 10050 -j ACCEPT
iptables -A INPUT -p udp -m state --state NEW -m udp --dport 10051 -j ACCEPT
service iptables save


# Setting up our zabbix-agent
sed -i "s / ^ Server =. * / Server = zabbix-sever-or-proxy / g address" /etc/zabbix/zabbix_agentd.conf
sed -i "s / ^ ServerActive =. * / ServerActive = zabbix-sever-or-proxy / g address" /etc/zabbix/zabbix_agentd.conf
sed -i "s / ^ Hostname =. * / Hostname =` hostname` / g "/etc/zabbix/zabbix_agentd.conf
echo EnableRemoteCommands = 1 >> /etc/zabbix/zabbix_agentd.conf
echo LogRemoteCommands = 1 >> /etc/zabbix/zabbix_agentd.conf
echo Timeout = 30 >> /etc/zabbix/zabbix_agentd.conf


# Done, watch logs
/etc/init.d/zabbix-agent restart && tail -f -n 100 /var/log/zabbix/zabbix_*.log

Thank you for your attention, if you find this material interesting, I will be glad to share many more and more!

HAPRoxy for Percona or Galera on CentOS. Its configuration and monitoring in Zabbix

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


All Articles