zabbix 安装配置

zabbix

https://www.zabbix.com/download_sources

编译

Documentation: Zabbix 6.4 Installation from sources

1
2
3
4
5
6
❯ sudo addgroup --system --quiet zabbix

❯ sudo adduser --quiet --system --disabled-login --ingroup zabbix --home /var/lib/zabbix --no-create-home zabbix


./configure --prefix=/opt/zabbix --enable-server --enable-agent --with-mysql --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --with-openipmi

Running make install will by default install the daemon binaries (zabbix_server, zabbix_agentd, zabbix_proxy) in /usr/local/sbin and the client binaries (zabbix_get, zabbix_sender) in /usr/local/bin.

缺依赖

https://packages.debian.org/search?searchon=contents&keywords=libssl.so

依赖库文件
各种报错缺依赖情况
configure: error: Unable to use libevent (libevent check failed)
configure: error: Curl library not found

cs@debian:apt-get install -y libevent-dev cs@debian:apt install -y libghc-curl-dev

No package 'libxml-2.0' found checking for xmlReadMemory in -lxml2... no configure: error: Not found libxml2 library cs@debian: apt-get install -y libxml2-dev
checking for net-snmp-config... no configure: error: Invalid Net-SNMP directory - unable to find net-snmp-config cs@debian:sudo apt install libsnmp-dev
checking for OPENIPMI support... no configure: error: Invalid OPENIPMI directory - unable to find ipmiif.h cs@debian: sudo apt install libopenipmi-dev
checking for libevent support... no configure: error: Unable to use libevent (libevent check failed) cs@debian: sudo apt install libevent-dev
checking for curl-config... no configure: error: Curl library not found cs@debian: sudo apt install libcurl4-openssl-dev=7.88.1-7~bpo11+2

checking pkg-config is at least version 0.9.0... yes configure: error: cannot find pkg-config package for libpcre cs@debian: sudo apt-get install libpcre3-dev #other os >pcre-devel

make ###报错 /usr/bin/ld: warning: libcrypto.so.1.0.2, needed by /usr/lib/x86_64-linux-gnu/libnetsnmp.so, may conflict with libcrypto.so.1.1 /usr/bin/ld: warning: libssl.so.1.0.2, needed by /usr/lib/x86_64-linux-gnu/libcurl.so, may conflict with libssl.so.1.1 /usr/local/mysql/lib/libmysqlclient.so: undefined reference to `SSL_CTX_set_ciphersuites@OPENSSL_1_1_1' /usr/local/mysql/lib/libmysqlclient.so: undefined reference to `BIO_set_callback_ex@OPENSSL_1_1_1' collect2: error: ld returned 1 exit status
## ldconfig -p | grep libcrypto 或 locate xxx cs@debian:/opt/zabbix-6.0.2$ locate libcrypto.so /opt/kingsoft/wps-office/office6/libcrypto.so /opt/kingsoft/wps-office/office6/libcrypto.so.1.1 /opt/mysql/lib/private/libcrypto.so /opt/mysql/lib/private/libcrypto.so.1.1 /opt/vagrant/embedded/lib64/libcrypto.so /opt/vagrant/embedded/lib64/libcrypto.so.1.1 /usr/lib/x86_64-linux-gnu/libcrypto.so /usr/lib/x86_64-linux-gnu/libcrypto.so.1.0.2 /usr/lib/x86_64-linux-gnu/libcrypto.so.1.1 cs@debian:/opt/zabbix-6.0.2$ locate libssl.so /opt/kingsoft/wps-office/office6/libssl.so /opt/kingsoft/wps-office/office6/libssl.so.1.1 /opt/mysql/lib/private/libssl.so /opt/mysql/lib/private/libssl.so.1.1 /opt/vagrant/embedded/lib64/libssl.so /opt/vagrant/embedded/lib64/libssl.so.1.1 /usr/lib/x86_64-linux-gnu/libssl.so /usr/lib/x86_64-linux-gnu/libssl.so.1.0.2 /usr/lib/x86_64-linux-gnu/libssl.so.1.1
cs@debian:/opt/zabbix-6.0.2$ locate libmysqlclient.so /opt/mysql/lib/libmysqlclient.so /opt/mysql/lib/libmysqlclient.so.21 /opt/mysql/lib/libmysqlclient.so.21.1.21


