【Logstash】conf文件mysql多数据源导入elasticsearch配置说明

发布时间 2023-07-31 16:26:00作者: 日月星宿
# 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"
        }
    }
}