1. 环境

2. 查询mysql版本

  1. rpm -qa | grep -i -E mysql\|mariadb

卸载

  1. rpm -qa | grep -i -E mysql\|mariadb | xargs -n1 sudo rpm -e --nodeps

安装

  1. sudo rpm -ivh 01_mysql-community-common-5.7.29-1.el7.x86_64.rpm
  2. sudo rpm -ivh 02_mysql-community-libs-5.7.29-1.el7.x86_64.rpm
  3. sudo rpm -ivh 03_mysql-community-libs-compat-5.7.29-1.el7.x86_64.rpm
  4. sudo rpm -ivh 04_mysql-community-client-5.7.29-1.el7.x86_64.rpm
  5. sudo rpm -ivh 05_mysql-community-server-5.7.29-1.el7.x86_64.rpm
  6. sudo systemctl start mysqld

6.5安装

  1. wget https://cdn.mysql.com//archives/mysql-5.7/mysql-5.7.14-1.el6.x86_64.rpm-bundle.tar
  2. rpm -ivh mysql-community-common-5.7.14-1.el6.x86_64.rpm
  3. rpm -ivh mysql-community-libs-5.7.14-1.el6.x86_64.rpm
  4. rpm -ivh mysql-community-client-5.7.14-1.el6.x86_64.rpm
  5. rpm -ivh mysql-community-server-5.7.14-1.el6.x86_64.rpm
  6. service mysqld start
  7. chkconfig mysqld on #设置开机自启动

如果不行则 在后面加上 —nodeps —force 安装时不再分析包之间的依赖关系而直接安装

查询mysql密码

  1. sudo cat /var/log/mysqld.log | grep password

修改mysql密码

  1. mysql -uroot -ppassword

设置复杂密码(由于mysql密码策略,此密码必须足够复杂)

  1. set global validate_password_length=4;
  2. set global validate_password_policy=0;

设置密码

set password=password("A373213257s");
use mysql
select user, host from user;
update user set host="%" where user="root";  
flush privileges;
quit;

3. 安装hive

tar -zxvf /opt/software/apache-hive-3.1.2-bin.tar.gz -C /opt/module/
mv /opt/module/apache-hive-3.1.2-bin/ /opt/module/hive
#环境变量
sudo vim /etc/profile.d/my_env.sh
#HIVE_HOME
export HIVE_HOME=/opt/module/hive
export PATH=$PATH:$HIVE_HOME/bin
source /etc/profile
mv $HIVE_HOME/lib/log4j-slf4j-impl-2.10.0.jar $HIVE_HOME/lib/log4j-slf4j-impl-2.10.0.bak

4. Hive的元数据配置到mysql

cp /opt/software/mysql-connector-java-5.1.48.jar $HIVE_HOME/lib
vim $HIVE_HOME/conf/hive-site.xml

配置hive-site.xml

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <property>
        <!-- mysql 连接地址-->
        <name>javax.jdo.option.ConnectionURL</name>
        <value>jdbc:mysql://hadoop102:3306/metastore?useSSL=false</value>
    </property>

    <property>
         <!--驱动 -->
        <name>javax.jdo.option.ConnectionDriverName</name>
        <value>com.mysql.jdbc.Driver</value>
    </property>

    <property>
         <!--用户 -->
        <name>javax.jdo.option.ConnectionUserName</name>
        <value>root</value>
    </property>

    <property>
         <!--密码 -->
        <name>javax.jdo.option.ConnectionPassword</name>
        <value>A373213257s</value>
    </property>

    <property>
         <!--hive元数据仓库位置 -->
        <name>hive.metastore.warehouse.dir</name>
        <value>/user/hive/warehouse</value>
    </property>

    <property>
        <name>hive.metastore.schema.verification</name>
        <value>false</value>
    </property>

    <property>
        <name>hive.metastore.uris</name>
        <value>thrift://hadoop102:9083</value>
    </property>

    <property>
    <name>hive.server2.thrift.port</name>
    <value>10000</value>
    </property>

    <property>
        <name>hive.server2.thrift.bind.host</name>
        <value>hadoop102</value>
    </property>

    <property>
        <name>hive.metastore.event.db.notification.api.auth</name>
        <value>false</value>
    </property>

</configuration>

5. Tez引擎

Tez可以将多个有依赖的作业转换为一个作业,这样只需写一次HDFS,且中间节点较少,从而大大提升作业的计算性能

