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方式)。
另外zabbix server还支持SNMP (v1,v2),可以与SNMP软件(例如:net-snmp)等配合使用。
zabbix特点与功能
zabbix的主要特点:
安装与配置简单,学习成本低
支持多语言(包括中文)
免费开源
自动发现服务器与网络设备
分布式监视以及WEB集中管理功能
可以无agent监视
用户安全认证和柔软的授权方式
通过WEB界面设置或查看监视结果
email等通知功能
Zabbix主要功能:
CPU负荷
内存使用
磁盘使用
网络状况
端口监视
日志监视
zabbix配置文件
zabbix配置文件种类:
1、服务器端配置文件(/usr/local/etc/zabbix_server.conf)
2、客端配置文件(/usr/local/etc/zabbix_agentd.conf)
3、zabbix代理配置文件(/usr/local/etc/zabbix_proxy.conf)
服务器端配置文件zabbix-server.conf常用配置参数:
参数 | 作用 |
---|---|
LogFile | 设置服务端日志文件存放路径 |
ListenIP | 设置服务端监听IP |
ListenPort | 设置服务端监听的端口号 |
PidFile | 设置服务端进程号文件存放路径 |
DBHost | 指定zabbix的数据库服务器IP |
DBName | 指定zabbix使用数据库库名 |
DBUser | 指定zabbix数据库登录用户 |
DBPassword | 指定zabbix数据库登录密码 |
DBPort | 指定zabbix数据库端口号 |
User | 指定zabbix以什么用户的身份运行 |
AlertScriptsPath | 设置告警脚本存放路径 |
ExternalScripts | 外部脚本存放路径 |
客户端配置文件zabbix_agentd.conf常用配置参数:
参数 | 作用 |
---|---|
server | 指定zabbix服务器的IP域名 |
serverActive | 指定zabbix服务器的IP或域名 |
Hostname | 指定主机的主机名,此项必须与web界面配置项一致 |
UnsafeUserParameters | 是否启用自定义监控项,可选值为1或0 |
UserParameter | 指定自定义监控脚本参数 |
LogFile | 设置客户端日志文件存放路径 |
部署zabbix
环境说明:服务端安装lamp架构、zabbix server、zabbix agent,客户端安装zabbix agent。
环境 | IP |
---|---|
服务端 | 192.168.175.100 |
客户端 | 192.168.175.150 |
1.安装依赖包
[root@localhost ~]# yum -y install net-snmp-devel libevent-devel
已加载插件:fastestmirror
Repository base is listed more than once in the configuration
Repository updates is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Repository centosplus is listed more than once in the configuration
Repository 'base': Error parsing config: Error parsing "baseurl = 'local'": URL must be http, ftp, file or https not ""
base | 3.6 kB 00:00:00
epel/x86_64/metalink | 8.9 kB 00:00:00
extras | 2.9 kB 00:00:00
remi-php74 | 3.0 kB 00:00:00
remi-safe | 3.0 kB 00:00:00
updates | 2.9 kB 00:00:00
remi-safe/primary_db | 1.7 MB 00:03:22
Loading mirror speeds from cached hostfile
* base: mirrors.cn99.com
* epel: hkg.mirror.rackspace.com
* extras: mirrors.ustc.edu.cn
* remi-php74: mirrors.tuna.tsinghua.edu.cn
* remi-safe: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.cn99.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 libevent-devel.x86_64.0.2.0.21-4.el7 将被 安装
--> 正在处理依赖关系 libevent = 2.0.21-4.el7,它被软件包 libevent-devel-2.0.21-4.el7.x86_64 需要
--> 正在处理依赖关系 libevent_pthreads-2.0.so.5()(64bit),它被软件包 libevent-devel-2.0.21-4.el7.x86_64 需要
--> 正在处理依赖关系 libevent_openssl-2.0.so.5()(64bit),它被软件包 libevent-devel-2.0.21-4.el7.x86_64 需要
此处省略。。。。。。。
作为依赖被升级:
elfutils-libelf.x86_64 0:0.176-4.el7 elfutils-libs.x86_64 0:0.176-4.el7
libdb.x86_64 0:5.3.21-25.el7 libdb-utils.x86_64 0:5.3.21-25.el7
rpm.x86_64 0:4.11.3-43.el7 rpm-build-libs.x86_64 0:4.11.3-43.el7
rpm-libs.x86_64 0:4.11.3-43.el7 rpm-python.x86_64 0:4.11.3-43.el7
完毕!
[root@localhost ~]#
2.下载zabbix包并解压(在zabbix.com网站中下载)
[root@localhost ~]# ls
! php-7.4.7 zabbix-5.0.2.tar.gz
anaconda-ks.cfg php-7.4.7.tar.xz
mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz remi-release-7.rpm
[root@localhost ~]# tar xf zabbix-5.0.2.tar.gz
[root@localhost ~]# ls
! php-7.4.7 zabbix-5.0.2
anaconda-ks.cfg php-7.4.7.tar.xz zabbix-5.0.2.tar.gz
mysql-5.7.30-linux-glibc2.12-x86_64.tar.gz remi-release-7.rpm
3.创建用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin zabbix
4.配置zabbix数据库
[root@localhost ~]# mysql -uroot -p123456
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.30 MySQL Community Server (GPL)
Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
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.01 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye
[root@localhost ~]# cd zabbix-5.0.2
[root@localhost zabbix-5.0.2]#
[root@localhost zabbix-5.0.2]# cd database/
[root@localhost database]# cd mysql/
[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.
5.编译安装
[root@localhost ~]# cd zabbix-5.0.2
[root@localhost zabbix-5.0.2]# pwd
/root/zabbix-5.0.2
[root@localhost zabbix-5.0.2]# ls
aclocal.m4 ChangeLog config.sub database install-sh man README
AUTHORS compile configure depcomp m4 misc sass
bin conf configure.ac include Makefile.am missing src
build config.guess COPYING INSTALL Makefile.in NEWS ui
[root@localhost zabbix-5.0.2]# ./configure --enable-server \
> --enable-agent \
> --with-mysql \
> --with-net-snmp \
> --with-libcurl \
> --with-libxml2
[root@localhost zabbix-5.0.2]# make install
zabbix服务端配置
[root@localhost ~]# cd /usr/local/etc/
[root@localhost etc]# ls
zabbix_agentd.conf zabbix_agentd.conf.d zabbix_server.conf zabbix_server.conf.d
[root@localhost etc]# vim zabbix_server.conf 修改以下图片内容
[root@localhost ~]# pkill zabbix
[root@localhost ~]# zabbix_server
[root@localhost ~]# ss -antl (10051端口号出来即启动成功)
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 *:9000 *:*
LISTEN 0 80 :::3306 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
[root@localhost etc]# zabbix_agentd
[root@localhost etc]# ss -antl (10050端口号出来即启动成功)
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 *:10050 *:*
LISTEN 0 128 *:10051 *:*
LISTEN 0 128 *:9000 *:*
LISTEN 0 80 :::3306 :::*
LISTEN 0 128 :::80 :::*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
zabbix web界面安装前配置
[root@localhost ~]# cd zabbix-5.0.2
[root@localhost zabbix-5.0.2]# ls
aclocal.m4 ChangeLog config.log configure.ac include Makefile misc sass
AUTHORS compile config.status COPYING INSTALL Makefile.am missing src
bin conf config.sub database install-sh Makefile.in NEWS ui
build config.guess configure depcomp m4 man README
[root@localhost zabbix-5.0.2]# cd ui
[root@localhost ui]# ls
actionconf.php discoveryconf.php index.php screenedit.php
api_jsonrpc.php disc_prototypes.php index_sso.php screen.import.php
app favicon.ico items.php screens.php
applications.php graphs.php js services.php
assets history.php jsLoader.php setup.php
audio host_discovery.php jsrpc.php slideconf.php
auditacts.php hostgroups.php local slides.php
browserwarning.php hostinventoriesoverview.php locale srv_status.php
chart2.php hostinventories.php maintenance.php sysmap.php
chart3.php host_prototypes.php map.import.php sysmaps.php
chart4.php host_screen.php map.php templates.php
chart5.php hosts.php modules toptriggers.php
chart6.php httpconf.php overview.php tr_events.php
chart7.php httpdetails.php queue.php trigger_prototypes.php
chart.php image.php report2.php triggers.php
conf imgstore.php report4.php vendor
conf.import.php include robots.txt zabbix.php
correlation.php index_http.php screenconf.php
[root@localhost ui]# cd ..
[root@localhost zabbix-5.0.2]# cp -r ui /usr/local/apache/htdocs/zabbix
[root@localhost zabbix-5.0.2]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# ls
index.html xunxian zabbix
[root@localhost htdocs]# chown -R apache.apache zabbix/
[root@localhost htdocs]# cd
[root@localhost ~]# vim /etc/httpd24/httpd.conf
[root@localhost ~]# cd /usr/local/apache/htdocs/zabbix/
[root@localhost zabbix]# ls
actionconf.php discoveryconf.php index.php screenedit.php
api_jsonrpc.php disc_prototypes.php index_sso.php screen.import.php
app favicon.ico items.php screens.php
applications.php graphs.php js services.php
assets history.php jsLoader.php setup.php
audio host_discovery.php jsrpc.php slideconf.php
auditacts.php hostgroups.php local slides.php
browserwarning.php hostinventoriesoverview.php locale srv_status.php
chart2.php hostinventories.php maintenance.php sysmap.php
chart3.php host_prototypes.php map.import.php sysmaps.php
chart4.php host_screen.php map.php templates.php
chart5.php hosts.php modules toptriggers.php
chart6.php httpconf.php overview.php tr_events.php
chart7.php httpdetails.php queue.php trigger_prototypes.php
chart.php image.php report2.php triggers.php
conf imgstore.php report4.php vendor
conf.import.php include robots.txt zabbix.php
correlation.php index_http.php screenconf.php
[root@localhost zabbix]# ll -d conf
drwxr-xr-x. 3 apache apache 94 7月 21 11:32 conf
[root@localhost zabbix]# ls conf
certs maintenance.inc.php zabbix.conf.php.example
[root@localhost zabbix]# chmod 777 conf
[root@localhost zabbix]# apachectl stop
[root@localhost zabbix]# apachectl start
[root@localhost zabbix]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@localhost zabbix]# service mysqld restart
Shutting down MySQL.... SUCCESS!
Starting MySQL. SUCCESS!
访问页面
此时发现报错
添加以下内容并重启服务
[root@localhost ~]# sed -ri 's/(post_max_size =).*/\1 16M/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_execution_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -ri 's/(max_input_time =).*/\1 300/g' /etc/php.ini
[root@localhost ~]# sed -i '/;date.timezone/a date.timezone = Asia/Shanghai' /etc/php.ini
[root@localhost ~]# service php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
登录 用户名是Admin 密码是zabbix