Logstash
Logstash est une infrastructure de collecte et de traitement de journaux légère qui peut facilement collecter des journaux dispersés et diversifiés, effectuer un traitement personnalisé, puis les transférer vers un emplacement spécifié, tel qu'un serveur ou un fichier.
Docker installe Logstash.
1: Trouvez le miroir: recherche de docker Logstash.
docker search Logstash
![](https://img-blog.csdnimg.cn/20210330115616815.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzIyNTk2OTMx,size_16,color_FFFFFF,t_70)
2: Téléchargez le miroir:
docker pull logstash:5.6
Remarque: Pour afficher la version du miroir et du TAG, vous devez afficher l'adresse sur le hub docker comme suit: https://hub.docker.com Après avoir entré, recherchez dans la zone de recherche dans le coin supérieur gauche du page
![](https://img-blog.csdnimg.cn/202103301156478.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzIyNTk2OTMx,size_16,color_FFFFFF,t_70)
3: Vérifiez l'image que nous avons téléchargée: images du docker
![](https://img-blog.csdnimg.cn/20210330115709713.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzIyNTk2OTMx,size_16,color_FFFFFF,t_70)
4: Courir
Référence: https://blog.csdn.net/qq_33547169/article/details/86629261
Créer un dossier (pour monter des fichiers de conteneur)
mkdir /usr/local/logstash/config
Créer des fichiers de configuration associés
logstash.yml (un fichier vide fera l'affaire)
log4j2.properties
logger.elasticsearchoutput.name = logstash.outputs.elasticsearch
logger.elasticsearchoutput.level = debug
pipelines.yml (la petite barre est très importante)
- pipeline.id: my-logstash
path.config: "/usr/share/logstash/config/*.conf"
pipeline.workers: 3
* fichier .conf
input {
jdbc {
# mysql jdbc connection string to our backup databse 后面的test 对应mysql中的test数据库
jdbc_connection_string => "jdbc:mysql://127.0.0.1:3306/tensquare_article?characterEncoding=UTF8"
# the user we wish to excute our statement as
jdbc_user => "root"
jdbc_password => "123456"
# the path to our downloaded jdbc driver
jdbc_driver_library => "D:/logstash‐5.6.8/mysqletc/mysqlconnector‐java‐5.1.46.jar"
# the name of the driver class for mysql
jdbc_driver_class => "com.mysql.jdbc.Driver"
jdbc_paging_enabled => "true"
jdbc_page_size => "50000"
#以下对应着要执行的sql的绝对路径。
statement => "select id,title,content from tb_article"
#定时字段 各字段含义(由左至右)分、时、天、月、年,全部为*默认含义为 每分钟都更新
schedule => "* * * * *"
}
}
output {
elasticsearch {
#ESIP地址与端口
hosts => "localhost:9200"
#ES索引名称(自己定义的)
index => "tensquare"
#自增ID编号
document_id => "%{id}"
document_type => "article"
}
stdout {
#以JSON格式输出
codec => json_lines
}
}
Démarrez et exécutez:
docker run -d -p 5044:5044 -p 9600:9600 -it -v /usr/local/logstash/config/:/usr/share/logstash/config/ logstash:5.6