#解压
mkdir /opt/module/tez
tar -zxvf /opt/software/tez-0.10.1-SNAPSHOT.tar.gz -C /opt/module/tez

#上传Tez到hdfs
hadoop fs -mkdir /tez
hadoop fs -put /opt/software/tez-0.10.1-SNAPSHOT.tar.gz /tez

#新建tez-size.xml
vim $HADOOP_HOME/etc/hadoop/tez-site.xml

配置tez-size.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
    <name>tez.lib.uris</name>
    <value>${fs.defaultFS}/tez/tez-0.10.1-SNAPSHOT.tar.gz</value>
</property>
<property>
     <name>tez.use.cluster.hadoop-libs</name>
     <value>true</value>
</property>
<property>
     <name>tez.am.resource.memory.mb</name>
     <value>1024</value>
</property>
<property>
     <name>tez.am.resource.cpu.vcores</name>
     <value>1</value>
</property>
    <!--task\AM占用JVM Xmx的比例,该参数建议调整,需根据具体业务情况修改 默认0.8 -->
<property>
     <name>tez.container.max.java.heap.fraction</name>
     <value>0.8</value>
</property>
<property>
     <name>tez.task.resource.memory.mb</name>
     <value>1024</value>
</property>
<property>
     <name>tez.task.resource.cpu.vcores</name>
     <value>1</value>
</property>
</configuration>

修改Hadoop环境变量

vim $HADOOP_HOME/etc/hadoop/shellprofile.d/tez.sh
hadoop_add_profile tez
function _tez_hadoop_classpath
{
    hadoop_add_classpath "$HADOOP_HOME/etc/hadoop" after
    hadoop_add_classpath "/opt/module/tez/*" after
    hadoop_add_classpath "/opt/module/tez/lib/*" after
}

修改Hive的计算模型

vim $HIVE_HOME/conf/hive-site.xml

追加

<property>
    <name>hive.execution.engine</name>
    <value>tez</value>
</property>
<property>
    <name>hive.tez.container.size</name>
    <value>1024</value>
</property>

解决日志jar包冲突

rm /opt/module/tez/lib/slf4j-log4j12-1.7.10.jar

6. 启动

mysql -uroot -pA373213257s

#建库
create database metastore;
quit;

#初始化hive
schematool -initSchema -dbType mysql -verbose

#编写启动脚本
vim $HIVE_HOME/bin/hiveservices.sh
#!/bin/bash
HIVE_LOG_DIR=$HIVE_HOME/logs

mkdir -p $HIVE_LOG_DIR

#检查进程是否运行正常,参数1为进程名,参数2为进程端口
function check_process()
{
    pid=$(ps -ef 2>/dev/null | grep -v grep | grep -i $1 | awk '{print $2}')
    ppid=$(netstat -nltp 2>/dev/null | grep $2 | awk '{print $7}' | cut -d '/' -f 1)
    echo $pid
    [[ "$pid" =~ "$ppid" ]] && [ "$ppid" ] && return 0 || return 1
}

function hive_start()
{
    metapid=$(check_process HiveMetastore 9083)
    cmd="nohup hive --service metastore >$HIVE_LOG_DIR/metastore.log 2>&1 &"
    cmd=$cmd" sleep4; hdfs dfsadmin -safemode wait >/dev/null 2>&1"
    [ -z "$metapid" ] && eval $cmd || echo "Metastroe服务已启动"
    server2pid=$(check_process HiveServer2 10000)
    cmd="nohup hive --service hiveserver2 >$HIVE_LOG_DIR/hiveServer2.log 2>&1 &"
    [ -z "$server2pid" ] && eval $cmd || echo "HiveServer2服务已启动"
}

function hive_stop()
{
    metapid=$(check_process HiveMetastore 9083)
    [ "$metapid" ] && kill $metapid || echo "Metastore服务未启动"
    server2pid=$(check_process HiveServer2 10000)
    [ "$server2pid" ] && kill $server2pid || echo "HiveServer2服务未启动"
}

case $1 in
"start")
    hive_start
    ;;
"stop")
    hive_stop
    ;;
"restart")
    hive_stop
    sleep 2
    hive_start
    ;;
