zabbix 创建用户及告警媒介设置,配置邮件告警发送qq邮箱/163(上)
用户组 邮件告警
1. 创建用户组
2. 添加用户
先看下触发告警的流程
1.创建用户组
2.为刚刚创建的用户组添加用户
第二个的报警媒介就先不创建,
3.添加告警媒介
在添加告警媒介之前,我们需要先把邮件发送调试成功
发送告警信息有很多方式,我这里是用邮件演示;
邮件发送是主要是通过mailx命令发送,在此之前我们需要先关闭 和 ;
①进入到-服务器
#①查看一下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 AgentLoaded: 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 agoProcess: 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: 2Memory: 6.4MCGroup: /system.slice/postfix.service├─1430 /usr/libexec/postfix/master -w└─1439 qmgr -l -t unix -u11月 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 Bodyecho "$SENT_CONTENT"|mailx -s "$SENT_SUBJECT" $SENT_TO
按“:x”,保存退出;
[root@ ~]# exec -it /bin/bash
bash-5.0# chmod a+x mail.sh
bash-5.0# vi mail.sh
bash-5.0# ./mail.sh “ 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如果zabbix-server是直接部署在虚拟机里的,那么这里就可以直接成功了!
下面是针对server装在docker容器里的问题
!!! !!! !!!
就在我以为一切都很完美的时候;
报错了,mailx找不到,
我忘了我的服务是在里面的,而前面我是把mailx安装在了虚拟机上,容器里根本没有mailx;
那我在里安装一下***,我不知道是否是应该安装这个,网上也找不到,有谁知道,评论告诉我一下,我安装完,进入里执行脚本依然报错,***
[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
下图为-没有安装在里可以执行脚本,就会成功;
错误
[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
记录一下错误,后面再搞,关于安装的这个-mailx配置文件,和上面mail.rc是一样的