栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

zabbix 创建用户及告警媒介设置,配置邮件告警发送qq邮箱/163

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

zabbix 创建用户及告警媒介设置,配置邮件告警发送qq邮箱/163

zabbix 用户组 邮件告警

1. 创建用户组
2. 添加用户
3. 添加告警媒介,邮箱告警配置

先看下触发告警的流程

1.创建用户组


2.为刚刚创建的用户组添加用户



第二个的报警媒介就先不创建,

3.添加告警媒介

在添加告警媒介之前,我们需要先把邮件发送调试成功
发送告警信息有很多方式,我这里是用邮件演示;
邮件发送是主要是通过mailx命令发送,在此之前我们需要先关闭sendmail 和 postfix;

①进入到zabbix-server服务器

#①查看一下sendmail状态,发现我没有这个服务
[root@localhost ~]# systemctl status sendmail
Unit sendmail.service could not be found.
②查看postfix,发现服务是开着的,关闭postfix,并且移除该服务·	
[root@localhost ~]# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
   Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
   Active: active (running) since 二 2021-11-23 23:14:01 CST; 1 day 16h ago
  Process: 1131 ExecStart=/usr/sbin/postfix start (code=exited, status=0/SUCCESS)
  Process: 1127 ExecStartPre=/usr/libexec/postfix/chroot-update (code=exited, status=0/SUCCESS)
  Process: 1088 ExecStartPre=/usr/libexec/postfix/aliasesdb (code=exited, status=0/SUCCESS)
 Main PID: 1430 (master)
    Tasks: 2
   Memory: 6.4M
   CGroup: /system.slice/postfix.service
           ├─1430 /usr/libexec/postfix/master -w
           └─1439 qmgr -l -t unix -u

11月 25 15:30:14 localhost.localdomain postfix/master[1430]: warning: /usr/libexec/postfix/pickup: bad command startup -- throttling
11月 25 15:31:14 localhost.localdomain postfix/pickup[29089]: fatal: parameter inet_interfaces: no local interface found for ::1
11月 25 15:31:15 localhost.localdomain postfix/master[1430]: warning: process /usr/libexec/postfix/pickup pid 29089 exit status 1
11月 25 15:31:15 localhost.localdomain postfix/master[1430]: warning: /usr/libexec/postfix/pickup: bad command startup -- throttling
11月 25 15:32:15 localhost.localdomain postfix/pickup[29113]: fatal: parameter inet_interfaces: no local interface found for ::1
11月 25 15:32:16 localhost.localdomain postfix/master[1430]: warning: process /usr/libexec/postfix/pickup pid 29113 exit status 1
11月 25 15:32:16 localhost.localdomain postfix/master[1430]: warning: /usr/libexec/postfix/pickup: bad command startup -- throttling
11月 25 15:33:16 localhost.localdomain postfix/pickup[29138]: fatal: parameter inet_interfaces: no local interface found for ::1
11月 25 15:33:17 localhost.localdomain postfix/master[1430]: warning: process /usr/libexec/postfix/pickup pid 29138 exit status 1
11月 25 15:33:17 localhost.localdomain postfix/master[1430]: warning: /usr/libexec/postfix/pickup: bad command startup -- throttling
[root@localhost ~]# 
[root@localhost ~]# systemctl stop postfix
[root@localhost ~]# systemctl disable postfix
Removed symlink /etc/systemd/system/multi-user.target.wants/postfix.service.
#安装mailx
[root@localhost ~]# yum install mailx
[root@localhost ~]# 

配置mail.rc之前先打开qq邮箱的pop3/smtp服务,如果用163或者其他邮箱也是要开启
开启会获得一个授权码,记一下,等下要写在配置文件里
开启位置:qq邮箱——>“设置”——>“账户”

#配置mail.rc
[root@localhost ~]# vi /etc/mail.rc
#在配置文件最后加上下面命令
set from=你自己的邮箱@qq.com  (用来发送邮件的)
set smtp=smtp.qq.com
set smtp-auth-user=你自己的邮箱@qq.com  (登录的名字,为了方便可以直接设置为邮箱)
set smtp-auth-password=xxxxxx(这个就是你刚刚获取的授权码)
set smtp-auth=login
#然后保存

