本文共 3880 字,大约阅读时间需要 12 分钟。
1. 下载解压cd /mk/softtar -xvzf apache-hive-1.2.1-bin.tar.gz -C /appl/cd /applmv apache-hive-1.2.1-bin hive-1.2.12. 配置环境变量
vi /etc/profileexport HIVE_HOME=/appl/hive-1.2.1export PATH=$PATH:$HIVE_HOME/binexport CLASSPATH=.:$HIVE_HOME/libwqsource /etc/profile3. 配置Hive
cd /appl/hive-1.2.1/confcp hive-default.xml.template hive-default.xml (不改变)cp hive-default.xml.template hive-site.xml (覆盖hive-default.xml配置项)cp hive-env.sh.template hive-env.sh
cp hive-log4j.properties.template hive-log4j.propertiesvi hive-env.shexport HADOOP_HOME=${HADOOP_HOME}export HIVE_CONF_DIR=${HIVE_HOME}/conf
vi hive-log4j.properties#log4j.appender.EventCounter=org.apache.hadoop.hive.shims.HiveEventCounter#log4j.appender.EventCounter=org.apache.hadoop.metrics.jvm.EventCounterlog4j.appender.EventCounter=org.apache.hadoop.log.metrics.EventCountervi hive-site.xml --------
--------javax.jdo.option.ConnectionURL jdbc:mysql://centos1:3306/metastore_hive?createDatabaseIfNotExist=true 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 hive password to use against metastore database hive.metastore.warehouse.dir /hive/warehouse location of default database for the warehouse (hdfs path) hive.metastore.uris thrift://centos1:9083 hive.server2.authentication NONE
hadoop fs -mkdir /hivehadoop fs -mkdir /hive/warehousehadoop fs -chmod g+w /hive/warehousehadoop fs -mkdir /hive/tmphadoop fs -chmod g+w /hive/tmpmysql mysql -uroot -proot
create database metastore_hive;grant all on metastore_hive.* to hive@'%' identified by 'hive';grant all on metastore_hive.* to hive@localhost identified by 'hive';grant all on metastore_hive.* to hive@centos1 identified by 'hive';ALTER DATABASE metastore_hive CHARACTER SET latin1;show databases;exitmysql -hcentos1 -P3306 -uhive -phiveuse metastore_hiveexit传mysql-connector-java-5.1.30-bin.jar到/appl/hive-2.1.0/lib/
hadoop 配置(这一步很多参考文章缺少了)
/appl/hadoop-2.7.0/etc/hadoop/hdfs-site.xml
dfs.permissions false
/appl/hadoop-2.7.0/etc/hadoop/hadoop-env.sh
export HADOOP_CLASSPATH=$CLASSPATH:$HADOOP_CLASSPATH# 开通端口(centos)
/sbin/iptables -I INPUT -p tcp --dport 9083 -j ACCEPT/sbin/iptables -I INPUT -p tcp --dport 10000 -j ACCEPT/etc/init.d/iptables saveservice iptables restart5. 启动服务 1、启动metastore服务 hive --service metastore & (默认端口:9083,可-p 9083控制;测试:hive --service metastore) 2、启动hiveserver服务 hive --service hiveserver2 & (测试:hive --service hiveserver2) 3、访问hiveserver的两种方式 (1) JDBC Class.forName("org.apache.hive.jdbc.HiveDriver"); DriverManager.getConnection("jdbc:hive2://IP:10000/default","",""); (2) beeline beeline -u jdbc:hive2://localhost:10000/ -n hive -p hive 或 beeline
!connect jdbc:hive2://localhost:10000show tables;create table test1 (id int, name string) row format delimited fields terminated by ',' stored as textfile;load data local inpath '/mk/test/test1.txt' into table test1;select * from test1;!quit查看hive文件 hadoop fs -ls /hive/warehouse/test1 停止:因为不是通过服务启动,只能ps -ef|grep hive,再kill <pid> 参考 http://blog.csdn.net/an342647823/article/details/46048403 http://blog.fens.me/hadoop-hive-intro/ http://blog.csdn.net/jiangkai_nju/article/details/7292313 http://blog.csdn.net/reesun/article/details/8556078 http://www.micmiu.com/bigdata/hive/hive-metastore-config/ http://blog.csdn.net/stark_summer/article/details/45844403