首页 > 数据库 >Postgresql同步数据到Elasticsearch

Postgresql同步数据到Elasticsearch

时间:2024-03-30 21:56:34浏览次数:28  
标签:... 同步 Postgresql Waiting Kibana running Elasticsearch connectors

Postgresql同步数据到es需要借助中间工具连接器,连接器部署主要有两种方式,一种是基于Elastic云托管的连接器(Native connectors), 另外一种自己安装管理的连接器(self-managed connector). 

托管方式连接器的使用方法文档:https://www.elastic.co/guide/en/enterprise-search/8.13/native-connectors.html

本文主要介绍如何自己安装配置连接器:

前提条件:

  • Linux 或者 macOS系统
  • Python 3.10或者更高版本
  • 系统安装了Docker与Docker compose

我们在启动连接器的时候,要根据提示来设置连接器配置,所以必做还要安装 `build-essential` , 否则会报错

sudo apt install build-essential

 

 


 

 

 

下载连接器仓库源码:

git clone https://github.com/elastic/connectors.git && cd connectors 
cp config.yml.example config.yml  # 要先手动复制一份配置文件并命名为config.yml,否则后面运行脚本会报找不到这个文件  
 

执行安装脚本

k3s@k3s-test-master:~/connectors$ ELASTIC_PASSWORD="my_new_password" CONNECTORS_VERSION=8.11.2.0 ./scripts/stack/run-stack.sh --no-snapshot
~/connectors/scripts/stack ~/connectors
Using compose file at: /home/k3s/connectors/scripts/stack/docker/docker-compose.yml
set PROJECT_ROOT to /home/k3s/connectors
ELASTICSEARCH_VERSION=8.11.2
KIBANA_VERSION=8.11.2
CONNECTORS_VERSION=8.11.2.0
Starting Elasticsearch...
Creating network "docker_connectors_stack_net" with the default driver
Creating docker_elasticsearch_1 ... done
Connecting to Elasticsearch on http://localhost:9200
Waiting for Elasticsearch to be running...
Waiting for Elasticsearch to be running...
Waiting for Elasticsearch to be running...
Waiting for Elasticsearch to be running...
Waiting for Elasticsearch to be running...
Waiting for Elasticsearch to be running...
Waiting for Elasticsearch to be running...
Waiting for Elasticsearch to be running...
Waiting for Elasticsearch to be running...
Waiting for Elasticsearch to be running...
Waiting for Elasticsearch to be running...
Waiting for Elasticsearch to be running...
Waiting for Elasticsearch to be running...
Waiting for Elasticsearch to be running...
Waiting for Elasticsearch to be running...
Starting Kibana...
docker_elasticsearch_1 is up-to-date
Creating docker_kibana_1 ... done
Connecting to Kibana on http://localhost:5601
Waiting for Kibana to be running...
Waiting for Kibana to be running...
Waiting for Kibana to be running...
Waiting for Kibana to be running...
Waiting for Kibana to be running...
Waiting for Kibana to be running...
Waiting for Kibana to be running...
Waiting for Kibana to be running...
Waiting for Kibana to be running...
Waiting for Kibana to be running...
Waiting for Kibana to be running...
Waiting for Kibana to be running...
Waiting for Kibana to be running...
Waiting for Kibana to be running...
Updating Kibana password in Elasticsearch running on http://localhost:9200
{ }
Do you want to run the configurator? (y/n) y
ELASTICSEARCH_VERSION=8.11.2
KIBANA_VERSION=8.11.2
CONNECTORS_VERSION=8.11.2.0
config.yml already exists in /home/k3s/connectors/scripts/stack/connectors-config. Not overwriting.
ELASTICSEARCH_VERSION=8.11.2
KIBANA_VERSION=8.11.2
CONNECTORS_VERSION=8.11.2.0

                                                                   
脚本会调用 docker-compose安装 连接器、kibana和es,变量ELASTIC_PASSWORD指定kibana登陆密码,CONNECTORS_VERSION 指定这三个服务使用的版本(如果不使用脚本安装的话最好也要保持它们的版本一致).   Kibana和ES容器启动后,会提示选择一个连接器类型,我这里使用的数据源是postgres, 使用鼠标上下键选择,enter确定

 

 创建完成,验证:

k3s@k3s-test-master:~/connectors$ docker ps
CONTAINER ID   IMAGE                                                             COMMAND                  CREATED          STATUS          PORTS                                                 NAMES
4afc1d4bb5fd   docker.elastic.co/enterprise-search/elastic-connectors:8.11.2.0   "/app/bin/elastic-in…"   7 minutes ago    Up 7 minutes                                                          docker_elastic-connectors_1
a0779b7bf5a6   docker.elastic.co/kibana/kibana:8.11.2                            "/bin/tini -- /usr/l…"   19 minutes ago   Up 19 minutes   0.0.0.0:5601->5601/tcp, :::5601->5601/tcp             docker_kibana_1
f21bf94c223b   docker.elastic.co/elasticsearch/elasticsearch:8.11.2              "/bin/tini -- /usr/l…"   20 minutes ago   Up 20 minutes   0.0.0.0:9200->9200/tcp, :::9200->9200/tcp, 9300/tcp   docker_elasticsearch_1

 

 

