sistemas:suap:zabbix

host: pgsql-suap.ifce.edu.br

Primeiramente foi feito uma verificação para saber qual versão do Ubuntu Server estava rodando na máquina:

monitoramento@pgsql-suap:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.2 LTS
Release:        16.04
Codename:       xenial

Para instalar o Zabbix Agent é necessário adicionar o repositório do Zabbix. O Zabbix configurado na máquina zabbix.ifce.edu.br está na versão 3.2 logo devemos baixar o arquivo .deb encontrado no site https://repo.zabbix.com/zabbix/3.2/ubuntu/pool/main/z/zabbix-release/ referente a versão xenial

monitoramento@pgsql-suap:~$ cd /tmp/
monitoramento@pgsql-suap:/tmp$ wget https://repo.zabbix.com/zabbix/3.2/ubuntu/pool/main/z/zabbix-release/zabbix-release_3.2-1+xenial_all.deb
monitoramento@pgsql-suap:/tmp$ sudo dpkg -i zabbix-release_3.2-1+xenial_all.deb 

Nesse momento ocorreu um erro ao tentar adicionar o repositório pois o diretório /boot estava com a capacidade máxima. Foi necessária fazer a limpeza do diretório /boot para prosseguir a instalação

Primeiro foi alterado o usuário para root e verificado a versão do kernel que tá sendo utilizada:

monitoramento@pgsql-suap:~$ uname -r
4.4.0-62-generic

Com essa informação podemos liberar os arquivos do diretório:

root@pgsql-suap:/boot# ls -lah
total 144M
drwxr-xr-x  4 root root 4,0K Jul 25 08:49 .
drwxr-xr-x 23 root root 4,0K Jul 25 08:44 ..
-rw-r--r--  1 root root 1,2M Jan 18  2017 abi-4.4.0-62-generic
-rw-r--r--  1 root root 1,2M Jun 26 16:45 abi-4.4.0-83-generic
-rw-r--r--  1 root root 1,2M Jul 18 12:00 abi-4.4.0-87-generic
-rw-r--r--  1 root root 186K Jan 18  2017 config-4.4.0-62-generic
-rw-r--r--  1 root root 186K Jun 26 16:45 config-4.4.0-83-generic
-rw-r--r--  1 root root 186K Jul 18 12:00 config-4.4.0-87-generic
drwxr-xr-x  5 root root 1,0K Jul 25 08:48 grub
-rw-r--r--  1 root root  37M Jul 25 08:43 initrd.img-4.4.0-62-generic
-rw-r--r--  1 root root  37M Jul 25 08:45 initrd.img-4.4.0-83-generic
-rw-r--r--  1 root root  37M Jul 25 08:49 initrd.img-4.4.0-87-generic
drwx------  2 root root  12K Mar  9 13:01 lost+found
-rw-------  1 root root 3,7M Jan 18  2017 System.map-4.4.0-62-generic
-rw-------  1 root root 3,8M Jun 26 16:45 System.map-4.4.0-83-generic
-rw-------  1 root root 3,8M Jul 18 12:00 System.map-4.4.0-87-generic
-rw-------  1 root root 6,8M Jan 18  2017 vmlinuz-4.4.0-62-generic
-rw-------  1 root root 6,8M Jun 26 16:45 vmlinuz-4.4.0-83-generic
-rw-------  1 root root 6,8M Jul 18 12:00 vmlinuz-4.4.0-87-generic

OBS: Isso é apenas um esboço do que realmente tinha lá pois já havia sido liberado o espaço.

Em seguida, utilizando o comando:

root@pgsql-suap:/boot# cat /dev/null > arquivo

Onde arquivo é um dos arquivos do diretório /boot e não pode ser o da versão atual, no caso, 4.4.0-62-generic

Exemplo:

root@pgsql-suap:/boot# cat /dev/null > initrd.img-4.4.0-87-generic

Com o espaço máximo possível liberado, pode se usar os seguintes comandos:

apt-get install -f
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d' | xargs sudo apt-get -y purge

Como resultado o espaço foi liberado e é possível agora continuar a instalação do Zabbix Agent

root@pgsql-suap:~# df -lh | grep boot
Sist. Arq.                        Tam. Usado Disp. Uso% Montado em
/dev/sda1                         464M  153M  283M  36% /boot
root@pgsql-suap:/tmp# cd /tmp/
root@pgsql-suap:/tmp# dpkg -i zabbix-release_3.2-1+xenial_all.deb
root@pgsql-suap:/tmp# apt update
root@pgsql-suap:/tmp# apt install zabbix-agent zabbix-get

OBS: Durante a atualização do Zabbix-Agent o PostgreSQL foi atualizado acidentalmente para a versão 9.5.7

monitoramento@pgsql-suap:~$ psql --version
psql (PostgreSQL) 9.5.7

Depois de terminar a instalação do Zabbix Agent é necessário editar o arquivo de configuração /etc/zabbix/zabbix_agentd.conf e atualizar as seguintes linhas:

...

### Option: Server
#       List of comma delimited IP addresses (or hostnames) of Zabbix servers.
#       Incoming connections will be accepted only from the hosts listed here.
#       If IPv6 support is enabled then '127.0.0.1', '::127.0.0.1', '::ffff:127.0.0.1' are treated equally.
#
# Mandatory: no
# Default:
# Server=

Server=zabbix.ifce.edu.br,127.0.0.1

...