#找到动态链接库的路径 export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib #找到静态库的路径 export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/lib

cs@debian:/opt/zabbix-6.0.2$ make make[1]: Leaving directory '/opt/zabbix-6.0.2' cs@debian:/opt/zabbix-6.0.2$ make install make[1]: Leaving directory '/opt/zabbix-6.0.2 编译成功

mysql

1
./configure  --prefix=/opt/zabbix   --enable-proxy  --with-mysql    --enable-agent2

find /usr/lib -name libmysqlclient.so
/usr/lib/x86_64-linux-gnu/libmysqlclient.so

No database selected for Zabbix server/proxy. Use –with-mysql or –with-oracle or –with-postgresql or –with-sqlite3.

postgresql

1
./configure --prefix=/opt/monitor/zabbix-7.0  --enable-server --enable-agent --enable-agent2 --enable-proxy  --with-postgresql  --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2  --with-openipmi

sudo apt-get install libpq-dev

sudo yum install postgresql-devel

sql

mysql

Must be at least (8.00.30) mysql

https://www.zabbix.com/documentation/6.4/en/manual/appendix/install/db_scripts

mysql -uroot -p

1
2
3
4
5
mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin;
mysql> create user 'zabbix'@'localhost' identified by 'zabbix';
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
mysql> SET GLOBAL log_bin_trust_function_creators = 1;
mysql> quit;

❯ mysql -uzabbix -p -P3305 zabbix <schema.sql
Enter password:

#proxy节点的数据库无需倒入下面的。

❯ mysql -uzabbix -P3305 -p zabbix <images.sql
Enter password:
❯ mysql -uzabbix -P3305 -p –default-character-set=utf8mb4 zabbix <data.sql
Enter password:

log_bin_trust_function_creators 当二进制日志启用后,这个变量就会启用。它控制是否可以信任存储函数创建者,不会创建写入二进制日志引起不安全事件的存储函数。如果设置为0(默认值),用户不得创建或修改存储函数,除非它们具有除CREATE ROUTINE或ALTER ROUTINE特权之外的SUPER权限。 设置为0还强制使用DETERMINISTIC特性或READS SQL DATA或NO SQL特性声明函数的限制。 如果变量设置为1,MySQL不会对创建存储函数实施这些限制。

1
2
3
4
mysql -uroot -p<password>

mysql> SET GLOBAL log_bin_trust_function_creators = 0;
mysql> quit;

如果Zabbix server和proxy安装在同一个主机上,那么它们的数据库必须用不同的名称创建!

1
2
3
4
MySQL root@localhost:none>  create database zabbix_proxy character set utf8mb4 collate utf8mb4_bin;
MySQL root@localhost:none> grant all privileges on zabbix_proxy.* to 'zabbix'@'localhost';


# For a Zabbix proxy database, only schema.sql should be imported (no images.sql nor data.sql).

❯ mysql -uzabbix -p -P3305 zabbix_proxy <schema.sql
Enter password:

PostgreSQL

https://www.zabbix.com/documentation/current/zh/manual/appendix/install/db_scripts#postgresql

https://www.zabbix.com/documentation/current/zh/manual/appendix/install/timescaledb

1
2
3
4
5
6
7
8
9
10
8189  sudo -u postgres createuser --pwprompt zabbix
8198 sudo -u postgres createdb -O zabbix -E Unicode -T template0 zabbix
8200 cd /home/cs/文档/zabbix-7.0.0/database/postgresql/
8201 cat schema.sql | sudo -u zabbix psql zabbix
8202 cat images.sql | sudo -u zabbix psql zabbix
8203 cat data.sql | sudo -u zabbix psql zabbix
8204 echo "CREATE EXTENSION IF NOT EXISTS timescaledb CASCADE;" | sudo -u postgres psql zabbix
8205 cat /home/cs/文档/zabbix-7.0.0/database/postgresql/timescaledb/schema.sql | sudo -u postgres psql zabbix
8206 sudo -u postgres psql -l

