ES7.3.0配置郵件告警


情況說明:
三台es組成集群,一台kibana,版本均為7.3.0
es版本要求是白金版,基礎版的不行,不過可以試用30天的白金版

步驟:先說我自己走通的流程,然后介紹官方說明

1.因為我這邊使用的是三台es,所以我這邊三台都需要配置
原因如下:只配置一台的話,電子郵件選項是灰色的不可用狀態,只有三台都配置了才行

2.修改elasticsearch.yml配置文件
我這邊使用的是阿里雲企業郵箱,開啟的有smtp和pop3服務,走的是常規端口,加密端口還未測試驗證

說明,使用QQ郵箱,163郵箱的話,需要注意,在配置發件箱中使用的密碼不是登陸這個郵箱使用的密碼,而是使用這個郵箱的郵箱授權碼

xpack.notification.email.account:
    aliyun_account:  # 發件箱配置名稱,可以隨意指定,配置多個發件箱地址時會根據這個進行區分
        profile: standard # 采用默認的郵件模板
        email_defaults: # 設置默認發件箱
            from: elk@tongchuangkeji.net  # 發件箱
        smtp:
            auth: true # 開啟賬號驗證
            starttls.enable: false # 關閉ssl
            starttls.required: false # 不要ssl
            host: smtp.qiye.aliyun.com # 阿里雲企業郵箱smtp地址
            port: 25 # 端口
            user: elk@tongchuangkeji.net # 發件箱

附:阿里雲企業郵箱的POP3、SMTP、IMAP地址
新老地址都可以,建議使用新地址

新地址
協議	服務器地址	                服務器端口號(常規)	服務器端口號(加密)
POP3	pop.qiye.aliyun.com	     110	               995
IMAP	imap.qiye.aliyun.com	   143	               993
SMTP	smtp.qiye.aliyun.com	   25	                       465

老地址
協議	   服務器地址	             服務器端口號(常規)	 服務器端口號(加密)
POP3	 pop3.mxhichina.com	  110	                    995
SMTP	 smtp.mxhichina.com	  25	                            465
IMAP	 imap.mxhichina.com	  143	                    993

3.設置發件箱密碼
在es程序根目錄下執行這個命令

# 注意:aliyun_account要跟配置文件中的發件箱配置名稱那個保持一致
bin/elasticsearch-keystore add xpack.notification.email.account.aliyun_account.smtp.secure_password
# 接下來輸入郵箱密碼即可

# 完成的命令步驟,供參考
# 設置郵箱密碼
[root@bogon elasticsearch]# bin/elasticsearch-keystore add xpack.notification.email.account.aliyun_account.smtp.secure_password
# 輸入密碼
Enter value for xpack.notification.email.account.aliyun_account1.smtp.secure_password: 
# 查看
[root@bogon elasticsearch]# bin/elasticsearch-keystore list
keystore.seed # 系統自帶的
xpack.notification.email.account.aliyun_account.smtp.secure_password # 確保有這個

4.重啟es集群

5.在kibana中設置Watcher

郵件發送成功的話界面右下角會有提示。

查看發件箱的發件情況

6.說明
該文檔只是說明配置告警郵件,具體告警參數,郵件內容根據個人具體情況而定

官方關於郵件告警的設置

地址:https://www.elastic.co/guide/en/kibana/7.3/watcher-ui.html#_define_the_watch_input_and_schedule
1.進入Management > Elasticsearch > Watcher
若Elasticsearch security features 開啟的話,需要給使用kibana的用戶設置如下角色,確保該用戶有權限配置這個郵件告警:manage_watcher or monitor_watcher

2.點擊Create,選擇Create threshold alert,輸入告警名稱,選擇索引,選擇日期字段,選擇時間頻率

3.設置告警條件
WHEN條件選擇max(),監控項選擇system.process.cpu.total.norm.pct,監控值選擇 IS ABOVE 填寫0.25

4.添加監控動作
點擊Add action,選擇Email,輸入收件箱地址,郵件主題,郵件內容等,發送測試郵件。
若能收到測試郵件,最后點Create alert。

5.刪除,修改等操作看官網文檔

接下里說官方配置郵件的示例
地址:https://www.elastic.co/guide/en/elasticsearch/reference/7.3/actions-email.html

在es配置文件中進行修改

郵件模板有三個,standard (default), gmail, and outlook 。若發件箱不是gmail和outlook,則選擇standard。后面會有說明

若是有多個發件箱的話,采用如下配置,只有一個的話不用配置

xpack.notification.email:
  default_account: team1
  account:
    team1:
      ...
    team2:
      ...

gmail發件箱設置

xpack.notification.email.account:
    gmail_account: # 注意這個名稱,設置郵箱密碼的時候用得着
        profile: gmail
        smtp:
            auth: true
            starttls.enable: true
            host: smtp.gmail.com
            port: 587
            user: <username> # 發件箱地址

設置發件箱密碼
這個是執行命令,不是在es配置文件中修改

# 注意gmail_account要跟上面的保持一致
bin/elasticsearch-keystore add xpack.notification.email.account.gmail_account.smtp.secure_password

outlook配置

xpack.notification.email.account:
    exchange_account:
        profile: outlook
        email_defaults:
            from: <email address of service account> 
        smtp:
            auth: true
            starttls.enable: true
            host: <your exchange server>
            port: 587
            user: <email address of service account> 

設置發件箱密碼
這個是執行命令,不是在es配置文件中修改

# 注意exchange_account要跟上面的保持一致
bin/elasticsearch-keystore add xpack.notification.email.account.exchange_account.smtp.secure_password

既不是gmail,也不是outlook,采取兩者結合的方式,根據自己實際情況修改

xpack.notification.email.account:
    email_account:
        profile: standard
        email_defaults:
            from: xxxx@xx.com
        smtp:
            auth: true
            starttls.enable: false
            starttls.required: false
            host: smtp.qiye.aliyun.com 
            port: 25
            user: xxxx@xx.com
# 設置密碼
bin/elasticsearch-keystore add xpack.notification.email.account.email_account.smtp.secure_password

關於安全設置的官方地址:https://www.elastic.co/guide/en/elasticsearch/reference/7.3/secure-settings.html#

其他郵箱配置大致一樣,看官方文檔

郵件內容設置相關,是否允許發送html內容的配置等

# 關閉
xpack.notification.email.html.sanitization.enabled: false

# 開啟
xpack.notification.email.html.sanitization.enabled: true

# 進一步限制html頁面內容,哪些能發,哪些不能發
xpack.notification.email.html.sanitization:
    allow: _tables, _blocks
    disallow: h4, h5, h6


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM