1.zabbix介绍
zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。
zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。
zabbix由2部分构成,与可选组件。zabbix serverzabbix agent
zabbix server可以通过,端口监视等方法提供对远程服务器/网络状态的监视,数据收集等功能,它可以运行在Linux,Ubuntu,Solaris,HP-UX,AIX,Free BSD,Open BSD,OS X等平台上。SNMPzabbix agentping
zabbix agent需要安装在被监视的目标服务器上,它主要完成对硬件信息或与操作系统有关的内存,CPU等信息的收集。
zabbix server可以单独监视远程服务器的服务状态;同时也可以与配合,可以轮询主动接收监视数据(agent方式),同时还可被动接收发送的数据(trapping方式)。
另外还支持SNMP (v1,v2),可以与SNMP软件(例如:net-snmp)等配合使用。zabbix agentzabbix agentzabbix agentzabbix server
2. zabbix特点
zabbix的主要特点:
-
安装与配置简单,学习成本低
-
支持多语言(包括中文)
-
免费开源
-
自动发现服务器与网络设备
-
分布式监视以及WEB集中管理功能
-
可以无代理监视
-
用户安全认证和柔软的授权方式
-
通过WEB界面设置或查看监视结果
-
电子邮件等通知功能
Zabbix主要功能: -
CPU负荷
-
内存使用
-
磁盘使用
-
网络状况
-
端口监视
-
日志监视
3. zabbix配置文件
zabbix配置文件有两种:
服务器端配置文件(/usr/local/etc/zabbix_server.conf)
客户端配置文件(/usr/local/etc/zabbix_agentd.conf)
zabbix代理配置文件(/usr/local/etc/zabbix_proxy.conf)
服务器端配置文件zabbix_server.conf常用配置参数:
客户端配置文件zabbix_agentd.conf常用配置参数:
4. 部署zabbix
环境说明:
环境 | 知识产权 | 要安装的应用 |
---|---|---|
服务器 | 192.168.106.16 | lamp 架构 zabbix server zabbix agent |
客户端 | 192.168.106.17 | zabbix agent |
因为zabbix是用php语言开发的,所以必须先部署lamp架构,使其能够支持运行php网页,如果没有部署lamp可以去查看编译安装lamp
4.1 zabbix服务端安装
//安装依赖包
[root@localhost ~]# yum -y install net-snmp-devel libevent-devel
//下载5.0的zabbix
[root@localhost ~]# wget https://cdn.zabbix.com/zabbix/sources/stable/5.0/zabbix-5.0.25.tar.gz
//解压
[root@localhost ~]# tar -zxvf zabbix-5.0.25.tar.gz //过程已省略
//创建一个名为zabbix的系统用户
[root@localhost ~]# useradd -r -M -s /sbin/nologin zabbix
//创建用于存放数据的目录
[root@localhost ~]# mkdir /usr/lib/zabbix
[root@localhost ~]# chown zabbix.zabbix /usr/lib/zabbix
[root@localhost ~]# chmod 770 /usr/lib/zabbix
配置zabbix数据库
[root@localhost ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.7.37 MySQL Community Server (GPL)
Copyright (c) 2000, 2022, 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> create user 'zabbix'@'localhost' identified by '<zabbix>';
Query OK, 0 rows affected (0.01 sec)
mysql> grant all privileges on zabbix.* to 'zabbix'@'localhost';
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> quit
Bye
把数据导入到数据库
[root@localhost ~]# cd zabbix-5.0.25/database/mysql/
[root@localhost mysql]# ls
data.sql double.sql images.sql Makefile.am Makefile.in schema.sql
[root@localhost mysql]# mysql -uzabbix -p'<zabbix>' zabbix < schema.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -p'<zabbix>' zabbix < images.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
[root@localhost mysql]# mysql -uzabbix -p'<zabbix>' zabbix < data.sql
mysql: [Warning] Using a password on the command line interface can be insecure.
配置Zabbix服务器和代理的源代码
/由于我用的是虚拟机上面跑的,所以有些配置我是没有写进去的。如有需要请参考官方文档
[root@localhost mysql]# cd ..
[root@localhost database]# cd ..
[root@localhost zabbix-5.0.25]# ./configure --enable-server --enable-agent --with-mysql --with-net-snmp --with-libcurl --with-libxml2 //编译已省略 最后效果如下
***********************************************************
* Now run 'make install' *
* *
* Thank you for using Zabbix! *
* <http://www.zabbix.com> *
***********************************************************
//编译安装
[root@localhost zabbix-5.0.25]# make install //编译安装已省略
4.2 zabbix服务端配置
[root@localhost zabbix-5.0.25]# 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
DBpassword=zabbix //设置zabbix数据库连接密码
//启动zabbix_server
[root@localhost ~]# zabbix_server
[root@localhost ~]# zabbix_agentd
[root@localhost ~]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
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:* //看到10051就说明成功了
LISTEN 0 128 0.0.0.0:10050 0.0.0.0:*
LISTEN 0 128 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:111 [::]:*
4.3 zabbix服务端web界面安装与配置
4.3.1 zabbix web界面安装前配置
//修改/etc/php.ini的配置并重启php-fpm
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
//删除/usr/local/apache/htdocs/的所有文件
[root@localhost etc]# cd /usr/local/apache/htdocs/
[root@localhost htdocs]# ls
index.html test.com
[root@localhost htdocs]# rm -rf *
[root@localhost ~]# cd zabbix-5.0.25/
[root@localhost zabbix-5.0.25]# mkdir /usr/local/apache/htdocs/zabbix
[root@localhost zabbix-5.0.25]# cp -a ui/* /usr/local/apache/htdocs/zabbix/
[root@localhost zabbix-5.0.25]# cd /usr/local/apache/htdocs/zabbix/
[root@localhost zabbix]# ls //文件以及放到里面去了
actionconf.php hostgroups.php overview.php
api_jsonrpc.php hostinventoriesoverview.php queue.php
app hostinventories.php report2.php
applications.php host_prototypes.php report4.php
assets host_screen.php robots.txt
audio hosts.php screenconf.php
auditacts.php httpconf.php screenedit.php
browserwarning.php httpdetails.php screen.import.php
chart2.php image.php screens.php
chart3.php imgstore.php services.php
chart4.php include setup.php
chart5.php index_http.php slideconf.php
chart6.php index.php slides.php
chart7.php index_sso.php srv_status.php
chart.php items.php sysmap.php
conf js sysmaps.php
conf.import.php jsLoader.php templates.php
correlation.php jsrpc.php toptriggers.php
discoveryconf.php local tr_events.php
disc_prototypes.php locale trigger_prototypes.php
favicon.ico maintenance.php triggers.php
graphs.php map.import.php vendor
history.php map.php zabbix.php
host_discovery.php modules
//配置apache虚拟主机
[root@localhost zabbix]# cd ..
[root@localhost htdocs]# cd ..
[root@localhost apache]# vim conf/httpd.conf
<VirtualHost *:80>
DocumentRoot "/usr/local/apache/htdocs/zabbix/"
ServerName zabbix.example.com
ProxyRequests Off
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000/usr/local/apache/htdocs/zabbix/$1
<Directory "/usr/local/apache/htdocs/test.com">
Options none
AllowOverride none
Require all granted
</Directory>
</VirtualHost>
//设置zabbix/conf目录的权限,让zabbix有权限生成配置文件zabbix.conf.php
[root@localhost apache]# chmod 777 /usr/local/apache/htdocs/zabbix/conf/
[root@localhost apache]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxrwxrwx. 3 cxr cxr 94 6月 27 03:41 /usr/local/apache/htdocs/zabbix/conf
//重启apache
[root@localhost apache]# apachectl -t
Syntax OK
[root@localhost apache]# apachectl stop
[root@localhost apache]# apachectl start
[root@localhost apache]# ss -antl
State Recv-Q Send-Q Local Address:Port Peer Address:Port
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 127.0.0.1:9000 0.0.0.0:*
LISTEN 0 128 0.0.0.0:111 0.0.0.0:*
LISTEN 0 128 *:80 *:*
LISTEN 0 128 [::]:22 [::]:*
LISTEN 0 5 [::1]:631 [::]:*
LISTEN 0 80 *:3306 *:*
LISTEN 0 128 [::]:111 [::]:*
//关闭防火墙以及selinux
[root@localhost apache]# systemctl stop firewalld.service
[root@localhost apache]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset>
Active: inactive (dead) since Wed 2022-07-06 09:02:51 EDT; 21s ago
Docs: man:firewalld(1)
Process: 1112 ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS (code>
Main PID: 1112 (code=exited, status=0/SUCCESS)
7月 06 06:45:57 localhost.localdomain systemd[1]: Starting firewalld - dynamic firew>
7月 06 06:45:59 localhost.localdomain systemd[1]: Started firewalld - dynamic firewa>
7月 06 06:45:59 localhost.localdomain firewalld[1112]: WARNING: AllowZoneDrifting is>
7月 06 09:02:50 localhost.localdomain systemd[1]: Stopping firewalld - dynamic firew>
7月 06 09:02:51 localhost.localdomain systemd[1]: Stopped firewalld - dynamic firewa>
[root@localhost apache]# setenforce 0
4.3.2 安装zabbix web界面
-
修改/etc/hosts文件,添加域名与IP的映射
在你的真机上的C:\Windows\System32\drivers\etc\hosts文件中添加以下一行
-
在浏览器上访问域名,本文设置的域名为zabbix.example.com,你需要修改成你自己的域名
-
在浏览器上访问域名进行安装
-
恢复zabbix/conf目录的权限为755
[root@localhost ~]# chmod 755 /usr/local/apache/htdocs/zabbix/conf
[root@localhost ~]# ll -d /usr/local/apache/htdocs/zabbix/conf
drwxr-xr-x. 3 apache apache 117 7月 6 09:16 /usr/local/apache/htdocs/zabbix/conf
4.4 登录zabbix
zabbix默认登录用户名和密码:
用户名 | 密码 |
---|---|
Admin | zabbix |