#测试一下邮箱能否发送通过
[root@localhost ~]# echo "你想发送的内容" |mailx -s "邮件的标题" xxxx@qq.com(你想发送给谁)
#例如:
[root@localhost ~]# echo "Hello,Xukaidi! test" | mailx -s "Zabbix Mail test" 1134298123@qq.com
[root@localhost ~]# 


ok,邮箱可以通了;

#接下来配置告警发送的脚本
#先查看一下邮件配置文件所在位置,进入到server配置文件里查看
[root@localhost ~]# vim /etc/zabbix/zabbix_server.conf
!!!!!!!!!!!!!!!!!!!!!
#***但是我这里zabbix-server是安装在docker容器里的***
[root@localhost ~]# docker exec -it xkdzabbix  /bin/bash
bash-5.0# vi /etc/zabbix/zabbix_server.conf 
bash-5.0# exit
alertscriptsPath=/usr/lib/zabbix/alertscripts
[root@localhost ~]#
[root@localhost ~]# cd /usr/lib/zabbix/alertscripts
[root@localhost alertscripts]#ls
[root@localhost alertscripts]#vim mail.sh

配置文件内容如下

#!/bin/bash
SENT_TO=$1      告警的接受人
SENT_SUBJECT=$2       标题
SENT_CONTENT=$3       Body

mailx -s "$SENT_SUBJECT" $SENT_TO <$SENT_CONTENT

按“:x”,保存退出;
[root@localhost ~]# docker exec -it xkdzabbix /bin/bash
bash-5.0# chmod a+x mail.sh
bash-5.0# vi mail.sh
bash-5.0# ./mail.sh 1134298123@qq.com “zabbix test2” “test two”

#给脚本添加权限
bash-5.0# chmod a+x mail.sh
bash-5.0# vi mail.sh
bash-5.0# ./mail.sh  1134298123@qq.com "zabbix test2" "test two"
./mail.sh: line 7: mailx: command not found

!!! !!! !!!
就在我以为一切都很完美的时候;
报错了,mailx找不到,
我忘了我的服务是在docker里面的,而前面我是把mailx安装在了虚拟机上,docker容器里根本没有mailx

那我在docker里安装一下***,我不知道是否是应该安装这个,网上也找不到,有谁知道,评论告诉我一下,我安装完,进入docker里执行脚本依然报错,***

[root@localhost ~]# docker search heirloom-mailx
NAME                            DEscriptION                                     STARS     OFFICIAL   AUTOMATED
corentinaltepe/heirloom-mailx   Heirloom-mailx in Alpine to easily send emai…   5                    
fezzz/php-fpm                   php8.0-fpm(latest) image for nextcloud:  Ser…   1                    [OK]
harobed/docker-heirloom-mailx   heirloom-mailx Alpine Docker image              0                    [OK]
teamidefix/vault-mailx          Vault + heirloom-mailx                          0                    
asproat/debian-mailx            Debian stretch with heirloom-mailx              0                    
[root@localhost ~]# docker pull corentinaltepe/heirloom-mailx
Using default tag: latest
latest: Pulling from corentinaltepe/heirloom-mailx
97518928ae5f: Already exists 
6bac87e09cbb: Pull complete 
Digest: sha256:671585c532fa92145b436d66e735cc5f4d64bf80d2cc1efc3def736debef4c41
Status: Downloaded newer image for corentinaltepe/heirloom-mailx:latest
docker.io/corentinaltepe/heirloom-mailx:latest

下图为zabbix-server没有安装在docker里可以执行脚本,就会成功;

错误
[root@localhost ~]# docker exec -it xkdzabbix /bin/bash 
bash-5.0# ./mail.sh  1134298123@qq.com "zabbix test2" "test two"
bash: ./mail.sh: No such file or directory
bash-5.0# cd /usr/lib/zabbix/alertscripts
bash-5.0# ./mail.sh  1134298123@qq.com "zabbix test2" "test two"
./mail.sh: line 6: mailx: command not found
bash-5.0# exit

记录一下错误,后面再搞,关于docker安装的这个heirloom-mailx配置文件,和上面mail.rc是一样的

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/603758.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号