1. zabbix介绍
zabbix
是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
zabbix
能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
zabbix
由2部分构成,zabbix server
与可选组件zabbix agent
。
zabbix server
可以通过SNMP
,zabbix agent
,ping
,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Ubuntu,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。
zabbix agent
需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。
zabbix server
可以单独监视远程服务器的服务状态;同时也可以与zabbix agent
配合,可以轮询zabbix agent
主动接收监视数据(agent方式),同时还可被动接收zabbix agent
发送的数据(trapping方式)。
另外
2. zabbix特点
zabbix的主要特点:
- 安装与配置简单,学习成本低
- 支持多语言(包括中文)
- 免费开源
- 自动发现服务器与网络设备
- 分布式监视以及WEB集中管理功能
- 可以无agent监视
- 用户安全认证和柔软的授权方式
- 通过WEB界面设置或查看监视结果
- email等通知功能
Zabbix主要功能:
- CPU负荷
- 内存使用
- 磁盘使用
- 网络状况
- 端口监视
- 日志监视
zabbix server
还支持SNMP (v1,v2),可以与SNMP软件(例如:net-snmp)等配合使用。
3. zabbix安装!!!
3.1 用二进制安装zabbix!!!!
[root@localhost ~]# yum -y install net-snmp-devel libevent-devel
上次元数据过期检查:0:32:17 前,执行于 2021年05月13日 星期四 03时12分32秒。
依赖关系解决。
=========================================================================================
软件包 架构 版本 仓库 大小
=========================================================================================
安装:
libevent-devel x86_64 2.1.8-5.el8 appstream 104 k
net-snmp-devel x86_64 1:5.8-20.el8 appstream 274 k
......
已安装:
annobin-9.65-1.el8.0.1.x86_64
dwz-0.12-9.el8.x86_64
efi-srpm-macros-3-3.el8.noarch
elfutils-devel-0.182-3.el8.x86_64
elfutils-libelf-devel-0.182-3.el8.x86_64
ghc-srpm-macros-1.4.2-7.el8.noarch
go-srpm-macros-2-17.el8.noarch
libevent-devel-2.1.8-5.el8.x86_64
libzstd-devel-1.4.4-1.el8.x86_64
lm_sensors-devel-3.4.0-23.20180522git70f7e08.el8.x86_64
net-snmp-devel-1:5.8-20.el8.x86_64
ocaml-srpm-macros-5-4.el8.noarch
openblas-srpm-macros-2-2.el8.noarch
perl-CPAN-Meta-2.150010-396.el8.noarch
perl-CPAN-Meta-Requirements-2.140-396.el8.noarch
perl-CPAN-Meta-YAML-0.018-397.el8.noarch
perl-Encode-Locale-1.05-10.module_el8.3.0+416+dee7bcef.noarch
perl-ExtUtils-Command-1:7.34-1.el8.noarch
perl-ExtUtils-Install-2.14-4.el8.noarch
perl-ExtUtils-MakeMaker-1:7.34-1.el8.noarch
perl-ExtUtils-Manifest-1.70-395.el8.noarch
perl-ExtUtils-ParseXS-1:3.35-2.el8.noarch
perl-JSON-PP-1:2.97.001-3.el8.noarch
perl-Test-Harness-1:3.42-1.el8.noarch
perl-Time-HiRes-4:1.9758-2.el8.x86_64
perl-devel-4:5.26.3-419.el8.x86_64
perl-srpm-macros-1-25.el8.noarch
perl-version-6:0.99.24-1.el8.x86_64
popt-devel-1.18-1.el8.x86_64
python-rpm-macros-3-41.el8.noarch
python-srpm-macros-3-41.el8.noarch
python3-pyparsing-2.1.10-7.el8.noarch
python3-rpm-macros-3-41.el8.noarch
qt5-srpm-macros-5.15.2-1.el8.noarch
redhat-rpm-config-125-1.el8.noarch
rpm-devel-4.14.3-13.el8.x86_64
rust-srpm-macros-5-2.el8.noarch
systemtap-sdt-devel-4.4-10.el8.x86_64
xz-devel-5.2.4-3.el8.x86_64
完毕!
[root@localhost ~]# cd /usr/src/
[root@localhost src]# wget https://cdn.zabbix.com/zabbix/sources/stable/5.2/zabbix-5.2.6.tar.gz
--2021-05-13 04:03:36-- https://cdn.zabbix.com/zabbix/sources/stable/5.2/zabbix-5.2.6.tar.gz
正在解析主机 cdn.zabbix.com (cdn.zabbix.com)... 172.67.215.198, 104.21.69.236, 2606:4700:3030::ac43:d7c6, ...
正在连接 cdn.zabbix.com (cdn.zabbix.com)|172.67.215.198|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:20602665 (20M) [application/octet-stream]
正在保存至: “zabbix-5.2.6.tar.gz”
zabbix-5.2.6.tar.gz 100%[=========================>] 19.65M 4.38MB/s 用时 4.5s
2021-05-13 04:03:42 (4.38 MB/s) - 已保存 “zabbix-5.2.6.tar.gz” [20602665/20602665])
[root@localhost src]# ls
debug kernels zabbix-5.2.6.tar.gz
3.2 解压与创建zabbix用户和组!!1
[root@localhost src]# tar xf zabbix-5.2.6.tar.gz
[root@localhost src]# ls
debug kernels zabbix-5.2.6 zabbix-5.2.6.tar.gz
[root@localhost src]# groupadd -r zabbix
[root@localhost src]# useradd -r -g zabbix -M -s /sbin/nologin zabbix
(创建一个系统用户 属组为zabbix!!!!)
3.3 配置zabbix 数据库!!!
[root@localhost ~]# mysql -uroot -p123liuZEzheng!
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.33 MySQL Community Server (GPL)
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> create database zabbix character set utf8 collate utf8_bin;
Query OK, 1 row affected (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix123!';
Query OK, 0 rows affected, 2 warnings (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@192.168.180.129 identified by 'zabbix123!';
Query OK, 0 rows affected, 1 warning (0.00 sec)
mysql> grant all privileges on zabbix.* to zabbix@localhost identified by 'zabbix123!';
Query OK, 0 rows affected, 2 warnings (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
3.4 将安装包的内容导入到数据库里面!
[root@localhost ~]# cd /usr/src/zabbix-5.2.6/database/mysql/
[root@localhost mysql]# ls
data.sql double.sql images.sql Makefile.am Makefile.in schema.sql
[root@localhost mysql]# mysql -uzabbix -pzabbix123! zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -pzabbix123! zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -pzabbix123! zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
3.5 编译安装zabbix!!!
[root@localhost zabbix-4.0.30]# ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2
checking for a BSD-compatible install... /usr/bin/install -c
checking whether build environment is sane... yes
checking for a thread-safe mkdir -p... /usr/bin/mkdir -p
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking whether make supports nested variables... yes
......
......
......
config.status: executing depfiles commands
Configuration:
Detected OS: linux-gnu
Install path: /usr/local
Compilation arch: linux
Compiler: cc
Compiler flags: -g -O2
Library-specific flags:
database: -I/usr/local/mysql/include
libXML2: -I/usr/include/libxml2
Net-SNMP: -I. -I/usr/include
Enable server: yes
Server details:
With database: MySQL
WEB Monitoring: cURL
SSL certificates: /usr/local/share/zabbix/ssl/certs
SSL keys: /usr/local/share/zabbix/ssl/keys
Native Jabber: no
SNMP: yes
IPMI: no
SSH: no
TLS: no
ODBC: no
Linker flags: -L/usr/local/mysql/lib -L/usr/lib64 -rdynamic
Libraries: -lmysqlclient -lpthread -lm -lrt -ldl -lxml2 -lnetsnmp -lz -lpthread -levent -lcurl -lm -ldl -lresolv -lpcre
Configuration file: /usr/local/etc/zabbix_server.conf
External scripts: /usr/local/share/zabbix/externalscripts
Alert scripts: /usr/local/share/zabbix/alertscripts
Modules: /usr/local/lib/modules
Enable proxy: no
Enable agent: yes
Agent details:
TLS: no
Linker flags: -rdynamic
Libraries: -lz -lpthread -lcurl -lm -ldl -lresolv -lpcre
Configuration file: /usr/local/etc/zabbix_agentd.conf
Modules: /usr/local/lib/modules
Enable Java gateway: no
LDAP support: no
IPv6 support: no
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
3.5.1 继续编译!!!
[root@localhost zabbix-4.0.30]# make install
Making install in src
make[1]: 进入目录“/usr/src/zabbix-4.0.30/src”
Making install in libs
make[2]: 进入目录“/usr/src/zabbix-4.0.30/src/libs”
Making install in zbxcrypto
make[3]: 进入目录“/usr/src/zabbix-4.0.30/src/libs/zbxcrypto”
cc -DHAVE_CONFIG_H -I. -I../../../include -g -O2 -MT libzbxcrypto_a-md5.o -MD -MP -MF .deps/libzbxcrypto_a-md5.Tpo -c -o libzbxcrypto_a-md5.o `test -f 'md5.c' || echo './'`md5.c
mv -f .deps/libzbxcrypto_a-md5.Tpo .deps/libzbxcrypto_a-md5.Po
cc -DHAVE_CONFIG_H -I. -I../../../include -g -O2 -MT libzbxcrypto_a-base64.o -MD -MP -MF .deps/libzbxcrypto_a-base64.Tpo -c -o libzbxcrypto_a-base64.o `test -f 'base64.c' || echo './'`base64.c
mv -f .deps/libzbxcrypto_a-base64.Tpo .deps/libzbxcrypto_a-base64.Po
cc -DHAVE_CONFIG_H -I. -I../../../include -g -O2 -MT libzbxcrypto_a-tls.o -MD -MP -MF .deps/libzbxcrypto_a-tls.Tpo -c -o libzbxcrypto_a-tls.o `test -f 'tls.c' || echo './'`tls.c
mv -f .deps/libzbxcrypto_a-tls.Tpo .deps/libzbxcrypto_a-tls.Po
rm -f libzbxcrypto.a
ar cru libzbxcrypto.a libzbxcrypto_a-md5.o libzbxcrypto_a-base64.o libzbxcrypto_a-tls.o
ranlib libzbxcrypto.a
make[4]: 进入目录“/usr/src/zabbix-4.0.30/src/libs/zbxcrypto”
make[4]: 对“install-exec-am”无需做任何事。
make[4]: 对“install-data-am”无需做任何事。
make[4]: 离开目录“/usr/src/zabbix-4.0.30/src/libs/zbxcrypto”
make[3]: 离开目录“/usr/src/zabbix-4.0.30/src/libs/zbxcrypto”
Making install in zbxcommon
......
......
......
make[2]: 对“install-exec-am”无需做任何事。
make[2]: 对“install-data-am”无需做任何事。
make[2]: 离开目录“/usr/src/zabbix-4.0.30/misc”
make[1]: 离开目录“/usr/src/zabbix-4.0.30/misc”
make[1]: 进入目录“/usr/src/zabbix-4.0.30”
make[2]: 进入目录“/usr/src/zabbix-4.0.30”
make[2]: 对“install-exec-am”无需做任何事。
make[2]: 对“install-data-am”无需做任何事。
make[2]: 离开目录“/usr/src/zabbix-4.0.30”
make[1]: 离开目录“/usr/src/zabbix-4.0.30”
[root@localhost zabbix-4.0.30]#
3.6 zabbix 服务端的配置!!!
[root@localhost ~]# ls /usr/local/etc/
zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.d
[root@localhost ~]# vim /usr/local/etc/zabbix_server.conf
# Mandatory: no
# Default:
# DBPassword=zabbix123! (设置zabbix的数据库链接密码!!!)
### Option: DBSocket
# Path to MySQL socket.
#
重启zabbix_server和zabbix_agentd!!!
[root@localhost zabbix-4.0.30]# zabbix_server
[root@localhost zabbix-4.0.30]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
LISTEN 0 80 *:3306 *:*
[root@localhost zabbix-4.0.30]# zabbix_agentd
[root@localhost zabbix-4.0.30]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
LISTEN 0 80 *:3306 *:*
3.7 zabbix服务端web界面安装与配置
3.7.1 zabbix web界面安装前配置
修改/etc/php.ini的配置并重启php-fpm
[root@localhost zabbix-4.0.30]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@localhost zabbix-4.0.30]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@localhost zabbix-4.0.30]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@localhost zabbix-4.0.30]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost zabbix-4.0.30]# service php-fpm restart
Redirecting to /bin/systemctl restart php-fpm.service
[root@localhost zabbix-4.0.30]# ls
aclocal.m4 compile config.sub depcomp m4 misc src
AUTHORS conf configure frontends Makefile missing
bin config.guess configure.ac include Makefile.am NEWS
build config.log COPYING INSTALL Makefile.in README
ChangeLog config.status database install-sh man sass
[root@localhost zabbix-4.0.30]# mkdir /usr/local/apache/htdocs/zabbix
[root@localhost zabbix-4.0.30]# cp -a frontends/php/* /usr/local/apache/htdocs/zabbix/
[root@localhost zabbix-4.0.30]# chown -R apache.apache /usr/local/apache/htdocs
配置apache虚拟机!!!
[root@localhost ~]# vim /etc/httpd24/httpd.conf
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/zabbix"
ServerName zabbix.liuzezheng.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1
<Directory "/usr/local/apache/htdocs/zabbix">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
设置zabbix/conf目录的权限,让zabbix有权限生成配置文件zabbix.conf.php
[root@localhost ~]# chmod 777 /usr/local/apache/htdocs/zabbix/conf
[root@localhost ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxrwsrwx. 2 apache apache 81 3月 29 04:33 /usr/local/apache/htdocs/zabbix/conf
3.7.2 重启apache!!!
[root@localhost ~]# apachectl -t
Syntax OK
[root@localhost ~]# apachectl stop
[root@localhost ~]# apachectl start
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port Process
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 32 192.168.122.1:53 0.0.0.0:*
LISTEN 0 128 0.0.0.0:22 0.0.0.0:*
LISTEN 0 5 127.0.0.1:631 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 0.0.0.0:10051 0.0.0.0:*
LISTEN 0 128 0.0.0.0:9000 0.0.0.0:*
LISTEN 0 128 [::]:111 [::]:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
LISTEN 0 80 *:3306 *:*
3.7.3 安装zabbix web界面