See www.zabbix.com for the official Zabbix site.

Docs/howto/high availability Zabbix Frontend

From Zabbix.org
Jump to: navigation, search

Introduction

This instruction is recommended for large installations and large number of connections per unit of time to your Zabbix frontend.
If you are having problems with performance of your web server, then perhaps this is what you need. This article is advisory in nature.
All changes to your production system must be tested and approved platform for testing. All the changes you make on your own risk.

About Google Pagespeed Module

PageSpeed improves web page latency and bandwidth usage by changing the resources on that web page to implement web performance best practices.
Each optimization is implemented as a custom filter in PageSpeed, which are executed when the HTTP server serves the website assets.
Some filters simply alter the HTML content, and other filters change references to CSS, JavaScript, or images to point to more optimized versions.

PageSpeed implements custom optimization strategies for each type of asset referenced by the website,
to make them smaller, reduce the loading time, and extend the cache lifetime of each asset.
These optimizations include combining and minifying JavaScript and CSS files, inlining small resources, and others.
PageSpeed also dynamically optimizes images by removing unused meta-data from each file, resizing the images to specified dimensions,
and re-encoding images to be served in the most efficient format available to the user.

PageSpeed ships with a set of core filters designed to safely optimize the content of your site without affecting the look or behavior of your site.
In addition, it provides a number of more advanced filters which can be turned on by the site owner to gain higher performance improvements.

PageSpeed can be deployed and customized for individual web sites, as well as being used by large hosting providers and CDNs to help their users improve performance of their sites,
lower the latency of their pages, and decrease bandwidth usage.

From Google

Build ngx_pagespeed From Source

To install our dependencies on RedHat, CentOS, and Fedora, run:

sudo yum install gcc-c++ pcre-dev pcre-devel zlib-devel make

On Ubuntu or Debian, run:

sudo apt-get install build-essential zlib1g-dev libpcre3 libpcre3-dev

Then download ngx_pagespeed:

cd ~
wget https://github.com/pagespeed/ngx_pagespeed/archive/release-1.6.29.7-beta.zip
unzip release-1.6.29.7-beta.zip
cd ngx_pagespeed-release-1.6.29.7-beta/
wget https://dl.google.com/dl/page-speed/psol/1.6.29.7.tar.gz
tar -xzvf 1.6.29.7.tar.gz # expands to psol/

Download and build nginx with support for pagespeed:

cd ~
# check http://nginx.org/en/download.html for the latest version
wget http://nginx.org/download/nginx-1.4.1.tar.gz
tar -xvzf nginx-1.4.1.tar.gz
cd nginx-1.4.1/
./configure --add-module=$HOME/ngx_pagespeed-release-1.6.29.7-beta
make
sudo make install

Configuration

With this instalation Nginx I use php-fpm interpreter.

Template of nginx.conf config without standalone settings:

user  nginx;

# worker_processes = number of cores
# grep -c '^processor' /proc/cpuinfo
 
worker_processes 24;
pid /var/run/nginx.pid;

events {
        worker_connections 4000;
        multi_accept on;

        use epoll;
}

