Zabbix - cgi and mysql: Difference between revisions

From Alpine Linux
(Updated documentation)
(A few errors corrected . Checked with Zabbix 4.2)
(35 intermediate revisions by 11 users not shown)
Line 1: Line 1:
[[Category:monitoring]]
The purpose of this document is to assist in installing the Zabbix server software and Zabbix agent on the Alpine Linux operating system. Instructions on how to configure and use Zabbix - as well as many useful tutorials - can be found at http://www.zabbix.com.


{{Note|The minimum required version of Alpine Linux required to install Zabbix is Alpine 2.2. this guide has been updated to zabbix 3.0}}


== Zabbix Monitoring Solution ==


The purpose of this document is to assist in installing the Zabbix server software and Zabbix agent on the Alpine Linux operating system. Instructions on how to configure and use Zabbix - as well as many useful tutorials - can be found at http://www.zabbix.com.
= Install Lighttpd, and PHP =


{{Note|Currently, Zabbix will only work as expected when running on an Alpine Linux system updated from the latest snapshots of the Edge repository. It will be properly supported with the next major version stable release (Alpine 2.2).}}
{{:Setting Up Lighttpd With FastCGI}}


== Install Lighttpd, and PHP ==
For Zabbix you will have to install following two extra packages otherwise Zabbix will not run.
1.  php7-mbstring  2. php7-pgsq


{{:Setting Up Lighttpd With FastCGI}}
To Install these two packages 
{{Cmd|apk add php7-mbstring php7-pgsq}}
= Configure PostgreSQL =


== Configure PostgreSQL ==
Install PostgreSQL


Setup and configure PostgreSQL:
{{Cmd|apk add postgresql postgresql-client}}


apk add postgresql postgresql-client
Now configure PostgreSQL:
/etc/init.d/postgresql setup
{{Cmd|/etc/init.d/postgresql setup
/etc/init.d/postgresql start
/etc/init.d/postgresql start
rc-update add postgresql
rc-update add postgresql}}


== Install Zabbix ==
= Install Zabbix =


apk add zabbix
{{Cmd|apk add zabbix zabbix-pgsql zabbix-webif zabbix-setup}}


Now we need to set up the zabbix database. Substitute '*********' in the example below for a real password:
Now we need to set up the zabbix database. Substitute '*********' in the example below for a real password:


<pre>
{{Cmd|<nowiki>psql -U postgres
psql –U postgres
postgres=# create user zabbix with password '*********';
postgres=# create user zabbix with password '*********';
postgres=# create database zabbix owner zabbix;
postgres=# create database zabbix owner zabbix;
postgres=# \q
postgres=# \q
cd /usr/share/zabbix/dbms/create/
cd /usr/share/zabbix/database/postgresql
cat postgresql.sql | psql -U zabbix zabbix
cat schema.sql | psql -U zabbix zabbix
cd data/
cat images.sql | psql -U zabbix zabbix
cat data.sql | psql -U zabbix zabbix
cat data.sql | psql -U zabbix zabbix</nowiki>}}
cat images_pgsql.sql | psql -U zabbix zabbix
</pre>


Create a softlink for the Zabbix web-frontend files:
Create a softlink for the Zabbix web-frontend files:


ln -s /usr/share/webapps/zabbix /var/www/localhost/htdocs/zabbix
{{Cmd|rm /var/www/localhost/htdocs -R
ln -s /usr/share/webapps/zabbix /var/www/localhost/htdocs}}


Edit PHP configuration to satisfy some zabbix requirements. Edit /etc/php/php.ini and configure the following values at least:
Edit PHP configuration to satisfy some zabbix requirements. Edit /etc/php/php.ini and configure the following values at least:
Line 51: Line 52:
post_max_size = 32M
post_max_size = 32M
upload_max_filesize = 16M
upload_max_filesize = 16M
max input time = 600
max_input_time = 600
memory limit = 256M
memory_limit = 256M
</pre>
</pre>
Also comment  (doc_root & user_dir )  by putting # before these. 


Configure the following entries in /etc/zabbix/zabbix_server.conf, where DBPassword is the password chosen for the database above:
Configure the following entries in /etc/zabbix/zabbix_server.conf, where DBPassword is the password chosen for the database above:
Line 68: Line 71:


DBPassword=*********
DBPassword=*********
FpingLocation=/usr/sbin/fping
</pre>
</pre>


Start Zabbix server:
Start Zabbix server:


rc-update add zabbix-server
{{Cmd|rc-update add zabbix-server
/etc/init.d/zabbix-server start
/etc/init.d/zabbix-server start}}
 
Fix permissions on conf directory.
 
{{Cmd|chown -R lighttpd /usr/share/webapps/zabbix/conf}}


You should now be able to browse to the Zabbix frontend: http://yourservername/zabbix.
You should now be able to browse to the Zabbix frontend: http://yourservername/.
 
or
 
You should now be able to browse to the Zabbix setup frontend: http://yourserverip/instal.php.


Follow the setup instructions to configure Zabbix, supplying the database information used above.
Follow the setup instructions to configure Zabbix, supplying the database information used above.


