【原创】hive搭建
Multi User Mode:通过网络连接到一个数据库中,是最经常使用到的模式。
FAILED: Error in metadata: javax.jdo.JDOFatalDataStoreException: Failed to start database 'metastore_db', see the next exception for details.
NestedThrowables:
java.sql.SQLException: Failed to start database 'metastore_db', see the next exception for details.
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask
下面我们开始搭建本地文件系统存放hive的元数据,步骤很简单!
export PATH=$HIVE_HOME/bin:$PATH
[root@hadoop1 ~]# cp /root/hbase/hbase-0.92.1-tests.jar /root/hive-0.8.1-bin/lib/
[root@hadoop1 ~]# mv /root/hive-0.8.1-bin/lib/hbase-0.89.0-SNAPSHOT.jar /home
[root@hadoop1 ~]# mv /root/hive-0.8.1-bin/lib/hbase-0.89.0-SNAPSHOT-tests.jar /home
[root@hadoop1 ~]# cp /root/hbase/conf/hbase-site.xml /root/hive-0.8.1-bin/conf
5、将默认的hive-default.xml.template拷贝一份为hive-site.xml文件
WARNING: org.apache.hadoop.metrics.jvm.EventCounter is deprecated. Please use org.apache.hadoop.log.metrics.EventCounter in all the log4j.properties files.
Logging initialized using configuration in jar:file:/root/hive-0.8.1-bin/lib/hive-common-0.8.1.jar!/hive-log4j.properties
Hive history file=/tmp/root/hive_job_log_root_201207200921_612921620.txt
hive> show tables;
OK
Time taken: 4.656 seconds
7、测试hive能否正常工作?我们现在hbase中新建一张表,然后插入点数据,最后在hive中关联上hbase里面的表,看看数据是否一致哈!
0 row(s) in 1.0680 seconds
0 row(s) in 0.1260 seconds
ROW COLUMN CELL
10000 column=cf1:val, timestamp=1342748087354, value=China
1 row(s) in 0.0310 seconds
> STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
> WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:val")
> TBLPROPERTIES ("hbase.table.name" = "xyz");
OK
Time taken: 1.186 seconds
hive> select * from hbase_table_1;
OK
10000 China
Time taken: 0.455 seconds
这样基本就测试可以了哈!
export PATH=$HIVE_HOME/bin:$PATH
3、把hbase的jar包copy到hive中
`hbase/hbase-0.92.1.jar' -> `hive-0.8.1-bin/lib/hbase-0.92.1.jar'
[root@hadoop1 ~]# cp -v hbase/hbase-0.92.1-tests.jar hive-0.8.1-bin/lib/
`hbase/hbase-0.92.1-tests.jar' -> `hive-0.8.1-bin/lib/hbase-0.92.1-tests.jar'
[root@hadoop1 ~]# cp -v hbase/conf/hbase-site.xml hive-0.8.1-bin/conf
`hbase/conf/hbase-site.xml' -> `hive-0.8.1-bin/conf/hbase-site.xml'
[root@hadoop1 ~]# mv hive-0.8.1-bin/lib/hbase-0.89.0-SNAPSHOT.jar /home
[root@hadoop1 ~]# mv hive-0.8.1-bin/lib/hbase-0.89.0-SNAPSHOT-tests.jar /home/
4、修改hive环境hive-config.sh,增加hadoop的安装路径,复制配置文件:
export HIVE_HOME=/root/hive-0.8.1-bin
[root@hadoop1 ~]# cp hive-0.8.1-bin/conf/hive-default.xml.template hive-0.8.1-bin/conf/hive-site.xml
yum -y install bison gcc gcc-c autoconf automake zlib* libxml* ncurses-devel libtool-ltdl-devel*
mysql需要cmake编译,所以先安装cmake
[root@hadoop1 ~]# tar zxvf cmake-2.8.6.tar.gz
[root@hadoop1 ~]# gmake
建立mysql用户和组,并且建立mysql存放数据的目录/mysql
[root@hadoop1 ~]# /usr/sbin/useradd -g mysql mysql
[root@hadoop1 ~]# mkdir /mysql
[root@hadoop1 ~]# chown -R mysql:mysql /mysql
安装mysql
[root@hadoop1 ~]# cd mysql-5.5.24
[root@hadoop1 ~]# cmake . -DCMAKE_INSTALL_PREFIX=/opt/mysql -DMYSQL_DATADIR=/mysql -DSYSCONFDIR=/etc/
[root@hadoop1 ~]# make && make install
修改my.cnf文件
wait-timeout = 30
max_connections = 512
default-storage-engine = MyISAM
在[mysqld]段修改:
生产授权表:
开启mysql:
更改密码:
测试连接mysql及授权用户登录:
mysql> create user 'hive'@'192.168.3.65' identified by 'hivepasswd';
6、修改hive的配置文件hive-site.xml
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
hive.metastore.local
true
controls whether to connect to remove metastore server or open a new metastore server in Hive Client JVM
javax.jdo.option.ConnectionURL
jdbc:mysql://192.168.3.65:3306/hive?createDatabaseIfNotExist=true
192.168.3.65 JDBC connect string for a JDBC metastore
javax.jdo.option.ConnectionDriverName
com.mysql.jdbc.Driver
Driver class name for a JDBC metastore
javax.jdo.option.ConnectionUserName
hive
username to use against metastore database
javax.jdo.option.ConnectionPassword
hivepasswd
password to use against metastore database
7、添加jdbc的jar包:
wget http://ftp.iij.ad.jp/pub/db/mysql/Downloads/Connector-J/mysql-connector-java-5.1.18.tar.gz
tar vxf mysql-connector-java-5.1.18.tar.gz
chwon -R hadoop mysql-connector-java-5.1.18/
cp -v mysql-connector-java-5.1.18/mysql-connector-java-5.1.18-bin.jar hive/lib/
WARNING: org.apache.hadoop.metrics.jvm.EventCounter is deprecated. Please use org.apache.hadoop.log.metrics.EventCounter in all the log4j.properties files.
Logging initialized using configuration in jar:file:/root/hive-0.8.1-bin/lib/hive-common-0.8.1.jar!/hive-log4j.properties
Hive history file=/tmp/root/hive_job_log_root_201207201723_1051702106.txt
hive> show tables;
OK
Time taken: 3.301 seconds
还是关联hbase中的表测试:
0 row(s) in 1.1120 seconds
0 row(s) in 0.2080 seconds
0 row(s) in 0.0320 seconds
ROW COLUMN+CELL
10000 column=cf1:val, timestamp=1342776914297, value=China
11000 column=cf1:val, timestamp=1342776933201, value=Japanese
2 row(s) in 0.0340 seconds
> STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'
> WITH SERDEPROPERTIES ("hbase.columns.mapping" = ":key,cf1:val")
> TBLPROPERTIES ("hbase.table.name" = "xyz");
OK
Time taken: 1.155 seconds
hive> select * from hbase_table_1;
OK
10000 China
11000 Japanese
Time taken: 0.379 seconds
这样基本就OK了哈!顺便看看mysql中的hive库中存放哪些表?
mysql> use hive;
Database changed
mysql> show tables;
+-----------------+
| Tables_in_hive |
+-----------------+
| BUCKETING_COLS |
| CDS |
| COLUMNS_V2 |
| DATABASE_PARAMS |
| DBS |
| PARTITION_KEYS |
| SDS |
| SD_PARAMS |
| SEQUENCE_TABLE |
| SERDES |
| SERDE_PARAMS |
| SORT_COLS |
| TABLE_PARAMS |
| TBLS |
+-----------------+
14 rows in set (0.00 sec)