📣【快捷部署系列】024期信息
编号 | 选型 | 版本 | 操作系统 | 部署形式 | 部署模式 | 复检时间 |
---|---|---|---|---|---|---|
024 | Hive | 3.1.3 | Ubuntu 20.04 | tar包 | 单机 | 2024-05-07 |
一、快捷部署
shell
#!/bin/bash
#################################################################################
# 作者:cxy@toc 2024-05-07
# 功能:快捷部署 Hive
# 说明:
#################################################################################
info(){
echo -e "\033[34m 【`date '+%Y-%m-%d %H:%M:%S'`】\033[0m" "\033[35m$1\033[0m "
}
proj_base_name=cxy
g_inner_ip=$(hostname -I)
info "参考IP地址:"${g_inner_ip}
read -p "请问,您当前服务器的内网IP地址是?(默认为:${g_inner_ip}):" inner_ip
inner_ip="${inner_ip:-${g_inner_ip}}"
echo ${inner_ip}
# 配置/etc/hosts
cat >> /etc/hosts <<EOF
${inner_ip} hadoop001 hadoop001
EOF
# 安装JDK
install_jdk(){
mkdir -p /${proj_base_name}/bao
mkdir -p /${proj_base_name}/jdk
cd /${proj_base_name}/bao
wget https://repo.huaweicloud.com/java/jdk/8u151-b12/jdk-8u151-linux-x64.tar.gz
tar xf /${proj_base_name}/bao/jdk-8u151-linux-x64.tar.gz -C /${proj_base_name}/jdk
cat >> /etc/profile <<EOF
export JAVA_HOME=/${proj_base_name}/jdk/jdk1.8.0_151
export JRE_HOME=\${JAVA_HOME}/jre
export CLASSPATH=.:\${JAVA_HOME}/lib:\${JRE_HOME}/lib
export PATH=.:\${JAVA_HOME}/bin:\$PATH
EOF
source /etc/profile
info "JDK部署完毕 ..."
}
#自定义配置文件
diy_custom_config(){
cd /${proj_base_name}/hadoop/hadoop-3.3.2
#备份要改动的文件
cp etc/hadoop/hadoop-env.sh etc/hadoop/hadoop-env.sh.bak
cp etc/hadoop/core-site.xml etc/hadoop/core-site.xml.bak
cp etc/hadoop/hdfs-site.xml etc/hadoop/hdfs-site.xml.bak
#修改 hadoop-env.sh
sed -i '42aexport JAVA_HOME='/${proj_base_name}/jdk'/jdk1.8.0_151' etc/hadoop/hadoop-env.sh
#修改 core-site.xml
rm -f etc/hadoop/core-site.xml
touch etc/hadoop/core-site.xml
cat >> etc/hadoop/core-site.xml <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
<!-- 数据存储目录 -->
<property>
<name>hadoop.tmp.dir</name>
<value>/${proj_base_name}/hadoop/data/tmp</value>
</property>
<property>
<name>hadoop.http.staticuser.user</name>
<value>root</value>
</property>
<!-- 配置访问hadoop的权限,能够让hive访问到 -->
<property>
<name>hadoop.proxyuser.root.hosts</name>
<value>*</value>
</property>
<property>
<name>hadoop.proxyuser.root.users</name>
<value>*</value>
</property>
</configuration>
EOF
#修改 hdfs-site.xml
rm -f etc/hadoop/hdfs-site.xml
touch etc/hadoop/hdfs-site.xml
cat >> etc/hadoop/hdfs-site.xml <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>dfs.namenode.name.dir</name>
<value>file:/${proj_base_name}/hadoop/data/hdfs/name</value>
</property>
<property>
<name>dfs.datanode.data.dir</name>
<value>file:/${proj_base_name}/hadoop/data/hdfs/data</value>
</property>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
EOF
}
# 部署Hadoop(Standalone)
install_Hadoop(){
mkdir /${proj_base_name}/hadoop
cd /${proj_base_name}/bao
wget https://repo.huaweicloud.com/apache/hadoop/common/hadoop-3.3.2/hadoop-3.3.2.tar.gz --no-check-certificate
tar zxvf hadoop-3.3.2.tar.gz -C /${proj_base_name}/hadoop
cat >> /etc/profile <<EOF
#Hadoop
export HADOOP_HOME=/${proj_base_name}/hadoop/hadoop-3.3.2
export PATH=\$PATH:\$HADOOP_HOME/bin
export PATH=\$PATH:\$HADOOP_HOME/sbin
export HDFS_NAMENODE_USER=root
export HDFS_DATANODE_USER=root
export HDFS_SECONDARYNAMENODE_USER=root
export YARN_RESOURCEMANAGER_USER=root
export YARN_NODEMANAGER_USER=root
EOF
source /etc/profile
hadoop version
diy_custom_config
#配置免密登录
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 0600 ~/.ssh/authorized_keys
# 初始化文件系统
bin/hdfs namenode -format
# 启动服务
sbin/start-dfs.sh
info "安装完成,访问:http://$(curl ifconfig.me/ip):9870/"
}
install_hive(){
mkdir /${proj_base_name}/hive
cd /${proj_base_name}/bao
wget https://repo.huaweicloud.com/apache/hive/hive-3.1.3/apache-hive-3.1.3-bin.tar.gz --no-check-certificate
tar -zxvf apache-hive-3.1.3-bin.tar.gz -C /${proj_base_name}/hive
cat >> /etc/profile <<EOF
#hive
export HIVE_HOME=/cxy/hive/apache-hive-3.1.3-bin
export PATH=$PATH:$HIVE_HOME/bin
EOF
source /etc/profile
cd $HIVE_HOME
$HIVE_HOME/bin/schematool -dbType derby -initSchema
info "hive 部署完毕~"
}
install_jdk
install_Hadoop
install_hive
二、入门体验
shell
$HADOOP_HOME/bin/hadoop fs -mkdir /tmp
$HADOOP_HOME/bin/hadoop fs -mkdir -p /user/hive/warehouse
$HADOOP_HOME/bin/hadoop fs -chmod g+w /tmp
$HADOOP_HOME/bin/hadoop fs -chmod g+w /user/hive/warehouse
vim students
11,HIve
12,Bigdata
13,ZJHW
21,Tom
22,Gerry
23,Simon
24,Jim
91,Jeffrey
92,Leo
93,Even
94,Aaron
95,Addison
hdfs dfs -put students /tmp
source /etc/profile
$HIVE_HOME/bin/beeline -u jdbc:hive2://
create table students(id int comment 'this is student id, is not null', Name string comment 'this is student name') row format delimited fields terminated by ',' stored as textfile;
show databases;
SHOW TABLES;
DESCRIBE students;
load data inpath '/tmp/students' into table students;
select * from students;
!quit
# rm -rf $HIVE_HOME/metastore_db
更多信息可访问官网:https://hive.apache.org
当然,您也可以关注我,关注后续相关博文。
往期精彩内容推荐
云原生:10分钟了解一下Kubernetes架构
云原生:5分钟了解一下Kubernetes是什么
「快速部署」第二期清单
「快速部署」第一期清单