== Install Zabbix Agent on Monitored Servers ==
After setup, login using: Login name: '''Admin''' Password:'''zabbix'''. (as described at http://www.zabbix.com/documentation/1.8/manual/installation)
 
Finally, Zabbix requires special permissions to use the fping binary.
 
{{Cmd|chmod u+s /usr/sbin/fping}}
 
= Install Zabbix Agent on Monitored Servers =


Zabbix can monitor almost any operating system, including Alpine Linux hosts. Complete the following steps to install the Zabbix agent on Alpine Linux.
Zabbix can monitor almost any operating system, including Alpine Linux hosts. Complete the following steps to install the Zabbix agent on Alpine Linux.
{{Note|Support to allow zabbix-agentd to view running processes on Alpine Linux has been added since linux-grsec-2.6.35.9-r2. Please ensure you have that kernel installed prior to attempting to run zabbix-agentd.}}
Ensure that the readproc group exists (support added since alpine-baselayout-2.0_rc1-r1), by adding the following line to /etc/group:
{{Cmd|readproc:x:30:zabbix}}


Install the agent package:
Install the agent package:


apk add zabbix-agent
{{Cmd|apk add zabbix-agent}}


Edit the /etc/zabbix/zabbix_agentd.conf file and configure at least the following option:
Edit the /etc/zabbix/zabbix_agentd.conf file and configure at least the following option:
<pre>
Server=<ip or hostname of zabbix server>
Hostname=<ip or hostname of zabbix agent>
ListenPort=10050
</pre>
Start the zabbix-agent:
{{Cmd|rc-update add zabbix-agentd
/etc/init.d/zabbix-agentd start}}
In case you want to monitor using SNMP agent on remote machines you have to add these packages on zabbix server:
{{Cmd|apk add net-snmp net-snmp-tools}}
And add these packages on remote machines:
{{Cmd|apk add net-snmp }}


Server=<ip or hostname of zabbix server>
= Optional: Crash course in adding hosts, checks, and notifications =


Start the zabbix-agent:
''Note:'' This is optional since it's not specific to Alpine Linux, but I wanted a couple notes for how to perform a simple check on a server that doesn't have the agent installed on it, and be notified on state changes.
 
Administration -> Media Types -> Email
* Setup server, helo, email from address
 
Administration -> Users
* Setup each user who'll get notified, make sure they have media type "Email" added with their address
 
Configuration -> Hosts -> Create host
* In Linux Servers hostgroup
* Define dns name, ip, connect by IP
* If the machine is a simple networking device that will only be monitored using SNMP, add it to Template_SNMPv2_Device, and you're done.
 
Configuration -> Templates -> Create template
* Give it a name (Template_Alpine_Linux_Infra_HTTP)
* In Templates group
 
Configuration -> Templates -> Template_Alpine_Linux_Infra_HTTP -> Items
* Create Item
* Host: Template_Alpine_Linux_Infra_HTTP
* Description: HTTP Basic Check
* Type: Simple_check
* Key: http,80
 
Configuration -> Templates -> Template_Alpine_Linux_Infra_HTTP -> Triggers
* Create Trigger
* Name: "HTTP Trigger"
* Expression: {Template_Alpine_Linux_Infra_HTTP:http,80.last(0)}#1
* Severity: High
 
Configuration -> Actions ->
* Create Action
* name: Email notifications
* Event source: triggers
* Default Subject: add "{HOST.DNS}:" to the beginning
* Default message: add "{HOST.DNS}:" to the beginning
* Conditions: make host have to be from "Linux Servers" hostgroup, and Template_Alpine_Linux_Infra_HTTP:HTTP trigger" is not 1
* Email affected users


rc-update add zabbix-agentd
[[Category:Monitoring]]
/etc/init.d/zabbix-agentd start
[[Category:PHP]]
[[Category:SQL]]

Revision as of 05:07, 12 September 2019

The purpose of this document is to assist in installing the Zabbix server software and Zabbix agent on the Alpine Linux operating system. Instructions on how to configure and use Zabbix - as well as many useful tutorials - can be found at http://www.zabbix.com.

Note: The minimum required version of Alpine Linux required to install Zabbix is Alpine 2.2. this guide has been updated to zabbix 3.0


Install Lighttpd, and PHP

Basic Installation

For installing the additional packages first activate community packages and update the package index

Install the required packages:

# apk add lighttpd php82 fcgi php82-cgi

Configure Lighttpd

Edit lighttpd.conf (/etc/lighttpd/lighttpd.conf) and uncomment the line:

Contents of /etc/lighttpd/lighttpd.conf

... include "mod_fastcgi.conf" ...

Edit mod_fastcgi.conf (/etc/lighttpd/mod_fastcgi.conf), find and change /usr/bin/php-cgi to /usr/bin/php-cgi82.

Contents of /etc/lighttpd/mod_fastcgi.conf

... "bin-path" => "/usr/bin/php-cgi82" # php-cgi ...

Start lighttpd service and add it to default runlevel

# rc-service lighttpd start # rc-update add lighttpd default

For Zabbix you will have to install following two extra packages otherwise Zabbix will not run. 1. php7-mbstring 2. php7-pgsq

To Install these two packages

apk add php7-mbstring php7-pgsq

Configure PostgreSQL

Install PostgreSQL

apk add postgresql postgresql-client

Now configure PostgreSQL:

/etc/init.d/postgresql setup /etc/init.d/postgresql start rc-update add postgresql

Install Zabbix

apk add zabbix zabbix-pgsql zabbix-webif zabbix-setup

Now we need to set up the zabbix database. Substitute '*********' in the example below for a real password:

psql -U postgres postgres=# create user zabbix with password '*********'; postgres=# create database zabbix owner zabbix; postgres=# \q cd /usr/share/zabbix/database/postgresql cat schema.sql | psql -U zabbix zabbix cat images.sql | psql -U zabbix zabbix cat data.sql | psql -U zabbix zabbix

Create a softlink for the Zabbix web-frontend files:

rm /var/www/localhost/htdocs -R ln -s /usr/share/webapps/zabbix /var/www/localhost/htdocs

Edit PHP configuration to satisfy some zabbix requirements. Edit /etc/php/php.ini and configure the following values at least:

Max_execution_time = 600
Expose_php = off
Date.timezone = <insert your timezone here>
post_max_size = 32M
upload_max_filesize = 16M
max_input_time = 600
memory_limit = 256M

Also comment (doc_root & user_dir ) by putting # before these.

Configure the following entries in /etc/zabbix/zabbix_server.conf, where DBPassword is the password chosen for the database above:

DBName=zabbix

# Database user

DBUser=zabbix

# Database password
# Comment this line if no password used

DBPassword=*********

FpingLocation=/usr/sbin/fping

Start Zabbix server:

rc-update add zabbix-server /etc/init.d/zabbix-server start

Fix permissions on conf directory.

chown -R lighttpd /usr/share/webapps/zabbix/conf

You should now be able to browse to the Zabbix frontend: http://yourservername/.

or

You should now be able to browse to the Zabbix setup frontend: http://yourserverip/instal.php.

Follow the setup instructions to configure Zabbix, supplying the database information used above.

After setup, login using: Login name: Admin Password:zabbix. (as described at http://www.zabbix.com/documentation/1.8/manual/installation)

Finally, Zabbix requires special permissions to use the fping binary.

chmod u+s /usr/sbin/fping

Install Zabbix Agent on Monitored Servers

Zabbix can monitor almost any operating system, including Alpine Linux hosts. Complete the following steps to install the Zabbix agent on Alpine Linux.

Note: Support to allow zabbix-agentd to view running processes on Alpine Linux has been added since linux-grsec-2.6.35.9-r2. Please ensure you have that kernel installed prior to attempting to run zabbix-agentd.

Ensure that the readproc group exists (support added since alpine-baselayout-2.0_rc1-r1), by adding the following line to /etc/group:

readproc:x:30:zabbix

Install the agent package:

apk add zabbix-agent

Edit the /etc/zabbix/zabbix_agentd.conf file and configure at least the following option:

Server=<ip or hostname of zabbix server>
Hostname=<ip or hostname of zabbix agent>
ListenPort=10050

Start the zabbix-agent:

rc-update add zabbix-agentd /etc/init.d/zabbix-agentd start

In case you want to monitor using SNMP agent on remote machines you have to add these packages on zabbix server:

apk add net-snmp net-snmp-tools

And add these packages on remote machines:

apk add net-snmp


Optional: Crash course in adding hosts, checks, and notifications

Note: This is optional since it's not specific to Alpine Linux, but I wanted a couple notes for how to perform a simple check on a server that doesn't have the agent installed on it, and be notified on state changes.

Administration -> Media Types -> Email

  • Setup server, helo, email from address

Administration -> Users

  • Setup each user who'll get notified, make sure they have media type "Email" added with their address

Configuration -> Hosts -> Create host

  • In Linux Servers hostgroup
  • Define dns name, ip, connect by IP
  • If the machine is a simple networking device that will only be monitored using SNMP, add it to Template_SNMPv2_Device, and you're done.

Configuration -> Templates -> Create template

  • Give it a name (Template_Alpine_Linux_Infra_HTTP)
  • In Templates group

Configuration -> Templates -> Template_Alpine_Linux_Infra_HTTP -> Items

  • Create Item
  • Host: Template_Alpine_Linux_Infra_HTTP
  • Description: HTTP Basic Check
  • Type: Simple_check
  • Key: http,80

Configuration -> Templates -> Template_Alpine_Linux_Infra_HTTP -> Triggers

  • Create Trigger
  • Name: "HTTP Trigger"
  • Expression: {Template_Alpine_Linux_Infra_HTTP:http,80.last(0)}#1
  • Severity: High

Configuration -> Actions ->

  • Create Action
  • name: Email notifications
  • Event source: triggers
  • Default Subject: add "{HOST.DNS}:" to the beginning
  • Default message: add "{HOST.DNS}:" to the beginning
  • Conditions: make host have to be from "Linux Servers" hostgroup, and Template_Alpine_Linux_Infra_HTTP:HTTP trigger" is not 1
  • Email affected users