一、安装配置zabbix-proxy
下载
root@localhost src]# wget -c https://astuteinternet.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.4.6/zabbix-4.4.6.tar.gz
[root@localhost src]# tar xf zabbix-4.4.6.tar.gz
[root@localhost src]# cd zabbix-4.4.6
安装数据库及配置与授权(zabbix_proxy)
安装数据库
[root@localhost core]# yum install -y mariadb mariadb-server mariadb-devel mariadb-libs
[root@localhost core]# rpm -qa|grep mariadb
mariadb-server-5.5.65-1.el7.x86_64
mariadb-5.5.65-1.el7.x86_64
mariadb-devel-5.5.65-1.el7.x86_64
mariadb-libs-5.5.65-1.el7.x86_64
[root@localhost core]# systemctl start mariadb
创建数据库及授权
[root@localhost core]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.65-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>
[root@localhost core]# mysql
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 5.5.65-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database zabbix_proxy charset utf8;
Query OK, 1 row affected (0.01 sec)
MariaDB [(none)]> grant all on zabbix_proxy.* to "zabbix"@"localhost" identified by "123456";
Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.01 sec)
安装配置zabbix-proxy
解压
[root@localhost src]# tar -zxvf zabbix-4.4.6.tar.gz
[root@localhost src]# cd zabbix-4.4.6/
安装软件环境支持
[root@localhost zabbix-4.4.6]# yum -y install gcc mysql-community-devel libxml2-devel unixODBC-devel net-snmp-devel libcurl-devel libssh2-devel OpenIPMI-devel openssl-devel openldap-devel libevent libevent-devel
编译安装
[root@localhost zabbix-4.4.6]# ./configure \
--enable-server \
--enable-agent \
--enable-proxy \
--with-mysql \
--enable-ipv6 \
--with-net-snmp \
--with-libcurl \
--with-libxml2 \
--with-unixodbc \
--with-ssh2 \
--with-openipmi \
--with-openssl \
--prefix=/usr/local/zabbix
[root@localhost zabbix-4.4.6]# make
[root@localhost zabbix-4.4.6]# make install
导入数据库
只导一个库即可
[root@localhost ~]# mysql -uzabbix -p123456 zabbix_proxy </usr/src/zabbix-4.4.6/database/mysql/schema.sql
配置zabbix-proxy.conf
注:这里配置主动模式
[root@localhost core]# vim /usr/local/zabbix/etc/zabbix_proxy.conf
[root@localhost ~]# egrep -v '^#|^$' /usr/local/zabbix/etc/zabbix_proxy.conf
ProxyMode=0
Server=192.168.1.11
ServerPort=10051
Hostname=proxy22
ListenPort=10051
LogFile=/tmp/zabbix_proxy.log
LogFileSize=0
PidFile=/tmp/zabbix_proxy.pid
SocketDir=/tmp
DBHost=localhost
DBName=zabbix_proxy
DBUser=zabbix
DBPassword=123456
HeartbeatFrequency=60
ConfigFrequency=60
DataSenderFrequency=3
Timeout=4
LogSlowQueries=3000
TmpDir=/tmp
StatsAllowedIP=127.0.0.1
启动
[root@localhost core]# /usr/local/zabbix/sbin/zabbix_proxy
[root@localhost ~]# ps -ef|grep zabbix_proxy
zabbix 16590 1 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy
zabbix 16595 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: configuration syncer [synced config 0 bytes in 0.056483 sec, idle 60 sec]
zabbix 16597 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: trapper #1 [processed data in 0.000000 sec, waiting for connection]
zabbix 16598 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: trapper #2 [processed data in 0.000000 sec, waiting for connection]
zabbix 16599 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: trapper #3 [processed data in 0.000000 sec, waiting for connection]
zabbix 16600 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: trapper #4 [processed data in 0.000000 sec, waiting for connection]
zabbix 16601 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: trapper #5 [processed data in 0.000000 sec, waiting for connection]
zabbix 16607 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: heartbeat sender [sending heartbeat message failed in 0.017171 sec, idle 60 sec]
zabbix 16608 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: data sender [sent 0 values in 0.004179 sec, idle 1 sec]
zabbix 16609 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: housekeeper [startup idle for 30 minutes]
zabbix 16611 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: http poller #1 [got 0 values in 0.001029 sec, idle 5 sec]
zabbix 16612 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: discoverer #1 [processed 0 rules in 0.001958 sec, idle 60 sec]
zabbix 16613 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: history syncer #1 [processed 0 values in 0.000025 sec, idle 1 sec]
zabbix 16614 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: history syncer #2 [processed 0 values in 0.000063 sec, idle 1 sec]
zabbix 16615 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: history syncer #3 [processed 0 values in 0.000025 sec, idle 1 sec]
zabbix 16616 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: history syncer #4 [processed 0 values in 0.000028 sec, idle 1 sec]
zabbix 16617 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: self-monitoring [processed data in 0.000025 sec, idle 1 sec]
zabbix 16618 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: task manager [processed 0 task(s) in 0.000689 sec, idle 5 sec]
zabbix 16619 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: poller #1 [got 0 values in 0.000061 sec, idle 5 sec]
zabbix 16620 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: poller #2 [got 0 values in 0.000022 sec, idle 5 sec]
zabbix 16627 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: poller #3 [got 0 values in 0.000037 sec, idle 5 sec]
zabbix 16628 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: poller #4 [got 0 values in 0.000036 sec, idle 5 sec]
zabbix 16629 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: poller #5 [got 0 values in 0.000022 sec, idle 5 sec]
zabbix 16630 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: unreachable poller #1 [got 0 values in 0.000023 sec, idle 5 sec]
zabbix 16631 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: icmp pinger #1 [got 0 values in 0.000044 sec, idle 5 sec]
zabbix 16632 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: preprocessing manager #1 [queued 0, processed 0 values, idle 5.009935 sec during 5.010114 sec]
zabbix 16633 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: preprocessing worker #1 started
zabbix 16634 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: preprocessing worker #2 started
zabbix 16635 16590 0 17:53 ? 00:00:00 /usr/local/zabbix/sbin/zabbix_proxy: preprocessing worker #3 started
root 16677 1684 0 17:54 pts/0 00:00:00 grep --color=auto zabbix_proxy
二、源码安装配置zabbix-agent
基础依赖安装
yum install -y libjpeg mysql-devel autoconf libpng-devel freetype freetype-devel libxslt libxslt-devel libXpm-devel sqlite-devel bzip2 bzip2-devel libjpeg libjpeg-devel libpng libpng-devel oniguruma oniguruma-devel libcurl libcurl-devel postgresql-devel openssl openssl-devel libzip libxml2 libxml2-devel pcre2 pcre-devel pcre gcc gcc-c++
yum install vim wget lrzsz unzip -y
下载安装编译
cd /usr/src/
wget -c https://astuteinternet.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20Stable/4.4.6/zabbix-4.4.6.tar.gz
tar xf zabbix-4.4.6.tar.gz ;cd zabbix-4.4.6/
./configure \
--enable-agent \
--with-mysql \
--enable-ipv6 \
--with-net-snmp \
--with-libcurl=/usr/bin/curl-config \
--with-libxml2 \
--with-unixodbc \
--with-ssh2 \
--with-openipmi \
--with-openssl \
--prefix=/usr/local/zabbix
make && make install
配置
#cd /usr/src/zabbix-4.4.6/misc/init.d/fedora/core
cp -rf zabbix_agentd /etc/init.d/zabbix_agentd
#vim /etc/init.d/zabbix_agentd
BASEDIR=/usr/local/zabbix
#vim /usr/local/zabbix/etc/zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log
Server=192.168.0.235
ListenPort=10050
ServerActive=192.168.0.235
Hostname=192.168.0.122
UserParameter=jenkins.status,ps -ef|grep -v grep|grep tomcat_jenkins|grep start >/dev/null 2>&1 && echo $?
UserParameter=nexus3.status,ps -ef|grep -v grep|grep nexus3|grep sonatype >/dev/null 2>&1 && echo $?
UserParameter=cpu.load_average,w|grep load|awk '{print $10}'|awk -F "," '{print $1}'
UserParameter=disk.Used,df -Th|grep '/$'|awk '{print $6}'
UserParameter=disk.available,df -Th|grep '/$'|awk '{print $5}'|awk -F 'G' '{print $1}'
创建用户
useradd zabbix
开启启动
/etc/init.d/zabbix_agentd restart; ps -ef|grep zabbix
chkconfig zabbix_agentd on ;chkconfig --list
三、常用监控项
cpu、内存、磁盘、进程、端口
进程
proc.num[,otoyix,all,toyixGateway-xx-xx.jar] 1为正常,返回数字,无正负
otoyix:启动用户
all:默认值
toyixGateway-xx-xx.jar:进程名
磁盘
agent_Active_base: /分区已使用率
vfs.fs.size[/,pused]
浮点数
单位:%
agent_Active_base: disk.available剩余可用
disk.available
数字无正负
单位G
UserParameter=disk.available,df -Th|grep '/$'|awk '{print $5}'|awk -F 'G' '{print $1}'
CPU负载
agent_Active_base: cpu负载
system.cpu.load[percpu,avg1]
浮点数
单位:空
内存
agent_Active_base: memory_available内存剩余可用量
vm.memory.size[available]
数字无正负
单位:空
agent_Active_base: memory_free_内存空闲量
vm.memory.size[free]
数字无正负
单位:空
agent_Active_base: memory_total内存总容量
vm.memory.size[total]
数字无正负
单位:空
端口
net.tcp.listen[port] 检查 TCP 端口 是否处于侦听状态。返回 0 - 未侦听;1 - 正在侦听
----------------end