首页 文章 精选 留言 我的

精选列表

搜索[Excel导入],共10000篇文章
优秀的个人博客,低调大师

elasticSearch数据导入工具logstash-input-jdbc 同步原理及相关问题解读

前言: 基于logstash-input-jdbc较其他插件的稳定性、易用性、版本和ES同步更新的特点,以下研究主要针对 logstash-input-jdbc 展开。 针对logstash-input-jdbc常见的几个疑难问题,部分问题也在git和stackoverflow进行了激烈讨论,以下统一给出验证和解答。 1、logstash-input-jdbc 的同步原理是什么? (1)、对于全量同步依据 配置文件jdbc.sql的sql语句的进行同步。 (2)、对于增量实时同步依据 1)设定的定时策略。 如最小更新间隔每分钟更新一次设定:schedule => “* * * * *”,目前最小更新间隔为1分钟,验证发现,不支持60s以内的秒级更新。 2)设定的sql语句。 如jdbc.sql, 决定同步哪些内容及同步更新的条件。 {"id":10,"name":"10test","@version":"1","@timestamp":"2016-06-29T03:18:00.177Z","type":"132c_type"} 1 2:logstash-input-jdbc 只支持基于时间同步吗? 验证表名:同步更新除了支持根据时间同步外,还支持根据某自增列(如:自增ID)字段的变化进行同步。 上次举例只是举了同步时间变化的例子,设定条件: [root@5b9dbaaa148a logstash_jdbc_test]# cat jdbc.sql_bak select * from cc where cc.modified_at > :sql_last_value 1 2 3 4 5 6 7 实际进一步研究发现,在配置文件中有use_column_value字段决定,是否需要记录某个column 的值,如果 record_last_run 为真,可以自定义我们需要 track 的 column 名称,此时该参数就要为 true. 否则默认 track 的是 timestamp 的值. 举例:以下即是设定以id的变化作为同步条件的。 [root@5b9dbaaa148a logstash_jdbc_test]# cat jdbc_xm.sql select * from cc where cc.id >= :sql_last_value 1 2 3 4 5 6 我们可以指定文件,来记录上次执行到的 tracking_column 字段的值 比如上次数据库有 12 条记录,查询完后该文件中就会有数字 12 这样的记录,下次执行 SQL 查询可以从 13 条处开始. 我们只需要在 SQL 语句中 WHERE MY_ID > :last_sql_value 即可. 其中 :last_sql_value 取得就是该文件中的值(12). last_run_metadata_path => “/etc/logstash/run_metadata.d/my_info” 如: [root@5b9 run_metadata.d]# cat /etc/logstash/run_metadata.d/my_info --- 12 1 2 3 已全局代码搜索,没有触发器trigger相关处理操作。 3:mysql和ES分别存储在两台服务器,且时间不一致,能否实现同步? (1). 设定对于以时间作为判定条件的增量同步,可以以设定的时间为基准点进行同步。 验证发现: 显示的时间戳timestamp为ES上的UTC时间值(不论ES机器是什么时区,都会修改为UTC时间存入ES),显示的modified_at时间值为同步过来的mysql时间值转化为UTC的结果值。 更新的前提是必须满足: cc.modified_at >= :sql_last_value。即如果mysql的时间修改为小于sql_last_value的时刻值,是无法进行同步的。 如: 1 2 [elasticsearch@5b9dbaaa148a run_metadata.d]$ cat my_info --- 2016-06-29 02:19:00.182000000 Z 1 2 3 (2). 对于选定某列作为判定条件(如自增ID),两者(mysql和ES)时间不一致,实际是也可以同步更新的。 验证发现: 测试设定的时间是mysql比ES早一天或者晚一天的时刻值,都可以实现同步更新操作。 4:如何支持实时同步mysql的delete操作到ES中? logstash-input-jdbc插件不支持物理删除的同步更新。详见: http://stackoverflow.com/questions/35813923/sync-postgresql-data-with-elasticsearch/35823497#35823497 https://github.com/logstash-plugins/logstash-input-jdbc/issues/145 解决方案: 同步删除操作改为同步update更新操作实现。 第一步:进行软件删除,而不是物理删除操作。 先不物理删除记录,而是软件删除,即新增一个 flag 列,标识记录是否已经被删除(默认为false,设置为true或者deleted代表已经被删除,业界通用方法),这样,通过已有的同步机制,相同的标记记录该行数据会同步更新到Elasticsearch。 第二步:ES中检索flag标记为true或者deleted的字段信息。 在ES可以执行简单的term查询操作,检索出已经删除的数据信息。 第三步:定时物理删除。 设置定时事件,间隔一段时间物理删除掉mysql和ES中的flag字段标记为true或deleted的记录,即完成物理删除操。 原文网址:http://blog.csdn.net/laoyang360/article/details/51793301