浏览器输入kibana地址:http://[服务器IP]:5601 帐号是 elastic, 密码是刚才设置的环境变量ELASTIC_PASSWORD的值。 进入后,点击左上角三条横线图标,然后Search栏Content,在右边Available indices栏就可以看到我们刚才创建的索引了

 

点击进入创建的索引,在Configuration配置中选择右边Sync菜单中Full Content,就开始把Postgresql数据库的相关库和表导入到es了

 

同步完成后页面会有提示,或者从连接器的日志也可以看出来

k3s@k3s-test-master:~/connectors$ docker logs 4afc 
[FMWK][14:40:33][INFO] Running connector service version 8.11.2.0
[FMWK][14:40:33][INFO] Loading config from /config/config.yml
[FMWK][14:40:33][INFO] Running preflight checks
[FMWK][14:40:33][INFO] Waiting for NodeConfig(scheme='http', host='localhost', port=9200, path_prefix='', headers={}, connections_per_node=10, request_timeout=10.0, http_compress=False, verify_certs=True, ca_certs=None, client_cert=None, client_key=None, ssl_assert_hostname=None, ssl_assert_fingerprint=None, ssl_version=None, ssl_context=None, ssl_show_warn=True, _extras={}) (so far: 0 secs)
[FMWK][14:40:33][INFO] Extraction service is not configured, skipping its preflight check.
[FMWK][14:40:33][INFO] Job Scheduling Service started, listening to events from http://localhost:9200
[FMWK][14:40:33][INFO] Job Execution Service started, listening to events from http://localhost:9200

[FMWK][13:19:08][INFO] [Connector id: z0F3jY4BelYPyai-qYpX, index name: search-bc0, Sync job id: 40GDj44BelYPyai-MYrM] Executing full sync
[FMWK][13:19:08][INFO] [Connector id: z0F3jY4BelYPyai-qYpX, index name: search-bc0, Sync job id: 40GDj44BelYPyai-MYrM] Filtering validation started
[FMWK][13:19:08][INFO] [Connector id: z0F3jY4BelYPyai-qYpX, index name: search-bc0, Sync job id: 40GDj44BelYPyai-MYrM] Collecting local document ids
[FMWK][13:19:08][INFO] [Connector id: z0F3jY4BelYPyai-qYpX, index name: search-bc0, Sync job id: 40GDj44BelYPyai-MYrM] Iterating on remote documents
[FMWK][13:19:08][INFO] [Connector id: z0F3jY4BelYPyai-qYpX, index name: search-bc0, Sync job id: 40GDj44BelYPyai-MYrM] Sync progress -- created: 0 | updated: 0 | deleted: 0
[FMWK][13:19:08][INFO] [Connector id: z0F3jY4BelYPyai-qYpX, index name: search-bc0, Sync job id: 40GDj44BelYPyai-MYrM] Sync progress -- created: 0 | updated: 100 | deleted: 0
[FMWK][13:19:09][INFO] [Connector id: z0F3jY4BelYPyai-qYpX, index name: search-bc0, Sync job id: 40GDj44BelYPyai-MYrM] Sync ended with status completed -- created: 0 | updated: 131 | deleted: 0 (took 1 seconds)

 

        如果要添加索引的话,可以在 Content页面右上角"Create a new index"

 

  选择"Use a connector"

 Select a connector 页面选择你的数据源类型,点击 "Continue"

输入索引名字,然后“Continue"

 点击”Generate API key" 创建一个api

 

 

 

 把生成的新的连接配置填入连接器配置文件:

k3s@k3s-test-master:~/connectors$ cat scripts/stack/connectors-config/config.yml
connectors:
- api_key: eUVHa2lvNEJlbFlQeWFpLXhJcmY6S1BDTHBHZElTQkNzMVpoUzFveFJjUQ==
  connector_id: ykGkio4BelYPyai-xYrG
  service_type: postgresql
- connector_id: "5EGLj44BelYPyai-lIpr"
  service_type: "postgresql"
  api_key: "NVVHTGo0NEJlbFlQeWFpLTdZclM6VEpOZEwwTWhSTm1pUDJLdGExXzdvdw=="
elasticsearch.host: http://localhost:9200
elasticsearch.password: my_new_password
elasticsearch.username: elastic

 

      重启连接器容器:
k3s@k3s-test-master:~/connectors$ docker restart docker_elastic-connectors_1
docker_elastic-connectors_1

 

重启完成后就可以回到刚才新建的索引的 “Configuration"第4步,填入你需要连接的数据库相关信息,保存即可

 

我们也可以在”Scheduling"选项卡中打开自动同步,并设置同步频率.

 

 

 

 

标签:...,同步,Postgresql,Waiting,Kibana,running,Elasticsearch,connectors
From: https://www.cnblogs.com/rick-zhang/p/18106088

相关文章

  • 中间件 ZK分布式专题与Dubbo微服务入门 6-3 同步异步创建zk节点
    0课程地址https://coding.imooc.com/lesson/201.html#mid=12719 1重点关注1.1本节内容javaapi客户端新增临时节点和永久节点 1.2javaapi新增节点同步调用/***同步或者异步创建节点,都不支持子节点的递归......
  • 信息工程大学第五届超越杯程序设计竞赛(同步赛)题解
    比赛传送门c++模板框架#pragmaGCCoptimize(3,"Ofast","inline")#include<bits/stdc++.h>#definerep(i,a,b)for(inti=a;i<b;++i)#defineper(i,a,b)for(inti=a;i>b;--i)#definesesecond#definefifirst#defineendl'\n�......
  • ElasticSearch
    ElasticSearch概述Elasticsearch,简称为es,es是一个开源的高扩展的分布式全文检索引擎,他可以近乎实时的存储、检索数据;本身扩展性很好,可以扩展到上百台服务器,处理PB级别(大数据时代)的数据。es也是用Java开发并使用Lucene作为其核心来实现所有索引和搜索的功能,但是它的目的是通过简......
  • Java(2) ----- 异常、多线程、同步安全、死锁、并发包、Lambda表达式、Stream流
    异常方法默认都可以自动抛出运行时异常!自定义异常:(1)自定义编译时异常1、定义一个异常类继承Exception2、重写构造器3、在出现异常的地方用thrownew自定义对象抛出4、编译时异常是编译阶段就报错,提醒跟家强烈,一定需要处理!(2)自定义运行时异常1、定义一个异常类继承RunTimeE......
  • Vuex的核心组成、版本问题及store.js的使用、 Vuex中存值、取值以及获取变量值、异步
    Vuex的核心组成、版本问题及store.js的使用、Vuex中存值、取值以及获取变量值、异步同步操作和Vuex后台交互  //store//初始值//设置值mutations  ---this.$store.commit('setDemoValue方法名',value); //更新值action --this.$store.disp......
  • openGauss 基于Dorado存储同步复制的主备双集群容灾
    基于Dorado存储同步复制的主备双集群容灾可获得性本特性自openGauss5.1.0版本开始引入,仅适用于资源池化架构。特性简介本特性采用Dorado存储的同步复制能力来实现主备双集群的xlog日志同步,保证主备双集群xlog日志实时一致性,从而提升主备双集群的事务性能,降低存储空间,并保证主......
  • postgresql自定义函数实现功能有两个数组arr1,arr2,返回第一个数组中不在第二个数组的
    CREATEORREPLACEFUNCTIONarray_difference(arr1text[],arr2text[])RETURNStext[]AS$$DECLAREresult_arrtext[];BEGIN--初始化结果数组为一个空数组result_arr:='{}';--遍历第一个数组中的每个元素FORiIN1..array_leng......
  • postgresql自定义函数实现三个数组存在相同数据,且在第四个数组中不存在的数据
    --使用postgresql语言写一个函数,实现以下功能:--1有管理权限用户数组、列表权限用户数组、查看权限用户数组、无权限用户数组四个用户数组--2当无权限用户数组存在用户数据时,如果管理权限用户数组,列表权限用户数组,查看权限用户数组中存在相同的用户数据,并且和无权限用户数......
  • 快麦ERP中采购单在旺店通中同步退货
    什么是快麦ERP快麦ERP作为专业的电商ERP系统软件,为所有的商家提供涵盖订单、库存、分销、采购、财务、员工绩效等一体化的电商ERP解决方案。通过仓储数字化升级和库存精准化管理,帮助商家有更高效的工作体系,以数字赋能大卖家实现降本增效快麦ERP系统的优化体系流程优化:分析和优......
  • 【学习资料】5G UE下行同步(PSS SSS PBCH MIB和SIB1系统信息解码( PDCCH PDSCH )
    https://ww2.mathworks.cn/help/5g/ug/nr-cell-search-and-mib-and-sib1-recovery.html通过本用例可以学习SSBPSSSSS实现的下行时频同步以及CELL_ID解码PBCH解码MIB信息以及频率的精同步PDCCHDCI解码PDSCHSIB1解码Matlab提供了协议级仿真函数,不可多得的仿真环境 ......