http {

      	open_file_cache max=200000 inactive=20s;
        open_file_cache_valid 30s;
        open_file_cache_min_uses 2;
        open_file_cache_errors on;

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 30;
        keepalive_requests 1000;
        reset_timedout_connection on;
        client_body_timeout 10;
        send_timeout 2;
        types_hash_max_size 2048;
        # server_tokens off;

        server_names_hash_bucket_size 64;
        server_name_in_redirect on;

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

        ##
	# Logging Settings
        ##

	access_log off;
        error_log /var/log/nginx/error.log;

        # Proxy Settings
        port_in_redirect off;
        proxy_cache_path  /dev/shm/nginx levels=1:2 keys_zone=czone:16m max_size=32m inactive=10m;
        proxy_temp_path /dev/shm/nginx/tmp;
        proxy_cache_key "$scheme$host$request_uri";
        proxy_cache_valid  200 302 10m;


        #GZIP SETTINGS

        gzip on;
        gzip_min_length 10240;
        gzip_proxied expired no-cache no-store private auth;
        gzip_types text/plain text/css text/xml text/javascript application/x-javascript application/xml;
        gzip_disable "MSIE [1-6]\.";

        ##
	# Virtual Host Configs
        ##

	include /etc/nginx/conf.d/*.conf;
        include /etc/nginx/sites-enabled/*;
}

And see fastcgi.conf config:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING	  $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE	  $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI	  $document_uri;
fastcgi_param  DOCUMENT_ROOT	  $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

For virtual hosts I use this config:

server {
    server_name zabbix.domain www.zabbix.domain;
    root /var/www/zabbix;
    listen 80;
    index index.html index.htm index.php;

        #Google Pagespeed

        pagespeed on;
        pagespeed FileCachePath /var/cache/google-pagespeed;
        pagespeed LowercaseHtmlNames on;
        pagespeed XHeaderValue "Powered by Google Pagespeed";
        pagespeed MaxSegmentLength 250;
        pagespeed CombineAcrossPaths off;
        pagespeed RewriteLevel CoreFilters;
        pagespeed EnableFilters combine_heads,move_css_above_scripts,move_css_to_head,extend_cache,rewrite_images;
        pagespeed EnableFilters inline_preview_images;
        pagespeed EnableFilters rewrite_javascript,canonicalize_javascript_libraries,resize_mobile_images,remove_comments,collapse_whitespace,lazyload_images;
        pagespeed EnableFilters elide_attributes;
        pagespeed EnableFilters combine_javascript;
        pagespeed EnableFilters extend_cache;
        pagespeed EnableFilters local_storage_cache;


        #Google Pagespeed Location

        location ~ "\.pagespeed\.([a-z]\.)?[a-z]{2}\.[^.]{10}\.[^.]+" { add_header "" ""; }
        location ~ "^/ngx_pagespeed_static/" { }
        location ~ "^/ngx_pagespeed_beacon$" { }
        location /ngx_pagespeed_statistics { allow 127.0.0.1; deny all; }
        location /ngx_pagespeed_message { allow 127.0.0.1; deny all; }

        #Disable access to important zabbix locations

        location ~* ^/(api|include|conf)($|\/) {deny all;}

        #Location directive

        location / { try_files $uri $uri/ /index.php?q=$uri&$args; }

        location ~* ^.+\.(jpg|jpeg|gif|png|ico|pdf)$ {
                root /var/www/zabbix;
                access_log off;
                expires max;
                add_header Cache-Control private;
        }

	location ~ \.php$ {
            fastcgi_buffers 8 256k;
            fastcgi_buffer_size 128k;
            fastcgi_intercept_errors on;
            include fastcgi_params;
            fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
            fastcgi_pass 127.0.0.1:9000;
        }

}

PageSpeed Filters Reference

For this config I use:

  • combine_heads - Combines multiple <head> elements found in document into one.
  • move_css_above_scripts - Moves CSS elements above script tags.
  • move_css_to_head - Moves CSS elements into the head directive.
  • extend_cache - Extends cache lifetime of CSS, JS, and image resources that have not otherwise been optimized, by signing URLs with a content hash.
  • rewrite_images - Optimizes images, re-encoding them, removing excess pixels, and inlining small images.
  • inline_preview_images - Uses inlined low-quality images as placeholders which will be replaced with original images once the web page is loaded.
  • rewrite_javascript - Rewrites Javscript files to remove excess whitespace and comments.
  • canonicalize_javascript_libraries - Redirects JavaScript libraries to a JavaScript hosting service of Zabbix uses in wan.
  • resize_mobile_images - Works just like inline_preview_images, but uses smaller placeholder images and only serves them to mobile browsers.
  • remove_comments - Removes comments in HTML files (but not in inline JavaScript or CSS).
  • collapse_whitespace - Removes excess whitespace in HTML files (avoiding pre, script, style, and textarea html selectors).
  • lazyload_images - Loads images when they become visible in the client viewport.
  • elide_attributes - Removes attributes which are not significant according to the HTML spec.
  • combine_javascript - Combines multiple script elements into one.
  • local_storage_cache - Cache inlined resources in HTML5 local storage.

Detail function reference here PageSpeed Filters

In The End

This article is incomplete and soon I did complement and expand. This article presents a productive configuration for a Web server.
You will integrate multiple Web servers via balancer that also significantly reduce the load on them.
This configuration is universal and suitable for any high load web service.


Send comments and ideas to audio<at>live.ru