Linux实战案列-发送告警邮件

发送告警邮件

准备

  • 外部邮件服务器
    首发在雪月书韵茶香
    原因
    本地自带邮箱容易被过滤,需要延迟性低的邮箱发送

配置docker

配置环境变量

主机版本:macOS 12.6.4

open .bash_profile
export DOCKER_PATH="/Applications/Docker.app/Contents/Resources/bin"
export PATH="$PATH:$DOCKER_PATH"

定义docker bin目录变量为 DOCKER_PATH
配置PATH变量 ,取值$$DOCKER_PATH

source .bash_profile

配置生效,一次性

vim ~/.zsrhrc
source ~/.bash_profile

环境变量配置永久生效
Linux实战案列-发送告警邮件_第1张图片

安装centos7

docker pull centos:centos7

拉取centos7镜像

docker run -itd --name centos centos:centos7

运行容器,设置名字为centos 镜像为centos7

docker exec -it centos /bin/bash

进入centos容器,或者打开桌面docker

安装邮箱小型发送程序

### 安装openssl mailx vim
yum -y install vim
yum install mailx -y
yum search openssl
yum install openssl openssl-devel
 
openssl version -a #安装后验证
vim /etc/mail.arc
   set from=[email protected] smtp=smtp.163.com
   set smtp-auth-user=[email protected] smtp-auth-password=授权码
   set ssl-verify=ignore
set nss-config-dir=/root/.certs
   set smtp-auth=login
  

from:对方收到邮件时显示的发件人
smtp:指定第三方发邮件的smtp服务器地址
set smtp-auth-user:第三方发邮件的用户名
set smtp-auth-password:邮箱授权码
smtp-auth:SMTP的认证方式,默认是login,也可以改成CRAM-MD5或PLAIN方式
nss-config-dir: SSL验证信息存放位置,
ssl-verify: SSL验证信息忽略

配置SSL验证数字证书

mkdir -p /root/.certs
```bash
>请求163证书
```bash
echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt

证书下载到本地

certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt

certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt

信任证书

cd /root/.certs/
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i 163.crt 

开启邮箱SMTP

Linux实战案列-发送告警邮件_第2张图片

获取授权码

Linux实战案列-发送告警邮件_第3张图片

测试发送邮件到其他邮箱

echo "test" |mail -s "first" [email protected]```

Linux实战案列-发送告警邮件_第4张图片
Linux实战案列-发送告警邮件_第5张图片

你可能感兴趣的:(linux,Docker,linux,运维,docker)