1、安装elasticSearch 版本6.2.4
1)wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.tar.gz
2)wget https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-6.2.4.tar.gz.sha512
3)shasum -a 512 -c elasticsearch-6.2.4.tar.gz.sha512 (这里报错:-bash: shasum: command not found 解决:sudo yum install perl-Digest-SHA)输出 elasticsearch-6.2.4.tar.gz: OK
4)cd elasticsearch-6.2.4
5)更改配置 将elasticsearch.yaml中的 network.host 改为自己的ip地址(可能会遇到错误,参考https://www.cnblogs.com/zhi-leaf/p/8484337.html)
5)启动 ./bin/elasticsearch(需要java环境)
2、安装kibana 版本6.2.4
1) wget https://artifacts.elastic.co/downloads/kibana/kibana-6.2.4-linux-x86_64.tar.gz
2)shasum -a 512 kibana-6.2.4-linux-x86_64.tar.gz
3)tar -xzf kibana-6.2.4-linux-x86_64.tar.gz
4)cd kibana-6.2.4-linux-x86_64
5)vi config/kibana.yaml
6)更改 server.host: "localhost" 为对应的主机IP地址
7)将 kibana.yaml中的elasticsearch.url 改为自己的ip地址
8)启动 ./bin/kibana
3、kibana中添加plugin(注意安装plugin)
./bin/kibana-plugin install 'https://git.bitsensor.io/front-end/elastalert-kibana-plugin/builds/artifacts/6.2.4/raw/artifact/elastalert-kibana-plugin-latest.zip?job=build'
4、安装docker
1) sudo yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
2)sudo yum install http://vault.centos.org/centos/7.3.1611/extras/x86_64/Packages/container-selinux-2.9-4.el7.noarch.rpm
3)sudo yum -y install docker-ce
4)启动 docker sudo systemctl start docker
5、下载安装elastAlert
1)git clone https://github.com/bitsensor/elastalert.git
2)cd elastalert
3)更改配置文件:elastalert.yaml、elastalert-test.yaml、config.json
将es_host 改为自己主机的ip
4)sudo make build
5)
sudo docker run -d -p 3030:3030 \
-v `pwd`/config/elastalert.yaml:/opt/elastalert/config.yaml \
-v `pwd`/config/elastalert-test.yaml:/opt/elastalert/config-test.yaml \
-v `pwd`/config/config.json:/opt/elastalert-server/config/config.json \
-v `pwd`/rules:/opt/elastalert/rules \
-v `pwd`/rule_templates:/opt/elastalert/rule_templates \
--net="host" \
--name elastalert bitsensor/elastalert:latest
6、在浏览器中访问
1)
2)测试rule 根据自己的情况配置以下基本内容
es_host: elasticsearch.example.com
es_port: 14900
name: Example rule
type: frequency
index: logstash-*
num_events: 50
timeframe:
hours: 4
filter:
- term:
some_field: "some_value"
alert:
- "email"
email:
- "[email protected]"
如果报错如下 很可能是前面的配置没配好 elasticsearch连接有问题,还有注意检查对应的版本,重新配置后需要重启docker 才能生效
如果配置好的话,会输出类似结果
到这里基本完成,但是有可能会发不出邮件,这时,进入docker 容器内部
sudo docker exec -it elastalert sh
运行elastalert命令创建默认索引
elastalert-create-rule
然后测试配置的rule
elastalert-test-rule example_frequency.yaml
如果没问题,就运行rule
python -m elastalert.elastalert --verbose --rule example_frequency.yaml
如果在运行过程中,有匹配到rule就会发出邮件