【ElasticSearch】logstash-conf文件mysql多数据源配置

logstash-conf文件mysql多数据源导入es配置说明

复制代码
# input plugin 输入插件,接收事件源
input {
    jdbc {
        # 定义类型_1 
        type => "type_1"
        
        # mysql的ip、端口以及用到的数据库名
        jdbc_connection_string => "jdbc:mysql://localhost:3306/数据库名"
        # mysql用户名
        jdbc_user => ""
        # mysql密码
        jdbc_password => ""
        # mysql驱动(根据mysql版本进行配置,8.0.12及以上版本驱动为com.mysql.cj.jdbc.Driver)
        jdbc_driver_class => "com.mysql.jdbc.Driver"
        # 进行连接校验
        jdbc_validate_connection => true
        # 设置时区
        jdbc_default_timezone => "Asia/Shanghai"
        # 设置分页
        jdbc_paging_enabled => "true"
        # 设置分页模式
        jdbc_paging_mode => "explicit"
        # 设置分页大小
        jdbc_page_size => "1000"
        # mysql-connector-java-5.1.47.jar包绝对路径
        jdbc_driver_library => "/xxx/xxx/mysql-connector-java-5.1.47.jar"
        # 可直接写sql或调用存储过程
        statement => ""
        # 同步频率(分 时 天 月 年)。
        #(* * * * *)或(1 * * * *)每分钟执行一次
        #(* 2 * * *)每天2点执行
        #(10 8 * * *)每天8点10分执行
        schedule => "* 3 * * *"
    }  
}
input {
    jdbc {
        # 定义类型_2 
        type => "type_2"
        
        # mysql的ip、端口以及用到的数据库名
        jdbc_connection_string => "jdbc:mysql://localhost:3306/数据库名"
        # mysql用户名
        jdbc_user => ""
        # mysql密码
        jdbc_password => ""
        # mysql驱动(根据mysql版本进行配置,8.0.12及以上版本驱动为com.mysql.cj.jdbc.Driver)
        jdbc_driver_class => "com.mysql.jdbc.Driver"
        # 进行连接校验
        jdbc_validate_connection => true
        # 设置时区
        jdbc_default_timezone => "Asia/Shanghai"
        # 设置分页
        jdbc_paging_enabled => "true"
        # 设置分页模式
        jdbc_paging_mode => "explicit"
        # 设置分页大小
        jdbc_page_size => "1000"
        # mysql-connector-java-5.1.47.jar包绝对路径
        jdbc_driver_library => "/xxx/xxx/mysql-connector-java-5.1.47.jar"
        # 可直接写sql或调用存储过程
        statement => ""
        # 同步频率(分 时 天 月 年)。
        #(* * * * *)或(1 * * * *)每分钟执行一次
        #(* 2 * * *)每天2点执行
        #(10 8 * * *)每天8点10分执行
        schedule => "* 3 * * *"
    }  
}
input {
    jdbc {
          # 定义类型_3 
        type => "type_3"
        
        # mysql的ip、端口以及用到的数据库名
        jdbc_connection_string => "jdbc:mysql://localhost:3306/数据库名"
        # mysql用户名
        jdbc_user => ""
        # mysql密码
        jdbc_password => ""
        # mysql驱动(根据mysql版本进行配置,8.0.12及以上版本驱动为com.mysql.cj.jdbc.Driver)
        jdbc_driver_class => "com.mysql.jdbc.Driver"
        # 进行连接校验
        jdbc_validate_connection => true
        # 设置时区
        jdbc_default_timezone => "Asia/Shanghai"
        # 设置分页
        jdbc_paging_enabled => "true"
        # 设置分页模式
        jdbc_paging_mode => "explicit"
        # 设置分页大小
        jdbc_page_size => "1000"
        # mysql-connector-java-5.1.47.jar包绝对路径
        jdbc_driver_library => "/xxx/xxx/mysql-connector-java-5.1.47.jar"
        # 可直接写sql或调用存储过程
        statement => ""
        # 同步频率(分 时 天 月 年)。
        #(* * * * *)或(1 * * * *)每分钟执行一次
        #(* 2 * * *)每天2点执行
        #(10 8 * * *)每天8点10分执行
        schedule => "* 3 * * *"
    }  
}
 
 
#output plugin  输出插件,将事件发送到特定目标。
output {
    if [type] == "type_1" {
        elasticsearch {
            # es地址,多个逗号隔开
            hosts => ["localhost:9200"]
            # es索引
            index => "xxx"
            # es账号
            user => "elastic"
            # es密码
            password => "123456"
            
            # 创建索引的时候若是需要指定mapping结构,则需使用以下配置
            # xdr_cent_busi_index_p_mapping.txt文件的绝对路径
            #template => "/home/lvlh/soft/logstash-8.4.1/config/"
            #template_name => "xdr_cent_busi_index_p_mapping.txt"
            #template_overwrite => true
        }
    }
    if [type] == "type_2" {
        elasticsearch {
            # es地址,多个逗号隔开
            hosts => ["localhost:9200"]
            # es索引
            index => "xxx"
            # es账号
            user => "elastic"
            # es密码
            password => "123456"
            
            # 创建索引的时候若是需要指定mapping结构,则需使用以下配置
            # xdr_cent_busi_index_p_mapping.txt文件的绝对路径
            #template => "/home/lvlh/soft/logstash-8.4.1/config/"
            #template_name => "xdr_cent_busi_index_p_mapping.txt"
            #template_overwrite => true
        }
    }
    else{
        elasticsearch {
            # es地址,多个逗号隔开
            hosts => ["localhost:9200"]
            # 索引(每天生成一个索引)
            index => "xxx_%{+YYYYMMdd}"
            # es账号
            user => "elastic"
            # es密码
            password => "123456"
        }
    }
}
相关推荐
周杰伦_Jay25 分钟前
【Elasticsearch】核心概念,倒排索引,数据操纵
大数据·elasticsearch·搜索引擎
cai_cai031 分钟前
springAlibaba + ollama + es 完成RAG知识库功能
大数据·elasticsearch·搜索引擎
库库茯苓34 分钟前
Kibana报错:Unable to retrieve version information from Elasticsearch nodes (解决方法)Window11环境
elasticsearch·kibana
nhdh37 分钟前
ELK(elasticsearch-7.6.2,kibana-7-6-2,Logstash-7.6.2)单节点部署
大数据·elk·elasticsearch
新元代码1 小时前
Git在Windows环境下的安装与使用教程
大数据·elasticsearch·搜索引擎
小园子的小菜1 小时前
深入理解Elasticsearch内部线程池:类型与核心作用解析
大数据·elasticsearch·搜索引擎
ZePingPingZe5 小时前
SpringBoot整合Sharding-jdbc分库分表及ES搜索引擎解决无分片键查询
spring boot·elasticsearch·搜索引擎
Mr.wangh6 小时前
SpringCloudConfig(配置中心)
大数据·elasticsearch·搜索引擎·springcloud·config
小园子的小菜6 小时前
深度解析Elasticsearch网络通信原理:节点协同与链接机制
大数据·elasticsearch·搜索引擎
Tipriest_6 小时前
详细解释pip及其使用方法(对比apt)
大数据·elasticsearch·apt·pip