HBase建表-修改表属性脚本

0.orignal.sh

echo `hbase shell <<EOF
 exists 'dc_task'
 quit
EOF` | grep 'does exist' >/dev/null 2>&1
rtstatus=$?
if [ $rtstatus -ne 0 ]; then
 `hbase shell <<EOF
 create 'dc_task','region'
 quit
EOF` >/dev/null 2>&1
fi 

1.create-hbase-table.sh

#!/bin/bash
htablename=$1

if [ $# -eq 1 ]; then
  date
  echo `hbase shell <<EOF
    exists $htablename
    quit
  EOF` | grep 'does exist' >/dev/null 2>&1
  rtstatus=$?
  if [ $rtstatus -ne 0 ]; then
    echo $htablename" hbase-table is creating and configuring..."
    `hbase shell <<EOF
      create '$htablename','data'
      disable '$htablename'
      alter '$htablename', METHOD => 'table_att', 'coprocessor' => 'hdfs:///hbase/lib/observer-$htablename.jar|com.jusfoun.data.DataSyncObserver|1001|es_cluster=elas2.3.4,es_type=data,es_index=hbase,es_port=9300,es_host=localhost--127.0.0.1'
      enable '$htablename'
      quit
    EOF` >/dev/null 2>&1
    echo $htablename" hbase-table is successed for create and configure."
  else
    echo "hbase-table already exists for name:"$htablename
  fi
  date
else
  echo "参数输入有误,请确认后重新运行。"
  echo "Usage: sh "$0" <HBase Table Name>"
fi

2.create-hbase-table-es-type.sh

#!/bin/bash
htablename=$1
estypename=$2

if [ $# -eq 2 ]; then
  date
  echo `hbase shell <<EOF
    exists $htablename
    quit
  EOF` | grep 'does exist' >/dev/null 2>&1
  rtstatus=$?
  if [ $rtstatus -ne 0 ]; then
    echo "copying new observer.jar to observer-"$htablename".jar..."
    hdfs dfs -cp /hbase/lib/observer.jar /hbase/lib/observer-$htablename.jar
    echo $htablename" hbase-table is creating and configuring..."
    `hbase shell <<EOF
      create '$htablename','data'
      disable '$htablename'
      alter '$htablename', METHOD => 'table_att', 'coprocessor' => 'hdfs:///hbase/lib/observer-$htablename.jar|com.jusfoun.data.DataSyncObserver|1001|es_cluster=elas2.3.4,es_type=$estypename,es_index=hbase,es_port=9300,es_host=localhost--127.0.0.1'
      enable '$htablename'
      quit
    EOF` >/dev/null 2>&1
    echo $htablename" hbase-table is successed for create and configure."
  else
    echo "hbase-table already exists for name:"$htablename
  fi
  date
else
  echo "参数输入有误,请确认后重新运行。"
  echo "Usage: sh "$0" <HBase Table Name> <ElasticSearch Type Name>"
fi

3.create-hb-es-server.sh

#!/bin/bash
htablename=$1
estypename=$2

if [ $# -eq 2 ]; then
  date
  echo `hbase shell <<EOF
    exists $htablename
    quit
  EOF` | grep 'does exist' >/dev/null 2>&1
  rtstatus=$?
  if [ $rtstatus -ne 0 ]; then
    echo "copying new observer.jar to observer-"$htablename".jar..."
    hdfs dfs -cp /hbase/lib/observer.jar /hbase/lib/observer-$htablename.jar
    echo $htablename" hbase-table is creating and configuring..."
    `hbase shell <<EOF
      create '$htablename','data'
      disable '$htablename'
      alter '$htablename', METHOD => 'table_att', 'coprocessor' => 'hdfs:///hbase/lib/observer-$htablename.jar|com.jusfoun.data.DataSyncObserver|1001|es_cluster=esc,es_type=$estypename,es_index=hbase,es_port=9300,es_host=192.168.4.205--192.168.4.206--192.168.4.207'
      enable '$htablename'
      quit
    EOF` >/dev/null 2>&1
    echo $htablename" hbase-table is successed for create and configure."
  else
    echo "hbase-table already exists for name:"$htablename
  fi
  date
else
  echo "参数输入有误,请确认后重新运行。"
  echo "Usage: sh "$0" <HBase Table Name> <ElasticSearch Type Name>"
fi

4.create-hb-es-index-type.sh

HBaseTableName=$1
sourceDBName=$2
function changeHTableProp{
    local htbale=$1
    local srcdb=$2
    hdfs dfs -cp /hbase/lib/observer.jar /hbase/lib/observer-$htbale.jar
    `hbase shell <<EOF
      disable '$htbale'
      alter '$htbale', METHOD => 'table_att', 'coprocessor' => 'hdfs:///hbase/lib/observer-$HBaseTableName.jar|com.jusfoun.data.DataSyncObserver|1001|es_cluster=esc,es_type=$htbale,es_index=$srcdb,es_port=9300,es_host=192.168.4.205--192.168.4.206--192.168.4.207'
      enable '$htbale'
      quit
EOF` >/dev/null 2>&1
}

echo `hbase shell <<EOF
    exists $HBaseTableName
    quit
EOF` | grep 'does exist' >/dev/null 2>&1
    if [ $? -ne 0 ]; then
    `hbase shell <<EOF
      create '$HBaseTableName','data'
      quit
EOF` >/dev/null 2>&1
    changeHTableProp $HBaseTableName $sourceDBName
   fi
changeHTableProp $HBaseTableName $sourceDBName
    原文作者:水他
    原文地址: https://www.jianshu.com/p/ce4c0647dee3
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