优秀的个人博客,低调大师

Azure 云平台用 SQOOP 将 SQL server 2012 数据表导入 HIVE / HBASE

My name is Farooq and I am with HDinsight support team here at Microsoft. In this blog I will try to give some brief overview of Sqoop in HDinsight and then use an example of importing data from a Windows Azure SQL Database table to HDInsight cluster to demonstrate how you can get stated with Sqoop in HDInsight. What is Sqoop? Sqoop is an Apache project and part of Hadoop ecosystem. It allows data transfer between Hadoop\HDInsight cluster and relational databases such as SQL, Oracle, MySQL etc. Sqoop is a collection of related tools, for example import, export, list-all-tables, list-databases etc. To use Sqoop, you specify the tool you want to use and the arguments that control the tool. For more information on Sqoop please check Sqoop User Guide. When do you need to use Sqoop? You need to use Sqoop only when you are trying to import/export data between Hadoop and a relational Database. HDInsight provides a full-featured Hadoop Distributed File System (HDFS) over Windows Azure Blob storage (WABS) and if you want to upload data to HDInsight or WASB from any other source, for example from your local computer's file system then you should use any of the tools discussed in this article. The same article also discusses how to import data to HDFS from SQL Database/SQL Server using Sqoop. In this blog I will elaborate on the same with an example and try to provide more details information along the way. What do I need to do for Sqoop to work in my HDInsight cluster? HDInsight 2.1 includes Sqoop 1.4.3. The Microsoft SQL Server SQOOP Connector for Hadoop is now part of Apache SQOOP 1.4. So you do not need to install the connector separately. All HDInsight clusters also have Microsoft SQL Server JDBC driver installed; so all components that are needed to transfer data between HDInsight cluster and SQL server are already installed in a HDI cluster and you do not have to install anything. How can I run a Sqoop job? With HDInsight preview version we could only run the Sqoop commands from Hadoop command line after doing a remote desktop session (RDP) on the HDInsight cluster head node. However the release version of HDInsight SDK includes the PowerShell cmdlet to run Sqoop job remotely. So we can Run Sqoop jobs locally from HDInsight head node using Hadoop Command Line Run Sqoop job remotely using HDInsight SDK PowerShell cmlets We recommend that you run your Sqoop commands remotely using HDInsight SDK cmdlets . We will discuss both the options in detail. First let's see how we can run Sqoop jobs locally from HDInsight head node using Hadoop Command Line. Run Sqoop jobs locally from HDInsight head node using Hadoop Command Line I am assuming you already have a Windows Azure SQL Database. If you don't and you want to get one please follow the steps in this article. Let's follow the steps below to create a test table and populate with some sample data in your Windows Azure SQL Database which we will import in our HDInsight cluster shortly. I will show how to do this from Windows Azure portal but you can also connect to the Windows Azure SQL Database from SSMS and do the same. Note: if you want to transfer data from a SQL server on your environment instead then you need to change the Sqoop command with appropriate connection information and it should be very similar to the connection string I have provided later in this blog under 'More sample Sqoop commands' section for SQL server on Window Azure VM. Login to your Windows Azure Portal and select 'SQL Databases' from the Left and click 'Manage' at the bottom. Provider your Windows Azure SQL Database user ID and password to login and then click 'New Query' to open a new query window to run T-SQL queries. Copy paste the following T-SQL query and execute to create a test table Table1. CREATE TABLE [dbo].[Table1]( [ID] [int] NOT NULL, [FName] [nvarchar](50) NOT NULL, [LName] [nvarchar](50) NOT NULL, CONSTRAINT [PK_Table_4] PRIMARY KEY CLUSTERED ( [ID] ASC ) ) ON [PRIMARY] GO Run the Following to Populate Table1 with 4 rows. INSERT INTO [dbo].[Table1] VALUES (1,'Jhon','Doe'), (2,'Harry','Hoe'), (3, 'Carla','Coe'), (4,'Jackie','Joe'); GO Now finally run the following T-SQL to make sure that is table is populated with the sample data. You should see the output as below. SELECT * from [dbo].[Table1] Now let's follow the steps below to Import the rows in Table1 to the HDInsight Cluster. Login to your HDInsight cluster head node via Remote Desktop (RDP) and double click the 'Hadoop Command Line' icon in the desktop to open Hadoop Command Line. RDP access is turned off by default but you can follow the steps inthis blog to enable RDP and then RDP to the head node of your HDInsight cluster. In Hadoop Command Line please navigate tothe "C:\apps\dist\sqoop-1.4.3.1.3.1.0-06\bin" folder. Note: Please verify the path for the Sqoop bin folder in your environment. It may slightly vary from version to version. Run the following Sqoop command to importall the rows of table "Table1" from Windows Azure SQL Database "mfarooqSQLDB" to HDInsight Cluster. sqoop.cmd import –-connect "jdbc:sqlserver://<SQLDatabaseServerName>.database.windows.net:1433;username=<SQLDatabasUsername>@<SQLDatabaseServerName>;password=<SQLDatabasePassword>;database=<SQLDatabaseDatabaseName>" --table Table1 --target-dir /user/hdp/SqoopImportTable1 Once the command is executed successfully you should see something similar as below in Hadoop Command Line window. There are quite a number of tools available to upload/download and view data in WASB. Let's use Azure Storage Explorer tool. You need to install the tool in your work station and configure for your cluster. Once all is done open the tool and find out /user/hdp/SqoopImportTable1 folder. You should see something similar as below. It shows 4 files indicating 4 map jobs were used. You can select a file and click the 'View' button to see the actual text data. Now let's export the same rows back to the SQL server from HDInsight cluster. Please use a different table with the same schema as 'Table1'. Otherwise you would get a Primary Key violation error since the rows already exist in 'Table1'. Create an empty table 'Table2' with the same schema as 'Table1'. CREATE TABLE [dbo].[Table2]( [ID] [int] NOT NULL, [FName] [nvarchar](50) NOT NULL, [LName] [nvarchar](50) NOT NULL, CONSTRAINT [PK_Table_2] PRIMARY KEY CLUSTERED ( [ID] ASC ) ) ON [PRIMARY] GO Run the following Sqoop command from Hadoop Command Line. sqoop.cmd export --connect "jdbc:sqlserver://<SQLDatabaseServerName>.database.windows.net:1433;username=<SQLDatabasUsername>@<SQLDatabaseServerName>;password=<SQLDatabasePassword>;database=<SQLDatabaseDatabaseName>" --table Table2 --export-dir /user/hdp/SqoopImportTable1 --input-fields-terminated-by "," More sample Sqoop commands: Import from a SQL server on Window Azure VM: sqoop.cmd import --connect "jdbc:sqlserver:// <WindowsAzureVMServerName>.cloudapp.net:1433; username=<SQLServerUserName>; password=<SQLServerPassword>; database=<SQLServerDatabaseName>" --table Table_1 --target-dir /user/hdp/SqoopImportTable Export to a SQL server on Window Azure VM: sqoop.cmd export --connect "jdbc:sqlserver://<WindowsAzureVMServerName>.cloudapp.net:1433; username=<SQLServerUserName>; password=<SQLServerPassword>; database=<SQLServerDatabaseName>" --table Table_2 --export-dir /user/hdp/SqoopImportTable2 --input-fields-terminated-by "," Importing to HIVE from Windows Azure SQL Database: C:\apps\dist\sqoop-1.4.2\bin>sqoop.cmd import –connect "jdbc:sqlserver://<WindowsAzureVMServerName>.cloudapp.net:1433; username=<SQLServerUserName>; password=<SQLServerPassword>; database=<SQLServerDatabaseName>" --table Table1 --hive-import Note: This will store the files under hive/warehouse/TableName folder in HDFS (For example hive/warehouse/table1/part-m-00000 ) Run Sqoop job remotely using HDInsight SDK PowerShell cmlets To use HDInsight PowerShell tools you need to install Windows Azure PowerShell tools first and then install HDInsight PowerShell tools. Then you need to prepare your workstation to use the HDInsight SDK. Please follow the detail steps in this earlier blog post to install the tools and prepare your work station to use the HDInsight SDK. Once you have installed and configured Windows Azure PowerShell tools and HDInsight SDK running a Sqoop job is very easy. Please follow the steps below to import all the rows of table "Table2" fromWindows Azure SQL Database "mfarooqSQLDB" to HDInsight Cluster. Open the Windows azure PowerShell console on the workstation and run the following cmdlets one at a time. Note: You can also use Windows Powershell ISE to type the code and run all at once. Powershell ISE makes edits easy and you can open the tool from "C:\Windows\System32\WindowsPowerShell\v1.0\powershell_ise.exe". Set the variables for your Windows Azure Subscription name and the HDInsight cluster name. $subscriptionName = "<WindowsAzureSubscriptionName>" $clusterName = "<HDInsightClusterName>" Select-AzureSubscription $subscriptionName Use-AzureHDInsightCluster $clusterName -Subscription $subscriptionName Define the Sqoop job that we want to run. In this exercise we will importall the rows of table "Table2" that we created earlier in Windows Azure SQL Database. $sqoop = New-AzureHDInsightSqoopJobDefinition -Command "import --connect jdbc:sqlserver://<SQLDatabaseServerName>.database.windows.net:1433;username=<SQLDatabasUsername>@<SQLDatabaseServerName>; password=<SQLDatabasePassword>; database=<SQLDatabaseDatabaseName> --table Table2 --target-dir /user/hdp/SqoopImportTable8" Run the Sqoop job that we just defined. $sqoopJob = Start-AzureHDInsightJob -Subscription $subscriptionName -Cluster $clusterName -JobDefinition $sqoop Run the following to wait for the completion or failure of the HDInsight job and show its progress. Wait-AzureHDInsightJob -Subscription $subscriptionName -WaitTimeoutInSeconds 3600 -Job $sqoopJob Run the following to retrieve the log output for a job from the storage account associated with a specified cluster. Get-AzureHDInsightJobOutput -Cluster $clusterName -Subscription $subscriptionName -StandardError -JobId $sqoopJob.JobId If the Sqoop job completes successfully you should see something similar as below in your Windows Azure PowerShell command line window. Troubleshooting tips When you run a Sqoop job command it runs MapReduce job in Hadoop Cluster (map only and no reduce task). You can specify the number of map tasks but by default four tasks are used. There is no separate log file specific to Sqoop. So we need to troubleshoot Sqoop job failure or performance issues as any other MapReduce job failure or performance issues and start by checking the task logs. I plan to write more on how to troubleshot Sqoop issues by focusing on some specific scenarios in the near future. That's all for today and I hope you found this blog useful. I look forward to your comments and suggestions J.

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册