Elasticsearch 在项目中的实战(三)

.1  安装数据库同步程序将原有项目数据库数据和ES库连接同步,此处用到工具elasticsearch-jdbc

1.安装数据库同步服务 elasticsearch-jdbc

将elasticsearch-jdbc-2.3.4.1.zip解压到/opt/aspire/product/search/(解压指令unzip)

解压考指令(不包含端口修改等操作):

cd /opt/aspire/product/search/upload

cp elasticsearch-jdbc-2.3.4.1.zip ..

cd ..

unzip elasticsearch-jdbc-2.3.4.1.zip


.1  配置数据源

2.配置数据源

进入${$ES_JDBC_HOME } /bin目录

修改sp_server.sh文件,设置数据库链接、用户名和密码和ES的服务器配置,其中红色部分为oracle数据库配置,蓝色部分为ES的配置。

#!/bin/sh

 

# This example is a template to connect to Oracle

# The JDBC URL and SQL must be replaced by working ones.

 

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

bin=${DIR}/../bin

lib=${DIR}/../lib

 

echo '

{

    "type" : "jdbc",

    "jdbc" : {

        "url" : "jdbc:oracle:thin:@//10.12.3.123:1521/ora11g",

        "connection_properties" : {

            "oracle.jdbc.TcpNoDelay" : false,

            "useFetchSizeWithLongColumn" : false,

            "oracle.net.CONNECT_TIMEOUT" : 10000,

            "oracle.jdbc.ReadTimeout" : 50000

        },

        "user" : "zenglx",

        "password" : "zenglx",

        "sql" : "select id,name,text from business_table",

        "index" : "bss",

        "type" : "businsess_type",

        "elasticsearch" : {

            "cluster" : "",

            "host" : "10.12.3.122",

            "port" : 9300

        },

        "max_bulk_actions" : 20000,

        "max_concurrent_bulk_requests" : 10,

        "index_settings" : {

            "index" : {

                "number_of_shards" : 1,

                "number_of_replica" : 0

            }

        },

                "timezone" : "GMT",

                "max_retries" : 3,

            "max_retries_wait" : "30s",

                "schedule" : "0 0-59 0-23 ? * *", 

                "query_timeout" : 1800

                 

    }

}

' | java \

    -cp "${lib}/*" \

    -Dlog4j.configurationFile=${bin}/log4j2.xml \

    org.xbib.tools.Runner \

    org.xbib.tools.JDBCImporter


1.   启动同步服务

3.启动服务

进入${$ES_JDBC_HOME } /bin目录,运行sp_server.sh启动同步服务,后在同级目录会生成sp_server.json文件。

日志会保存在${$ES_JDBC_HOME } /bin/logs下面,可查看日志是否执行成功

猜你喜欢

转载自blog.csdn.net/zengliangxi/article/details/80481119
今日推荐