当前位置:网站首页>在LAMP架构中部署Zabbix监控系统及邮件报警机制
在LAMP架构中部署Zabbix监控系统及邮件报警机制
2022-07-24 15:32:00 【星哥玩云】
初步了解Zabbix:
Zabbix能监视各种网络参数,保证服务器系统的安全运营;并提供灵活的通知机制以让系统管理员快速定位/解决存在的各种问题。是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案。被监控对象只要支持SNMP协议或者运行Zabbix_agents代理程序即可。 agent端:主机通过安装agent方式采集数据。 server端:通过收集agent发送的数据,写入数据库(MySQL,Oracle等),再通过php+apache在web前端展示.
SNMP:
SNMP是英文"Simple Network Management Protocol"的缩写,中文意思是"简单网络管理协议"。SNMP是一种简单网络管理协议,它属于TCP/IP五层协议中的应用层协议,用于网络管理的协议。SNMP主要用于网络设备的管理。
Zabbix工作原理:
Agentd安装在被监控的主机上,Agent负责定期收集客户端本地各项数据,并发送至Zabbix Server端,Zabbix Server收到数据,将数据存储到数据库中,用户基于Zabbix WEB可以看到数据在前端展现图像。当Zabbix监控某个具体的项目,改项目会设置一个触发器阈值,当被监控的指标超过该触发器设定的阈值,会进行一些必要的动作,动作包括:发送信息(邮件、微信、短信)、发送命令(SHELL 命令、Reboot、Restart、Install等)。
Zabbix重要的五个组件:
1、Zabbix Server:负责接收agent发送的报告信息的核心组件,所有配置,统计数据及操作数据均由其组织进行; 2、Database Storage:专用于存储所有配置信息,以及由Zabbix收集的数据; 3、Web interface:Zabbix的GUI接口,通常与Server运行在同一台主机上; 4、Proxy:可选组件,常用于分布监控环境中,代理Server收集部分被监控端的监控数据并统一发往Server端; 5、Agent:部署在被监控主机上,负责收集本地数据并发往Server端或Proxy端;
Zabbix基本组件拓扑:
下面我对如何部署zabbix进行详细配置
实验环境:
一、部署LAMP架构 下载LAMP所需安装包
[[email protected] ~]# yum install httpd mariadb mariadb-server php php-mysql php-gd libjpeg* php-ldap php-odbc php-pear php-xml php-xmlrpc php-mhash -y
配置Apache主配置文件
[[email protected] ~]# vim /etc/httpd/conf/httpd.conf ServerName www.yun.com:80 #修改域名 DirectoryIndex index.html index.php #让Apache支持PHP
为了让zabbix连接互联网,设置中国时区
[[email protected] ~]# vim /etc/php.ini date.timezone = PRC
开启httpd服务和mysql
[[email protected] ~]# systemctl start httpd.service [[email protected] ~]# systemctl start mariadb.service [[email protected] ~]# netstat -ntap | egrep '80|3306' #查看两个服务的端口 tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 38513/mysqld tcp6 0 0 :::80 :::* LISTEN 38242/httpd
重新配置mariadb数据库的参数
[[email protected] ~]# mysql_secure_installation Set root password? [Y/n] y #是否设置密码 Remove anonymous users? [Y/n] n #是否删除默认用户 Disallow root login remotely? [Y/n] n #是否禁止root远程登录 Remove test database and access to it? [Y/n] n #是否删除测试数据库 Reload privilege tables now? [Y/n] y #是否对数据库进行初始化配置
创建zabbix数据库
[[email protected] ~]# mysql -uroot -p MariaDB [(none)]> create database zabbix character set utf8 collate utf8_bin; #创建一个zabbix数据库 MariaDB [(none)]> grant all on zabbix.* to 'zabbix'@'%' identified by '123123'; #为zabbix数据库创建管理用户 MariaDB [(none)]> flush privileges;
创建PHP测试首页
[[email protected] ~]# vim /var/www/html/index.php <?php phpinfo(); ?>
编写测试脚本,测试PHP能否连接数据库
<?php
在使用zabbix用户进行登录数据库时有时会出现登录失败的现象,这是因为里面有空用户占用导致本地用户无法登录,所以需要删除空用户
[[email protected] ~]# mysql -u zabbix -p #登录失败 Enter password: ERROR 1045 (28000): Access denied for user 'zabbix'@'localhost' (using password: YES)
[[email protected] ~]# mysql -u root -p MariaDB [(none)]> select user,host from mysql.user; #有空用户占用导致本地用户无法登陆 +--------+-----------------------+ | user | host | +--------+-----------------------+ | zabbix | % | | root | 127.0.0.1 | | root | ::1 | | | localhost | | root | localhost | | | localhost.localdomain | | root | localhost.localdomain | +--------+-----------------------+ 7 rows in set (0.00 sec)
MariaDB [(none)]> drop user ''@'localhost'; #删除空用户 Query OK, 0 rows affected (0.01 sec)
MariaDB [(none)]> drop user ''@'localhost.localdomain'; #删除空用户 Query OK, 0 rows affected (0.00 sec)
[[email protected] ~]# mysql -u zabbix -p #再次登录就可以了 MariaDB [(none)]>
到此为止,LAMP架构就部署完了
二、部署zabbix server
[[email protected] ~]# yum install php-bcmath php-mbstring -y #下载两个PHP依赖包 [[email protected]~]#rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm #下载zabbix yum源,安装完成后会自动产生repo文件 [[email protected] ~]# yum install zabbix-server-mysql zabbix-web-mysql -y #安装zabbix软件包
修改zabbix配置文件
[[email protected] ~]# grep -n '^'[a-Z] /etc/zabbix/zabbix_server.conf #以下为需要修改的行 38:LogFile=/var/log/zabbix/zabbix_server.log 49:LogFileSize=0 72:PidFile=/var/run/zabbix/zabbix_server.pid 82:SocketDir=/var/run/zabbix 101:DBName=zabbix 117:DBUser=zabbix 125:DBPassword=123123 #密码改为zabbix登陆密码 357:SNMPTrapperFile=/var/log/snmptrap/snmptrap.log 475:Timeout=4 518:AlertScriptsPath=/usr/lib/zabbix/alertscripts 529:ExternalScripts=/usr/lib/zabbix/externalscripts 565:LogSlowQueries=3000
[[email protected] ~]# vim /etc/httpd/conf.d/zabbix.conf #修改时区 php_value date.timezone Asia/Shanghai
[[email protected] ~]# vim /usr/share/zabbix/include/defines.inc.php #修正图表中文乱码 :%s /graphfont/kaiti/g #将配置文件中的graphfont替换为kaiti [[email protected] ~]# cp STKAITI.TTF /usr/share/zabbix/fonts/ #从微软系统下复制相应的字体文件到/usr/share/zabbix/fonts/
开启zabbix服务端
[[email protected] ~]# systemctl start zabbix-server.service [[email protected] ~]# systemctl enable zabbix-server.service [[email protected] ~]# netstat -ntap | grep 10051 #查看端口 tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 40703/zabbix_server tcp6 0 0 :::10051 :::* LISTEN 40703/zabbix_server
[[email protected] ~]# systemctl restart httpd.service #重启Apache服务
http://192.168.199.129/zabbix #在浏览器上登陆zabbix页面
首先看见的是zabbix的版本:
这里所有的选项都为OK表示配置是没问题的:
密码为zabbix的登陆密码:
名字填写zabbix:
默认的用户名和密码为Admin和zabbix:
登陆完成后便会到zabbix的监控页面:
点击右上角头像可以选择语言,这里我选择中文:
三、安装被监控端
[[email protected] ~]# systemctl stop firewalld.service #关闭防火墙 [[email protected] ~]# setenforce 0
[[email protected]~]#rpm -ivh http://repo.zabbix.com/zabbix/3.5/rhel/7/x86_64/zabbix-release-3.5-1.el7.noarch.rpm #下载yum源 [[email protected] ~]# yum install zabbix-agent -y #被监控端需要装agent包,如果想要监控本机器,也可以在监控服务器上进行安装
更改配置文件
[[email protected] ~]# grep -n '^'[a-Z] /etc/zabbix/zabbix_agentd.conf #更改配置文件以下选项 13:PidFile=/var/run/zabbix/zabbix_agentd.pid 32:LogFile=/var/log/zabbix/zabbix_agentd.log 43:LogFileSize=0 98:Server=192.168.199.129 #将地址指向服务器端 139:ServerActive=192.168.199.129 #将地址指向服务器端 150:Hostname=test #名字可自行定义 268:Include=/etc/zabbix/zabbix_agentd.d/*.conf
开启服务
[[email protected] ~]# systemctl start zabbix-agent.service [[email protected] ~]# systemctl enable zabbix-agent.service Created symlink from /etc/systemd/system/multi-user.target.wants/zabbix-agent.service to /usr/lib/systemd/system/zabbix-agent.service. [[email protected] ~]# netstat -ntap | grep zabbix #查看端口 tcp 0 0 0.0.0.0:10050 0.0.0.0:* LISTEN 40351/zabbix_agentd tcp6 0 0 :::10050 :::* LISTEN 40351/zabbix_agentd
在服务器上配置完了就可以到zabbix监控页面进行配置 首先在监控页面中添加被监控服务器
配置主机项基本信息
配置模板选项,添加想要监控的模块
查看添加好的主机信息
回到主界面,点击刷新,过一会就回出现监控信息
四、配置邮件报警功能-----在监控服务器上配置
[[email protected] ~]# yum install mailx -y #下载邮箱服务 [[email protected] ~]# vim /etc/mail.rc #在文件末尾添加如下配置 set from=邮箱地址 set smtp=smtp.qq.com set smtp-auth-user=邮箱地址 set smtp-auth-password=********** #如果填写的是qq邮箱,密码为qq邮箱的SMTP密码 set smtp-auth=login
[[email protected] ~]# systemctl restart postfix.service #重新启动邮箱服务
[[email protected] ~]# echo "hello world" | mail -s "testmail" 邮箱地址 #发送一个测试邮件
可以看到我在QQ邮箱中收到了一封邮件
[[email protected] ~]# vim /usr/lib/zabbix/alertscripts/mail.sh #写一个发邮件的脚本,脚本路径一定要写对 #!/bin/bash #send mail
messages=`echo $3 | tr '\r\n' '\n'` subject=`echo $2 | tr '\r\n' '\n'` echo "${messages}" | mail -s "${subject}" $1 >>/tmp/mail.log 2>&1[[email protected] ~]# chmod +x /usr/lib/zabbix/alertscripts/mail.sh #给脚本执行权限 [[email protected] ~]# touch /tmp/mail.log #创建邮箱日志文件 [[email protected] ~]# chown -R zabbix.zabbix /tmp/mail.log #将权限给zabbix用户 [[email protected] ~]# chown -R zabbix.zabbix /usr/lib/zabbix/再次发送一封测试邮件使用脚本执行
[[email protected] ~]# cd /usr/lib/zabbix/alertscripts/ [[email protected] alertscripts]# ./mail.sh 邮箱地址 "yun" "hahahahaha" #发送格式为“地址”“标题”“内容”
六、配置zabbix邮件报警机制 1 选择报警媒介类型
2 选择管理用户
3 在动作配置项中定义报警邮件的发送形式
4 配置恢复操作后邮件的发送形式
七、测试,如果我关闭受监控的服务来模拟服务故障,zabbix一个会发送一封邮件提醒我,当我再次打开这个服务时表示这个服务已经被修复,zabbix一个也会发一封恢复邮件。
[[email protected] ~]# systemctl stop sshd.service #关闭被监控端的ssh服务
接着便会收到邮件信息了:
[[email protected] ~]# systemctl start sshd.service #我再次开启被监控端的SSH服务
到此为止Zabbix监控系统就搭建完成了。
边栏推荐
- Which securities company is good at opening an account with flush? Excuse me, is it safe to open an account with mobile phone or stock?
- Exomeiser annotates and prioritizes exome variants
- 遭受DDoS时,高防IP和高防CDN的选择
- Force button 31. Next arrangement -- double finger needling
- Kubectl_好用的命令行工具:oh-my-zsh_技巧和窍门
- Intelligent operation and maintenance scenario analysis: how to detect abnormal business system status through exception detection
- Android SQLite database practice
- Introduction to single chip microcomputer: LED lights cycle to the left and turn on
- 4279. Cartesian tree
- Exomiser对外显子组变体进行注释和优先排序
猜你喜欢

