hive安装:3.1.2版本
hive下载地址: https://downloads.apache.org/hive/hive-3.1.2/apache-hive-3.1.2-bin.tar.gz
或者镜像:https://dlcdn.apache.org/hive/hive-3.1.2/
hive的home目录:https://cwiki.apache.org/confluence/display/Hive/Home
hive安装文档:https://cwiki.apache.org/confluence/display/Hive/GettingStarted
hive在线学习文档:https://cwiki.apache.org/confluence/display/Hive/Tutorial
安装环境:
hadoop+jdk+环境变量+mysql8.23
hive中sql语法类似mysql
1,解压文件并设置环境变量
解压文件
tar -zxvf apache-hive-3.1.2-bin.tar.gz
重命名
mv apache-hive-3.1.2-bin apache-hive-3.1.2
设置环境变量
vi /etc/profile
添加环境变量
#hive
export HIVE_HOME=/apps/bigdata/apache-hive-3.1.2
export PATH=$HIVE_HOME/bin:$PATH
刷新环境变量
source /etc/profile
2.元数据默认derby,生产库使用mysql,(此处使用mysql)
内置derby(测试)
bin/hive 启动 和 ./hive启动不一致
缺点:不同路径启动hive,每个hive拥有一套自己的元数据,无法共享,
mysql版本
修改配置文件 conf/hive-site.xml
复制文件并重命名
cp hive-default.xml.template hive-site.xml
<property>
<name>hive.server2.active.passive.ha.enable</name>
<value>true</value>
<description>启用Hive Interactive会话时是否启用HiveServer2主备高可用性。这也需要hive.server2.support.dynamic.service。启用发现</description>
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://192.168.189.10:3306/hive?createDatabaseIfNotExist=true</value>
<description>
JDBC connect string for a JDBC metastore.
To use SSL to encrypt/authenticate the connection, provide database-specific SSL flag in the connection URL.
For example, jdbc:postgresql://myhost/db?ssl=true for postgres database.
</description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.cj.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
<description>Username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>rootpassword</value>
<description>password to use against metastore database</description>
</property>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/hive/warehouse</value>
</property>
<property>
<name>hive.exec.scratchdir</name>
<value>/hive/tmp</value>
</property>
<property>
<name>hive.querylog.location</name>
<value>/hive/log</value>
</property>
<property>
<name>hive.server2.authentication</name>
<value>NONE</value>
</property>
<property>
<name>hive.server2.thrift.bind.host</name>
<value>hadoop1</value>
</property>
<property>
<name>hive.server2.thrift.port</name>
<value>10000</value>
<description>TCP port number to listen on, default 10000</description>
</property>
<property>
<name>hive.server2.thrift.http.port</name>
<value>10001</value>
</property>
<property>
<name>hive.server2.thrift.client.user</name>
<value>root</value>
<description>Username to use against thrift client</description>
</property>
<property>
<name>hive.server2.thrift.client.password</name>
<value>liuchao.</value>
<description>Password to use against thrift client</description>
</property>
备注:
hive.server2.authentication 配置hive用户认证,设置为NONE则跳过认证
hive.server2.thrift.bind.host 配置thrift服务绑定的ip,需要在hadoop1启动hive服务,thrift服务才能与hadoop1建立连接,thrift主要用来实现hiveserver2的瘦客户端
hive.server2.thrift.port 配置thrift服务绑定的端口,主要用来建立与thrift服务连接
hive.server2.thrift.http.port 配置thrift服务绑定的http端口,可以通过http执行hive操作
hive.server2.thrift.client.user 配置thrift服务的验证账户
hive.server2.thrift.client.password 配置thrift服务的验证密码
修改配置文件:core-site.xml
hadoop.proxyuser.root.hosts 配置hadoop的代理用户,主要是用于让hiveserver2客户端访问及操作hadoop文件具备权限
hadoop.proxyuser.root.groups 配置hadoop的代理用户组,主要是用于让hiveserver2客户端访问及操作hadoop文件具备权限
<property>
<name>hadoop.proxyuser.root.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.root.groups</name>
<value>*</value>
</property>
修改配置而文件 conf/hive-env.sh
复制文件并重命名
cp hive-env.sh.template hive-env.sh
配置hadoop地址
export HADOOP_HOME=/apps/bigdata/hadoop-3.2.2
配置hive的conf地址
export HIVE_CONF_DIR=/apps/bigdata/apache-hive-3.1.2/conf
3.mysql8.23安装 hadoop1上
echo "---------1----------"
echo "安装mysql的rpm包"
rpm -ivh mysql-community-common-8.0.23-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-plugins-8.0.23-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.23-1.el7.x86_64.rpm --force --nodeps
rpm -ivh mysql-community-client-8.0.23-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.23-1.el7.x86_64.rpm --force --nodeps
echo "---------2----------"
echo "修改/etc/my.cnf文件"
echo "#设置默认字符集UTF-8" >> /etc/my.cnf
echo "character_set_server=utf8" >> /etc/my.cnf
echo "#设置默认字符集UTF-8" >> /etc/my.cnf
echo "init_connect='SET NAMES utf8'" >> /etc/my.cnf
echo "#解决大小写敏感问题1=不敏感 默认0" >> /etc/my.cnf
echo "lower_case_table_names = 1" >> /etc/my.cnf
echo "skip-grant-tables" >> /etc/my.cnf
sleep 5s
echo "---------3----------"
systemctl start mysqld
echo "---------4----------"
mysql
update user set host='%' where user='root';
SHOW VARIABLES LIKE 'validate_password%';
set global validate_password.policy=0;
set global validate_password.length=1;
flush privileges;
alter user root identified with mysql_native_password by 'rootpassword';
flush privileges;
#退出
exit
#查看状态
systemctl status mysqld
systemctl stop mysqld
echo '删除skip-grant-tables'
sed -i '$d' /etc/my.cnf
systemctl start mysqld
#登陆
mysql -uroot -prootpassword
4.配置
hive.metastore.warehouse.dir 默认/user/hive/warehouse
HDFS上创建/tmp和/user/hive/warehouse两个目录并修改他们的同组权限可写
配置环境变量直接使用命令不用进入hadoop-3.2.2目录下执行bin/hadoop fs -mkdir /tmp
hadoop fs -mkdir -p /hive/tmp
hadoop fs -mkdir -p /hive/warehouse
hadoop fs -mkdir -p /hive/log
hadoop fs -chmod 777 /hive/tmp
hadoop fs -chmod 777 /hive/warehouse
hadoop fs -chmod 777 /hive/log
5./apps/bigdata/apache-hive-3.1.2/bin初始化文件
./schematool -initSchema -dbType mysql
6.启动
进入apache-hive-3.1.2的bin目录
cd /apps/bigdata/apache-hive-3.1.2/bin
启动hive报错
报错Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V
at org.apache.hadoop.conf.Configuration.set(Configuration.java:1380)
...
at org.apache.hadoop.util.RunJar.main(RunJar.java:236)
原因:
hadoop和hive的两个guava.jar版本不一致
两个位置分别位于下面两个目录:
/apps/bigdata/apache-hive-3.1.2/lib/
/apps/bigdata/hadoop-3.2.2/share/hadoop/common/lib/
解决办法:
删除低版本的那个,将高版本的复制到低版本目录下
guava-27.0-jre.jar用这个替换/apps/bigdata/apache-hive-3.1.2/lib/下的guava-19.0.jar
7.同步文件至hadoop2,hadoop3
xsync /etc/profile
xsync /apps/bigdata/apache-hive-3.1.2
8.hive
hadoop2,hadoop3上都可以使用
9.查看hive版本
hive --version
10.启动
bin目录下
nohup hive --service hiveserver2 >> hiveserver2.log 2>&1 &
查看端口:
netstat -tunlp
hiveserver2页面:http://192.168.189.10:10002/
备用其他启动方式
启动
bin/hiveserver2
启动成功后可以在别的节点上用beeline去链接
bin/beeline -u jdbc:hive2://hadoop1:10000 -n root
或者
bin/beeline
!connect jdbc:hive2://hadoop1:10000