zabbix
https://www.zabbix.com/download_sources
编译
Documentation: Zabbix 6.4 Installation from sources
1 | ❯ sudo addgroup --system --quiet zabbix |
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.soNo 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 | mysql> create database zabbix character set utf8mb4 collate utf8mb4_bin; |
❯ 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 | mysql -uroot -p<password> |
如果Zabbix server和proxy安装在同一个主机上,那么它们的数据库必须用不同的名称创建!
1 | MySQL root@localhost:none> create database zabbix_proxy character set utf8mb4 collate utf8mb4_bin; |
# 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 | 8189 sudo -u postgres createuser --pwprompt zabbix |
docker
1 | version: '3' |
agent
1 | rpm -Uvh https://repo.zabbix.com/zabbix/6.4/rhel/7/x86_64/zabbix-release-6.4-1.el7.noarch.rpm |
1 | # sed '/^#/d;/^$/d' /etc/zabbix/zabbix_agentd.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 | [root@test ~]# ss -antl | grep 10050 |
server
cannot send list of active checks to “192.168.122.8”: host [test] not found
1 | ❯ netstat -tanlp | grep -I 10051 |
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 | #UserParameter=key[*],command |
[*]可选值: ‘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 | ./configure --prefix=/opt/php/php8.2.6 \ |
+——————————————————————–+
| 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
配置
1 | ❯ cp php.ini-production $PHP_HOME/etc/php.ini |
启动
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 | define('ZBX_FONTPATH', realpath('assets/fonts')); // where to search for font (GD > 2.0.18) |
cp /xxx/Windows/Fonts/simkai.ttf /opt/monitor/zabbix/ui/assets/fonts
/opt/monitor/zabbix/ui/include/defines.inc.php
1 | include/defines.inc.php:define('ZBX_GRAPH_FONT_NAME', 'DejaVuSans'); // font file name |
DejaVuSans 改为 simkai
/opt/monitor/zabbix/ui/include/graphs.inc.php
1 | function to_entities($string){ |
$string 修改为 to_entities($string)
ui/conf/zabbix.conf.php.example
1 | $DB['TYPE'] = 'MYSQL'; |
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