docker

https://github.com/zabbix/zabbix-docker/blob/bf07bef34cfcd6cd0d9c862f189dc4e6c0154642/Dockerfiles/web-nginx-pgsql/alpine/Dockerfile

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
version: '3'
services:
sonarqube:
image: zabbix/zabbix-web-nginx-pgsql:alpine-7.0-latest
container_name: zabbix-web
# depends_on:
# - db
ports:
- "8082:8080"
extra_hosts:
- "k8s.org:192.168.122.1" # 添加主机名
environment:
ZBX_SERVER_HOST: "k8s.org"
DB_SERVER_HOST: "k8s.org"
POSTGRES_PASSWORD: "zabbix"
POSTGRES_USER: "zabbix"
DB_SERVER_PORT: "5433"
POSTGRES_DB: "zabbix"

agent

本地包方式

1
2
rpm -Uvh https://repo.zabbix.com/zabbix/6.4/rhel/7/x86_64/zabbix-release-6.4-1.el7.noarch.rpm
yum install zabbix-agent
1
2
3
4
5
6
7
8
9
# sed '/^#/d;/^$/d' /etc/zabbix/zabbix_agentd.conf 
PidFile=/run/zabbix/zabbix_agentd.pid
LogFile=/var/log/zabbix/zabbix_agentd.log
LogFileSize=0
Server=127.0.0.1
ServerActive=127.0.0.1
Hostname=Zabbix server
Include=/etc/zabbix/zabbix_agentd.d/*.conf

https://blog.csdn.net/weixin_45880055/article/details/115330224

agent

no active checks on server [192.168.122.1:10051]: host [test] not found

在zabbix web页面Monitoring->Configuration->Hosts 页面更改Host name和zabbix_agentd.conf里面的Hostname一样

1
2
3
[root@test ~]# ss -antl | grep 10050
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 :::10050 :::*

server

cannot send list of active checks to “192.168.122.8”: host [test] not found

1
2
3
4
5
❯ netstat -tanlp | grep -I  10051
(Not all processes could be identified, non-owned process info
will not be shown, you would have to be root to see it all.)
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 4070/zabbix_server

Received empty response from Zabbix Agent at [127.0.0.1]. Assuming that agent dropped connection because of access permissions.

custom

自定义参数:被监控端/etc/zabbix/zabbix_agentd.d/目录下,建立*.conf结尾的文件

nginx_status 开启
nginx.conf server块内添加
  location /nginx_status {
       stub_status on;
       access_log off;
       allow 127.0.0.1;
       deny all;
    }  

/etc/zabbix/zabbix_agentd.d/nginx_status.conf

1
2
#UserParameter=key[*],command
UserParameter=nginx.status[*],/usr/local/zabbix_userparameter/scripts/nginx_status.sh $1

[*]可选值: ‘ping’, ‘active’, ‘reading’, ‘writing’, ‘waiting’, ‘accepts’, ‘handled’, ‘requests’

自定义脚本
nginx_status.sh
#!/bin/bash
HOST='127.0.0.1'
PORT=80
NGINX_COMMAND=$1

function ping() { /sbin/pidof nginx | wc -l }
function active() { /usr/bin/curl -s "http://$HOST:$PORT/nginx_status/" |awk '/Active/ {print $NF}' } function reading() { /usr/bin/curl -s "http://$HOST:$PORT/nginx_status/" |awk '/Reading/ {print $2}' } function writing() { /usr/bin/curl -s "http://$HOST:$PORT/nginx_status/" |awk '/Writing/ {print $4}' } function waiting() { /usr/bin/curl -s "http://$HOST:$PORT/nginx_status/" |awk '/Waiting/ {print $6}' } function accepts() { /usr/bin/curl -s "http://$HOST:$PORT/nginx_status/" |awk 'NR==3 {print $1}' } function handled() { /usr/bin/curl -s "http://$HOST:$PORT/nginx_status/" |awk 'NR==3 {print $2}' } function requests() { /usr/bin/curl -s "http://$HOST:$PORT/nginx_status/" |awk 'NR==3 {print $3}' }
case $NGINX_COMMAND in ping) ping; ;; active) active; ;; reading) reading; ;; writing) writing; ;; waiting) waiting; ;; accepts) accepts; ;; handled) handled; ;; requests) requests; ;; *) echo $"USAGE:$0 {ping|active|reading|writing|waiting|accepts|handled|requests}" esac

测试

1
zabbix_get -s 192.168.xx.xx    -k "nginx.status[ping]"

https://github.com/dongliwu/zabbix_userparameter

ui

php

https://www.php.net/manual/zh/install.unix.debian.php

编译

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
./configure --prefix=/opt/php/php8.2.6 \
--with-config-file-path=/opt/php/php8.2.6/etc \
--enable-mysqlnd \
--with-pdo-mysql \
--with-pdo-mysql=mysqlnd \
-with-mysqli \
--enable-bcmath \
--enable-fpm \
--with-fpm-user=www-data \
--with-fpm-group=www-data \
--enable-mbstring \
--enable-phpdbg \
--enable-shmop \
--enable-sockets \
--enable-sysvmsg \
--enable-sysvsem \
--enable-sysvshm \
--enable-gd \
--with-ldap \
--with-jpeg \
--with-freetype \
-with-gettext \
--with-zlib \
--with-curl \
--with-pear \
--with-openssl \
--enable-pcntl \
--with-readline

+——————————————————————–+
| License: |
| This software is subject to the PHP License, available in this |
| distribution in the file LICENSE. By continuing this installation |
| process, you are bound by the terms of this license agreement. |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point. |
+——————————————————————–+

Thank you for using PHP.

php编译
configure依赖
https://packages.debian.org/search?suite=default§ion=all&arch=any&searchon=contents&keywords=ldap.h
=====sqlite3
No package 'sqlite3' found

Consider adjusting the PKG_CONFIG_PATH environment variable if you installed software in a non-standard prefix.
Alternatively, you may set the environment variables SQLITE_CFLAGS and SQLITE_LIBS to avoid the need to call pkg-config. See the pkg-config man page for more details. ######安装sqlite3,依旧提示找不到包 ,pkg-config列表会没有,必须安装libsqlite3-dev
sudo apt-get install sqlite3 libsqlite3-dev
yum -y install sqlite-devel

=====ldap checking if we're at 64-bit platform... yes configure: error: Cannot find ldap.h
debian sudo apt install libldap-dev

centos yum -y install openldap openldap-devel
=====gb No package 'libpng' found No package 'freetype2' found
sudo apt install libjpeg-dev libpng-dev libfreetype-dev
=====oniguruma No package 'oniguruma' found
sudo apt install libonig-dev
=====readline.h iconfigure: error: Please reinstall readline - I cannot find readline.h sudo apt-get install libreadline-dev
=====zip configure: WARNING: unrecognized options: --enable-zip, --with-libzip sudo apt-get install libzip-dev libzip4 =====libreadline.so.7 error while loading shared libraries: libreadline.so.7: cannot open shared
sudo ln -s /lib/x86_64-linux-gnu/libreadline.so.8.1 /lib/x86_64-linux-gnu/libreadline.so.7
$ pkg-config --list-all | grep oniguruma oniguruma oniguruma - Regular expression library
[php.ini development,*php.ini-production*](https://github.com/php/php-src/blob/master/php.ini-production)

配置

1
2
3
4
❯ cp php.ini-production $PHP_HOME/etc/php.ini
❯ cp php-fpm.conf.default php-fpm.conf
❯ sed -i '/^;/d;/^$/d' php.ini
❯ cd ./php-fpm.d && cp www.conf.default www.conf

启动

1
./sbin/php-fpm

Starting………… [04-Jun-2023 18:03:24] NOTICE: [pool www] ‘user’ directive is ignored when FPM is not running as root
[04-Jun-2023 18:03:24] NOTICE: [pool www] ‘group’ directive is ignored when FPM is not running as root

检查端口

1
lsof -i tcp:9000

COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
php-fpm 10006 root 7u IPv4 288286 0t0 TCP localhost:9000 (LISTEN)
php-fpm 10007 www-data 5u IPv4 288286 0t0 TCP localhost:9000 (LISTEN)
php-fpm 10008 www-data 5u IPv4 288286 0t0 TCP localhost:9000 (LISTEN)

字体

zabbix/ui/assets/fonts/

1
2
define('ZBX_FONTPATH',				realpath('assets/fonts')); // where to search for font (GD > 2.0.18)
define('ZBX_GRAPH_FONT_NAME', 'DejaVuSans'); // font file name

cp /xxx/Windows/Fonts/simkai.ttf /opt/monitor/zabbix/ui/assets/fonts

/opt/monitor/zabbix/ui/include/defines.inc.php

1
2
3
include/defines.inc.php:define('ZBX_GRAPH_FONT_NAME',		'DejaVuSans'); // font file name
include/defines.inc.php:define('ZBX_FONT_NAME', 'DejaVuSans');

DejaVuSans 改为 simkai

/opt/monitor/zabbix/ui/include/graphs.inc.php

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
function to_entities($string){
$len = strlen($string);
$buf = "";
for($i = 0; $i < $len; $i++){
if (ord($string[$i]) <= 127){
$buf .= $string[$i];
} else if (ord ($string[$i]) <192){
//unexpected 2nd, 3rd or 4th byte
$buf .= "?";
} else if (ord ($string[$i]) <224){
//first byte of 2-byte seq
$buf .= sprintf("&#%d;",
((ord($string[$i + 0]) & 31) << 6) +
(ord($string[$i + 1]) & 63)
);
$i += 1;
} else if (ord ($string[$i]) <240){
//first byte of 3-byte seq
$buf .= sprintf("&#%d;",
((ord($string[$i + 0]) & 15) << 12) +
((ord($string[$i + 1]) & 63) << 6) +
(ord($string[$i + 2]) & 63)
);
$i += 2;
} else {
//first byte of 4-byte seq
$buf .= sprintf("&#%d;",
((ord($string[$i + 0]) & 7) << 18) +
((ord($string[$i + 1]) & 63) << 12) +
((ord($string[$i + 2]) & 63) << 6) +
(ord($string[$i + 3]) & 63)
);
$i += 3;
}
}
return $buf;
}

$string 修改为 to_entities($string)

ui/conf/zabbix.conf.php.example

1
2
3
4
5
6
$DB['TYPE']				= 'MYSQL';
$DB['SERVER'] = 'localhost';
$DB['PORT'] = '0';
$DB['DATABASE'] = 'zabbix';
$DB['USER'] = 'zabbix';
$DB['PASSWORD'] = 'zabbix';

nginx

include conf.d/http/*.conf;

zabbix.conf
zabbix.conf
upstream zabbix{
     server 127.0.0.1:9000;
 }

log_format zabbix '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"';
server { listen 8081; server_name localhost;
index index.php index.html index.html; root /opt/zabbix/ui; access_log logs/zabbix.log zabbix;
location /zabbix { try_files $uri $uri/ /index.php?$args; }
location ~ .*\.(php)?$ { expires -1s; try_files $uri =404; fastcgi_split_path_info ^(.+\.php)(/.+)$; include fastcgi_params; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_pass zabbix; include fastcgi.conf; } }

zabbix前端已经安装完成!超级用户名是Admin,密码是zabbix

grafana

grafana ui

点击打赏
文章目录
  1. 1. zabbix
    1. 1.1. 编译
      1. 1.1.1. 缺依赖
    2. 1.2. sql
      1. 1.2.1. mysql
      2. 1.2.2. PostgreSQL
        1. 1.2.2.1. docker
    3. 1.3. agent
      1. 1.3.1. agent
      2. 1.3.2. server
    4. 1.4. custom
  2. 2. ui
    1. 2.1. php
      1. 2.1.1. 编译
      2. 2.1.2. 配置
      3. 2.1.3. 启动
      4. 2.1.4. 检查端口
      5. 2.1.5. 字体
      6. 2.1.6. nginx
    2. 2.2. grafana
载入天数...载入时分秒... ,