### Option: ServerActive
#       List of comma delimited IP:port (or hostname:port) pairs of Zabbix servers for active checks.
#       If port is not specified, default port is used.
#       IPv6 addresses must be enclosed in square brackets if port for that host is specified.
#       If port is not specified, square brackets for IPv6 addresses are optional.
#       If this parameter is not specified, active checks are disabled.
#       Example: ServerActive=127.0.0.1:20051,zabbix.domain,[::1]:30051,::1,[12fc::1]
#
# Mandatory: no
# Default:
# ServerActive=

ServerActive=127.0.0.1,zabbix.ifce.edu.br

...

### Option: HostnameItem
#       Item used for generating Hostname if it is undefined. Ignored if Hostname is defined.
#       Does not support UserParameters or aliases.
#
# Mandatory: no
# Default:

HostnameItem=system.hostname

...

### Option: Include
#       You may include individual files or all files in a directory in the configuration file.
#       Installing Zabbix will create include directory in /usr/local/etc, unless modified during the compile time.
#
# Mandatory: no
# Default:
# Include=

Include=/etc/zabbix/zabbix_agentd.d/*.conf

...

O pacote utilizado encontra-se em https://github.com/lesovsky/zabbix-extensions/tree/master/files/postgresql e foi instalado como é mostrado a seguir:

root@pgsql-suap:~# cd /opt
root@pgsql-suap:/opt# mkdir zabbix
root@pgsql-suap:/opt# cd zabbix/
root@pgsql-suap:/opt/zabbix# git clone https://github.com/lesovsky/zabbix-extensions
root@pgsql-suap:/opt/zabbix# cd zabbix-extensions/files/postgresql/
root@pgsql-suap:/opt/zabbix/zabbix-extensions/files/postgresql# ls
postgresql.conf  postgresql-extended-template.xml  README.md

É preciso então copiar o arquivo de configuração postgresql.conf para o diretório /etc/zabbix/zabbix_agentd.d/ e reiniciar o serviço do zabbix-agent

root@pgsql-suap:/opt/zabbix/zabbix-extensions/files/postgresql# cp postgresql.conf /etc/zabbix/zabbix_agentd.d/
root@pgsql-suap:/opt/zabbix/zabbix-extensions/files/postgresql# service zabbix-agent restart
root@pgsql-suap:~# cd /etc/postgresql/9.5/main/
root@pgsql-suap:/etc/postgresql/9.5/main# ls
environment  pg_ctl.conf  pg_hba.conf  pg_ident.conf  postgresql.conf  start.conf

É importante editar as seguintes linhas linhas:

...

# "local" is for Unix domain socket connections only
local   all             all                                     trust

# IPv4 local connections:
host    all             all             127.0.0.1/32            trust

...

host    all             all             zabbix.ifce.edu.br      md5

...

O arquivo pg_hba.conf é pra ficar assim:

# PostgreSQL Client Authentication Configuration File
# ===================================================

# Use PEER apenas para conexoes locais em estacoes de trabalho
# Use TRUST apenas para conexões locais em estacoes de trabalho e sistemas monousuários
# Para os demais use MD5
# Nao use PASSWORD ou CRYPT

local   all            postgres                                 peer

# "local" is for Unix domain socket connections only
local   all             all                                     trust

# IPv4 local connections:
host    all             all             127.0.0.1/32            trust

# IPv6 local connections:
host    all             all             ::1/128                 md5

# Rede interna IFCE

host    all             all             10.0.0.0/8              md5
host    all             all             200.17.33.0/24          md5
host    all             all             201.20.97.250/30        md5
host    all             all             200.129.11.0/24         md5
host    all             all             200.129.48.0/24         md5
host    all             all             200.129.16.0/24         md5
host    all             all             200.129.17.0/24         md5
host    all             all             200.17.36.0/24          md5
host    all             all             zabbix.ifce.edu.br      md5
# Allow replication connections from localhost, by a user with the
# replication privilege.
#local   replication     postgres                                peer
#host    replication     postgres        127.0.0.1/32            md5
#host    replication     postgres        ::1/128                 md5

É necessário reiniciar o serviço do PostgreSQL

root@pgsql-suap:~# service postgresql restart
root@pgsql-suap:~# service postgresql status
● postgresql.service - PostgreSQL RDBMS
   Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
   Active: active (exited) since Ter 2017-07-25 10:53:17 BRT; 24h ago
  Process: 17869 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 17869 (code=exited, status=0/SUCCESS)
    Tasks: 0
   Memory: 0B
      CPU: 0
   CGroup: /system.slice/postgresql.service

Jul 25 10:53:17 pgsql-suap systemd[1]: Starting PostgreSQL RDBMS...
Jul 25 10:53:17 pgsql-suap systemd[1]: Started PostgreSQL RDBMS.

Para testar se o monitoramento está OK use o seguinte comando:

root@pgsql-suap:~# zabbix_get -s 127.0.0.1 -k pgsql.ping['-h 127.0.0.1 -p 5432 -U postgres -d postgres']

Primeiro é necessário importar o template postgresql-extended-template.xml para o Zabbix, encontrado no site https://github.com/lesovsky/zabbix-extensions/tree/master/files/postgresql

Configuration → Templates → Import

Criando um Host para monitorar o pgsql-suap.ifce.edu.br

Configuration → Hosts → Create Host

Linkar o Host aos templates:

Criando as Macros para monitoramento do PostgreSQL:

  • sistemas/suap/zabbix.txt
  • Última modificação: 2021/08/25 10:33
  • (edição externa)