1、准备配置文件文件夹
2、部署logstash & elasticsearch
docker pull docker.elastic.co/logstash/logstash:7.15.0
## 替换{你的ES地址}为ES地址
docker run -d --name logstash -p 5044:5044 -p 9600:9600 -v D:\logstash\data\:/usr/share/logstash/data -v D:\logstash\path\to\mysql-connector-j-8.0.33.jar:/usr/share/logstash/mysql-connector-j-8.0.33.jar -v D:\logstash\config\:/usr/share/logstash/config -v D:\logstash\pipeline\:/usr/share/logstash/pipeline -e "ELASTICSEARCH_HOSTS={你的ES地址}" docker.elastic.co/logstash/logstash:7.15.0
docker pull docker.elastic.co/elasticsearch/elasticsearch:7.15.0
## 配置文件如果需要修改,修改完后删除重新启动容器
docker run -d --name elasticsearch -v D:\elasticsearch\config\:/usr/share/elasticsearch/config -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" docker.elastic.co/elasticsearch/elasticsearch:7.15.0
页面访问 ip:9200端口,出现下面页面部署成功
3、准备驱动文件
4、编辑配置文件
input {jdbc {jdbc_driver_library => "/usr/share/logstash/mysql-connector-j-8.0.33.jar"jdbc_driver_class => "com.mysql.cj.jdbc.Driver"jdbc_connection_string => "jdbc:mysql://{你的MYSQL地址}/{你的数据库}"jdbc_user => "{数据库账号}"jdbc_password => "{数据库密码}"statement => "SELECT * FROM user"jdbc_paging_enabled => true # 开启分页jdbc_page_size => 2000 # 分页每页条数schedule => "*/5 * * * * * UTC" # 每5s执行一次}
}
output {elasticsearch {hosts => ["{你的ES地址}"] # ElasticSearch 的地址和端口index => "user" # 指定索引名,如果不存在es会自动创建document_id => "%{id}"codec => "json"}
}
5、删除容器、重新启动
docker rm -f logstash
docker run -d --name logstash -p 5044:5044 -p 9600:9600 -v D:\logstash\data\:/usr/share/logstash/data -v D:\logstash\path\to\mysql-connector-j-8.0.33.jar:/usr/share/logstash/mysql-connector-j-8.0.33.jar -v D:\logstash\config\:/usr/share/logstash/config -v D:\logstash\pipeline\:/usr/share/logstash/pipeline -e "ELASTICSEARCH_HOSTS={你的ES地址}" docker.elastic.co/logstash/logstash:7.15.0
6、查看日志
docker logs -f logstash
成功日志