美文网首页
linkedin 的 databus 部署

linkedin 的 databus 部署

作者: 乘以零 | 来源:发表于2017-08-24 15:39 被阅读0次

    1. 下载源码 复制 ojdbc.jar 到相应的文件夹

    git clone  https://github.com/linkedin/databus/   
    
    sandbox-repo/com/oracle/ojdbc6/11.2.0.2.0/ojdbc6-11.2.0.2.0.jar
    

    2. 在 subprojects.gradle 中 加上

    options.addStringOption('encoding', 'UTF-8')
    

    最后的结果为

    if (JavaVersion.current().isJava8Compatible()) {
        allprojects {
            tasks.withType(Javadoc) {
                options.addStringOption('Xdoclint:none', '-quiet')
                options.addStringOption('encoding', 'UTF-8')
            }
        }
    }
    

    3. 在 build.gradle 中加上

    tasks.withType(JavaCompile) { options.encoding = "UTF-8" }
    

    4. 在 com.linkedin.databus2.core.container.netty.ServerContainer 的 initializeContainerJmx() 方法中加上一句

    LocateRegistry.createRegistry(_containerStaticConfig.getJmx().getRmiRegistryPort());
    

    最后的结果为 (不然会报 Cannot bind to URL rmi://localhost:1099 ServiceUnavailableException )

    protected void initializeContainerJmx() {
        if (_containerStaticConfig.getJmx().isRmiEnabled()) {
            try {
                JMXServiceURL jmxServiceUrl = new JMXServiceURL(
                        "service:jmx:rmi://" + _containerStaticConfig.getJmx().getJmxServiceHost() + ":"
                                + _containerStaticConfig.getJmx().getJmxServicePort() + "/jndi/rmi://"
                                + _containerStaticConfig.getJmx().getRmiRegistryHost() + ":"
                                + _containerStaticConfig.getJmx().getRmiRegistryPort() + "/jmxrmi"
                                + _containerStaticConfig.getJmx().getJmxServicePort());
              LocateRegistry.createRegistry(_containerStaticConfig.getJmx().getRmiRegistryPort());
                _jmxConnServer = JMXConnectorServerFactory.newJMXConnectorServer(jmxServiceUrl, null, getMbeanServer());
            } catch (Exception e) {
                LOG.warn("Unable to instantiate JMX server", e);
            }
        }
    }
    

    5. 修改 databus2-example-client-pkg/conf/client_person.properties (非必须)

    databus.client.connectionDefaults.enablePullerMessageQueueLogging=false
    

    不然 databus2-example-client-pkg 中的 databus2-client-person.out 日志文件会快速增长

    6. 修改 oracle/bin/createUser.sh

    sqlplus system/manager\@${DBNAME} as sysdba << __EOF__
    

    改为自己的oracle管理员 用户名 密码
    system为管理员用户名 manager为密码

    7. 修改 databus2-example/database/person/tablespace (不改也没关系 下面的要一致 我是改成了 tbs_dbbus)

    8. 修改 sources-person.json 改为

    {
        "name": "person",
        "id": 1,
        "uri": "jdbc:oracle:thin:dbbus/dbbus@localhost:1521:orcl",
        "slowSourceQueryThreshold": 2000,
        "sources": [
            {
                "id": 101,
                "name": "com.linkedin.events.example.person.Person",
                "uri": "dbbus.person",
                "partitionFunction": "constant:1"
            }
        ]
    }
    

    9. 打包命令

    gradle -Dopen_source=true assemble
    

    生成的工程在 父项目的 build 目录下 (这一点gradle和maven不一样的 )

    10. 运行 createUser.sh 新建oracle 用户 dbbus/dbbus 这里的 db_table_space 要与 第8步骤中 databus2-example/database/person/tablespace 里面内容一致

    db_path 存放 oracle .dbf 文件的地方 如果不知道 find / -name '.dbf' 就可以找到路径了 乱写应该问题也不大(我没试过)

    #createUser.sh db_username db_password db_id db_table_space db_path
    sh createUser.sh dbbus dbbus orcl tbs_dbbus /home/u02/11g/dbs/
    

    11.运行 createSchema.sh 在oracle中生成必要的 package table seq tigger Procedure 等

    #createSchema.sh db_username/db_password@db_id tab_and_view_path
    sh createSchema.sh dbbus/dbbus@orcl /home/yiwu/databus/databus2-example/database/person/
    

    12. 生成 apache-avro 序列化文件

    • 如 com.linkedin.events.example.person.Person.1.avsc com.linkedin.events.example.person.Person_V1.java
    • 这步可以省略 官方的例子已经给你生成好了
    • avroOutDir javaOutDir 自定义 不需要太准确 生成好之后 拷贝到相应的目录就可以了
    #create Avro records
    sh dbus2-avro-schema-gen.sh -namespace com.linkedin.events.example.person -recordName Person -viewName "sy\$person" -avroOutDir /home/yiwu/dbtmp -avroOutVersion 1 -javaOutDir /home/yiwu/dbtmp -userName dbbus -password dbbus -database jdbc:oracle:thin:@127.0.0.1:1521:orcl
    
    

    13. 运行 relay

    #解压 
    tar -zxvf build/databus2-example-relay-pkg/distributions/databus2-example-relay-pkg-2.0.0.tar.gz
    #运行 
    sh start-example-relay.sh person
    

    14. 运行 client

    #解压 
    tar -zxvf build/databus2-example-client-pkg/distributions/databus2-example-client-pkg-2.0.0.tar.gz
    #运行 
    sh start-example-client.sh person 
    

    15. 在oracle中执行insert语句

    INSERT INTO person(id,first_name, last_name) VALUES(1,'balaji', 'varadaran');
    

    就可以在 build/databus2-example-client-pkg/distributions/logs/client.log 中看到相应的记录了

    2017-08-24 14:46:46,795 +752167 [callback-1] (INFO) {PersonConsumer} firstName: balaji, lastName: varadaran, birthDate: null, deleted: false
    

    end

    相关文章

      网友评论

          本文标题:linkedin 的 databus 部署

          本文链接:https://www.haomeiwen.com/subject/dbdedxtx.html