"status")
    check_process HiveMetastore 9083 >/dev/null && echo "Metastore服务运行正常" || echo "Metastore服务运行异常"
    check_process HiveServer2 10000 >/dev/null && echo "HiveServer2服务运行正常" || echo "HiveServer2服务运行异常"
    ;;
*)
    echo Invalid Args!
    echo 'Usage: '$(basename $0)' start|stop|restart|status'
    ;;
esac

修改日志配置

vim /opt/module/hive/conf/hive-log4j2.properties.template
#修改以下属性的值
property.hive.log.dir = /opt/module/hive/logs

启动脚本

chmod +x $HIVE_HOME/bin/hiveservices.sh
hiveservices.sh start

jps
#如果看到2个RunJar则成功

以官方命令行客户端 beeline 启动HiveJDBC

在哪台机器启动服务就以哪台服务器ip为准

beeline -u jdbc:hive2://hadoop102:10000 -n atguigu

Hive 2.x以上版本,要先启动这两个服务,否则会报错

如果不以脚本方式启动必须先启动 hive服务端元数据服务 否则无法打开hive客户端

hive --service metastore &
hive

7. 更换Tez引擎后,执行任务卡住

vim /opt/module/hadoop-3.1.3/etc/hadoop/capacity-scheduler.xml
<property>
    <name>yarn.scheduler.capacity.maximum-am-resource-percent</name>
    <!-- 更改为1  -->
    <value>1</value>
    <description>
      Maximum percent of resources in the cluster which can be used to run 
      application masters i.e. controls number of concurrent running
      applications.
    </description>
</property>
sudo xsync /opt/module/hadoop-3.1.3/etc/hadoop/capacity-scheduler.xml #同步

8. 遍历删除yarn中所有app

for i in  `yarn application  -list | grep -w  ACCEPTED | awk '{print $1}' | grep application_`; do yarn  application -kill $i; done
hadoop job -list #任务列表
yarn application -list # yarn的app
yarn node -list all # 查看所有节点
hdfs dfsadmin -safemode get # 查看是否是安全模式
hadoop dfsadmin -report  #查看每个节点的具体

02. 环境 - 图1

9. Tez UI

以下操作均在103节点中操作

tez-site.xml

追加

<property>
  <description>Enable Tez to use the Timeline Server for History Logging</description>
  <name>tez.history.logging.service.class</name>
  <value>org.apache.tez.dag.history.logging.ats.ATSHistoryLoggingService</value>
</property>

<property>
  <description>URL for where the Tez UI is hosted</description>
  <name>tez.tez-ui.history-url.base</name>
  <value>http://hadoop103/tez-ui/</value>
</property>

yarn-site.xml

追加

<property>
  <description>Indicate to clients whether Timeline service is enabled or not.
  If enabled, the TimelineClient library used by end-users will post entities
  and events to the Timeline server.</description>
  <name>yarn.timeline-service.enabled</name>
  <value>true</value>
</property>

<property>
  <description>The hostname of the Timeline service web application.</description>
  <name>yarn.timeline-service.hostname</name>
  <value>hadoop103</value>
</property>

<property>
  <description>Enables cross-origin support (CORS) for web services where
  cross-origin web response headers are needed. For example, javascript making
  a web services request to the timeline server.</description>
  <name>yarn.timeline-service.http-cross-origin.enabled</name>
  <value>true</value>
</property>

<property>
  <description>Publish YARN information to Timeline Server</description>
  <name> yarn.resourcemanager.system-metrics-publisher.enabled</name>
  <value>true</value>
</property>

启用tomcat服务器

sudo yum install -y tomcat
sudo groupmems -g tomcat -a atguigu # 将atguigu添加到,重新连接shell
#rpm -qa | grep java- | xargs -n sudo rpm -e --nodeps # 删除tomcat自带的java

下载tez版本对应的war包并解压

https://repository.apache.org/content/repositories/releases/org/apache/tez/tez-ui/

sudo yum -y install unzip
cd /var/lib/tomcat/wabapps #上传到此目录

mkdir tez-ui
uzip tez-ui-0.10.1.war -d tez-ui #解压 到tocat中
rm tez-ui-0.10.1.war

cd tez-ui/config
vim configs.env

#将里面的web地址 全部改成hadoop103
sudo systemctl start tomcat #启动服务

重启yarn,并启动timeline server

stop-yarn.sh
start-yarn.sh
yarn --daemon start timelineserver #启动timeline server服务