Various searches (⊙▽⊙) consolidate the chapter of promotion

Still using listview? Use animatedlist to make list elements move
![[shaders realize pixelate mosaic effect _shader effect Chapter 7]](/img/0f/3e8d9468d94b14217875c7e447aa15.png)
[shaders realize pixelate mosaic effect _shader effect Chapter 7]

Choice of advanced anti DDoS IP and CDN in case of DDoS

Jmeter-调用上传文件或图片接口
![Error reporting [project error reporting]](/img/7a/322ba86c13667a62c484b2329ac617.png)
Error reporting [project error reporting]

MongoDB入门学习

【Flutter -- 布局】流式布局(Flow和Wrap)

MySQL build master-slave synchronization - build with docker

Simple encapsulation of wechat applet wx.request
随机推荐
三、集合基础——ArrayList集合与简单学生管理系统
Error: pidfile (celerybeat.pid) already exists when celery starts beat
[bug solution] error in installing pycocotools in win10
Date class and time class definitions (operator overload application)
15. Talk about these common multi-threaded interview questions
(09) flask is OK if it has hands - cookies and sessions
Introduction to single chip microcomputer: LED lights cycle to the left and turn on
YOLO5Face:为什么要重新发明人脸检测器
什么是防火墙?防火墙能发挥什么样的作用?
Discussion on the basic use and address of pointer in array object
MySql函数
27. Directory and file system
Kubectl_ Easy to use command line tool: Oh my Zsh_ Tips and tricks
[tkinter beautification] window out of system style (common to three systems)
未来数据库需要关心的硬核创新
MySQL learning notes (summary)
图的存储和遍历
Cloud development standalone image Jiugongge traffic main source code
Calculate the M-day moving average price of two stocks
2022 RoboCom 世界机器人开发者大赛-本科组(省赛)---第一题 不要浪费金币 (已完结)