1、首先将hive-0.12.0-cdh5.1.2.tar.gz解压到某台准备安装hive的机器上,比如我们放到/usr/local下面。
2、将以下几个jar包拷贝到$HIVE_HOME/lib目录下面:
ant-1.9.1.jar
ant-launcher-1.9.1.jar
antlr-2.7.7.jar
antlr-runtime-3.4.jar
avro-1.7.5-cdh5.1.2.jar
bonecp-0.7.1.RELEASE.jar
commons-cli-1.2.jar
commons-codec-1.4.jar
commons-collections-3.2.1.jar
commons-compress-1.4.1.jar
commons-httpclient-3.0.1.jar
commons-io-2.4.jar
commons-lang-2.4.jar
commons-logging-1.1.3.jar
datanucleus-api-jdo-3.2.1.jar
datanucleus-core-3.2.2.jar
datanucleus-rdbms-3.2.1.jar
derby-10.4.2.0.jar
groovy-all-2.1.6.jar
guava-11.0.2.jar
hadoop-annotations-2.3.0-cdh5.1.2.jar
hadoop-auth-2.3.0-cdh5.1.2.jar
hadoop-common-2.3.0-cdh5.1.2.jar
hadoop-hdfs-2.3.0-cdh5.1.2.jar
hamcrest-core-1.1.jar
hamza-core-0.1.0.jar
hbase-client-0.98.1-cdh5.1.2.jar
hbase-common-0.98.1-cdh5.1.2.jar
hbase-examples-0.98.1-cdh5.1.2.jar
hbase-hadoop2-compat-0.98.1-cdh5.1.2.jar
hbase-hadoop-compat-0.98.1-cdh5.1.2.jar
hbase-it-0.98.1-cdh5.1.2.jar
hbase-prefix-tree-0.98.1-cdh5.1.2.jar
hbase-protocol-0.98.1-cdh5.1.2.jar
hbase-server-0.98.1-cdh5.1.2.jar
hbase-shell-0.98.1-cdh5.1.2.jar
hbase-testing-util-0.98.1-cdh5.1.2.jar
hbase-thrift-0.98.1-cdh5.1.2.jar
hive-ant-0.12.0-cdh5.1.2.jar
hive-beeline-0.12.0-cdh5.1.2.jar
hive-cli-0.12.0-cdh5.1.2.jar
hive-common-0.12.0-cdh5.1.2.jar
hive-contrib-0.12.0-cdh5.1.2.jar
hive-exec-0.12.0-cdh5.1.2.jar
hive-hbase-handler-0.12.0-cdh5.1.2.jar
hive-hwi-0.12.0-cdh5.1.2.jar
hive-jdbc-0.12.0-cdh5.1.2.jar
hive-metastore-0.12.0-cdh5.1.2.jar
hive-serde-0.12.0-cdh5.1.2.jar
hive-service-0.12.0-cdh5.1.2.jar
hive-shims-0.12.0-cdh5.1.2.jar
hive-shims-0.23-0.12.0-cdh5.1.2.jar
hive-shims-common-0.12.0-cdh5.1.2.jar
hive-shims-common-secure-0.12.0-cdh5.1.2.jar
hive-testutils-0.12.0-cdh5.1.2.jar
htrace-core-2.04.jar
httpclient-4.2.5.jar
httpcore-4.2.5.jar
jdo-api-3.0.1.jar
jetty-6.1.26.cloudera.2.jar
jetty-util-6.1.26.cloudera.2.jar
jline-0.9.94.jar
jsr305-1.3.9.jar
jta-1.1.jar
junit-4.10.jar
libfb303-0.9.0.jar
libthrift-0.9.0.cloudera.2.jar
log4j-1.2.16.jar
mybatis-3.1.1.jar
mysql-connector-java-5.1.10.jar
oro-2.0.8.jar
paranamer-2.3.jar
parquet-hadoop-bundle-1.2.5-cdh5.1.2.jar
servlet-api-2.5-20081211.jar
slf4j-api-1.7.5.jar
slf4j-log4j12-1.7.5.jar
snappy-java-1.0.4.1.jar
ST4-4.0.4.jar
stax-api-1.0.1.jar
stringtemplate-3.2.1.jar
tempus-fugit-1.1.jar
velocity-1.5.jar
xz-1.0.jar
zookeeper-3.4.5-cdh5.1.2.jar
注意hamza-core的包根据具体使用的Hamza工程版本为准,请一定要保持和hamza-client一致。hamza-client是提供给业务方使用jdbc访问的jar包.
3、更改$HIVE_HOME/conf/hive-log4j.propertis(cp hive-log4j.properties.template hive-log4j.properties),
hive.log.dir=/export/logs/hive/
hive.log.file=hive.log
4.修改hive-site.xml(cp hive-default.xml.template hive-site.xml)以下参数:
hive.cli.print.header true
hive.cli.print.current.db true
hive.metastore.warehouse.dir /user/hive/warehouse
Hive.exec.parallel true
hive.querylog.location /export/logs/hive
hive.metastore.ds.retry.attempts 3
hive.exec.mode.local.auto false
hive.server2.session.hook com.weibo.hamza.core.hook.HamzaSessionHook
hive.semantic.analyzer.hook com.weibo.hamza.core.hook.HamzaAnalyzerHook
hive.exec.post.hooks com.weibo.hamza.core.hook.HamzaExecPostHook
javax.jdo.option.ConnectionURL (jdbc:mysql://192.168.69.16:3306/cdh_hive?createDatabaseIfNotExist=true)
javax.jdo.option.ConnectionDriverName com.mysql.jdbc.Driver
javax.jdo.option.ConnectionUserName root
javax.jdo.option.ConnectionPassword 1234567
hive.server2.thrift.bind.host 192.168.69.9
hive.server2.enable.doAs false
5.确保hdfs目录/tmp /user/hive/warehouse目录存在且可以被运行hive的该linux用户读写,确保linux本地目录/export/logs/hive存在且可以被运行hive的该linux用户读写
6.预先在hive依赖的MySQL中创建好库(比如本文中的cdh_hive库,字符集选为UTF-8)进入$HIVE_HOME/bin目录,然后执行以下命令进行元数据metastore初始化:
./schematool -dbType mysql -initSchema
7.继续初始化元数据,加入hamza权限额外需要的几张表(T_HOST里面加入的IP就是hive安装这台机器的IP; 默认加入了一个管理员账户weibo_admin,只存在唯一一个管理员账户):
-- ----------------------------
-- Table structure for `T_DB`
-- ----------------------------
DROP TABLE IF EXISTS `T_DB`;
CREATE TABLE `T_DB` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`owner_id` bigint(20) NOT NULL,
`db_name` varchar(50) NOT NULL,
`create_time` datetime NOT NULL,
`remarks` varchar(50) NOT NULL,
`gmt_created` datetime DEFAULT NULL,
`gmt_modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of T_DB
-- ----------------------------
INSERT INTO `T_DB` VALUES ('1', '1', 'default', '2015-03-27 15:44:58', 'ss', '2015-03-27 15:45:02', '2015-03-27 15:45:05');
-- ----------------------------
-- Table structure for `T_DBPRIV`
-- ----------------------------
DROP TABLE IF EXISTS `T_DBPRIV`;
CREATE TABLE `T_DBPRIV` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) NOT NULL,
`db_id` bigint(20) NOT NULL,
`select_priv` tinyint(4) DEFAULT NULL,
`insert_priv` tinyint(4) DEFAULT NULL,
`update_priv` tinyint(4) DEFAULT NULL,
`load_priv` tinyint(4) DEFAULT NULL,
`delete_priv` tinyint(4) DEFAULT NULL,
`alter_priv` tinyint(4) DEFAULT NULL,
`create_priv` tinyint(4) DEFAULT NULL,
`drop_priv` tinyint(4) DEFAULT NULL,
`show_priv` tinyint(4) DEFAULT NULL,
`truncate_priv` tinyint(4) DEFAULT NULL,
`describe_priv` tinyint(4) DEFAULT NULL,
`gmt_created` datetime DEFAULT NULL,
`gmt_modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for `T_HOST`
-- ----------------------------
DROP TABLE IF EXISTS `T_HOST`;
CREATE TABLE `T_HOST` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`ip` varchar(50) NOT NULL,
`enabled` tinyint(4) NOT NULL,
`remarks` varchar(50) NOT NULL,
`gmt_created` datetime DEFAULT NULL,
`gmt_modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of T_HOST
-- ----------------------------
INSERT INTO `T_HOST` VALUES ('1', '192.161.68.9', '1', 'ss', '2015-03-27 15:43:17', '2015-03-27 15:43:19');
-- ----------------------------
-- Table structure for `T_TABLE`
-- ----------------------------
DROP TABLE IF EXISTS `T_TABLE`;
CREATE TABLE `T_TABLE` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`db_id` bigint(20) NOT NULL,
`tbl_name` varchar(50) NOT NULL,
`create_time` datetime NOT NULL,
`remarks` varchar(50) NOT NULL,
`gmt_created` datetime DEFAULT NULL,
`gmt_modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for `T_TABLEPRIV`
-- ----------------------------
DROP TABLE IF EXISTS `T_TABLEPRIV`;
CREATE TABLE `T_TABLEPRIV` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_id` bigint(20) NOT NULL,
`tbl_id` bigint(20) NOT NULL,
`priv` varchar(200) DEFAULT NULL,
`grant_time` datetime DEFAULT NULL,
`remarks` varchar(50) DEFAULT NULL,
`gmt_created` datetime DEFAULT NULL,
`gmt_modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Table structure for `T_USER`
-- ----------------------------
DROP TABLE IF EXISTS `T_USER`;
CREATE TABLE `T_USER` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`user_name` varchar(50) NOT NULL,
`password` varchar(50) NOT NULL,
`user_type` int(20) NOT NULL,
`enabled` tinyint(4) NOT NULL,
`remarks` varchar(50) NOT NULL,
`gmt_created` datetime DEFAULT NULL,
`gmt_modified` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-- ----------------------------
-- Records of T_USER
-- ----------------------------
INSERT INTO `T_USER` VALUES ('1', 'weibo_admin', 'hMyLXJ6uddQSy1WU', '1', '1', 'ss', '2015-03-27 15:40:52', '2015-03-27 15:40:55');
8.命令行下执行以下命令,验证安装是否成功:
$HIVE_HOME/bin/hive
hive> set hivevar:hamza.usr=squirrel_admin;
hive> set hivevar:hamza.passwd=!QAZxsw2;
也可以启动hiveserver2后远程通过beeline连接
$HIVE_HOME/bin/hiveserver2 &
$HIVE_HOME/bin/beeline -u "jdbc:hive2://192.161.68.9:10000/default" --hivevar hamza.usr="weibo_admin" --hivevar hamza.passwd="hMyLXJ6uddQSy1WU" --color=true -e "show tables";
9.要完成跟squirrel_web界面整合,需要在t_group_hive_relation里面加入一条记录,将hive管理员(weibo_admin)和squirrel的管理员组管理起来:
10.通过hive jdbc方式访问,需要将以下依赖加入工程(已经加入公司私服):
<dependency>
<groupId>com.weibo.hamza</groupId>
<artifactId>hamza-client</artifactId>
<version>0.1.0</version>
</dependency>
Class.forName("com.weibo.hamza.client.jdbc.HiveDriver");
String url = "jdbc:hive2://192.161.68.9:10000/default";
Connection conn = DriverManager.getConnection(url, username, pwd);
Statement stmt = conn.createStatement();
stmt.executeQuery(sql);