hive environment construction and simple use

There's a set of cdh versions of hadoop,hive,zookeeper, all matching.

Extraction code: m888
Reconfigure the hadoop runtime environment once, and configure it in detail



<!-- Specifies the number of redundant copies of data -->

		<!-- Close permission checking-->






        <!--Opening up History Service-->


		<!-- Mission History Service -->

The Open History Service in the above configuration is to access mapreduce tasks previously executed after executing the mapreduce program.



    <!--These two configuration nodes must be consistent with the above historical service configuration nodes-->


Distribute to other nodes, then initialize

bin/hdfs namenode -format

After initialization, write two scripts, one is to open all nodes of the cluster, the other is to close all nodes.

echo "---------------Cluster Services Opening------------"
echo "---------------Opening NameNode node------------"
ssh '/opt/modules/hadoop-2.5.0-cdh5.3.6/sbin/ start namenode'

echo "---------------Opening SecondaryNamenode node------------"

ssh '/opt/modules/hadoop-2.5.0-cdh5.3.6/sbin/ start secondarynamenode'

echo "---------------Opening DataNode node------------"

for i in
        ssh $i '/opt/modules/hadoop-2.5.0-cdh5.3.6/sbin/ start datanode'

echo "---------------Opening ResourceManager node------------"

ssh '/opt/modules/hadoop-2.5.0-cdh5.3.6/sbin/ start resourcemanager'

echo "---------------Opening NodeManager node------------"
for i in
         ssh $i '/opt/modules/hadoop-2.5.0-cdh5.3.6/sbin/ start nodemanager'

echo "---------------Opening JobHistoryServer node------------"
ssh '/opt/modules/hadoop-2.5.0-cdh5.3.6/sbin/ start historyserver'
echo "---------------Closing Cluster Services------------"
echo "---------------Shutting down JobHistoryServer node------------"
ssh '/opt/modules/hadoop-2.5.0-cdh5.3.6/sbin/ stop historyserver'

echo "---------------Shutting down ResourceManager node------------"

ssh '/opt/modules/hadoop-2.5.0-cdh5.3.6/sbin/ stop resourcemanager'

echo "---------------Shutting down NodeManager node------------"
for i in
         ssh $i '/opt/modules/hadoop-2.5.0-cdh5.3.6/sbin/ stop nodemanager'

echo "---------------Shutting down NameNode node------------"
ssh '/opt/modules/hadoop-2.5.0-cdh5.3.6/sbin/ stop namenode'

echo "---------------Shutting down SecondaryNamenode node------------"

ssh '/opt/modules/hadoop-2.5.0-cdh5.3.6/sbin/ stop secondarynamenode'

echo "---------------Shutting down DataNode node------------"

for i in
        ssh $i '/opt/modules/hadoop-2.5.0-cdh5.3.6/sbin/ stop datanode'

Modify their executable permissions after writing.

The single quotation mark after ssh in the above command indicates that the command in single quotation mark is executed after ssh goes to other nodes. echo `> kxj.txt is used to input the script result in the reverse quotation mark into kxj.txt.

The JobHistory Server node is the service of the history mentioned above.

It can't run after it's written. It involves a knowledge point, shells and no shells.

There are shell
Broadly speaking, when you log on to a Linux system manually using CRT, you have a shell
When you use ssh to access a system, there is no shell

When there is no shell, the environment variables of that system cannot be loaded, only the user variables of that system can be loaded.

The system variable is the / etc/profile file, and the user variable is in the user root directory.

User variables

Cat/etc/profile > ~/.bashrc Add the contents of system variables to user environment variables

Execute the other two, and after execution, you can test the script.


hive introduction

Characteristics of Hive
1. The operation interface adopts SQL grammar. HQL is very similar to sql.
2. Avoid the tedious process of writing MapReduce. Convert sql statement into MapReduce program and type it into jar package automatically and run it.

Hive Architecture
1. Client client has two kinds.
* Terminal command line
** JDBC -- Not often used, very troublesome (as opposed to the former)
** The bijective relationship between the original data set and field names and data information.
** We are currently stored in Mysql
3. Server server, that is, Hadoop
** While operating Hive, Hadoop's HDFS needs to be turned on, YARN on and MAPRED configured.

mysql, oracle, sqlserver, DB2, SQLite (small database on mobile phone), MDB
Data Warehouse:
Hive, the data warehouse is the client of MapReduce, which means that it is not necessary to install and deploy Hive on every machine.

Look at the figure below. Now let's assume that there is a txt text in this format, so that each field in each row corresponds to the field name of the table. It's troublesome to write mapreduce program, but if you use hive, you can build a table on hive, and then execute a paragraph of sql statement, and the desired results can be output.

After installing hive, a metastore database will be built in mysql database, which stores the mapping of fields between text files and tables.

Installation steps

After unzipping hive, go to conf directory and change the name of configuration file

mv hive-default.xml.template hive-site.xml


export HIVE_CONF_DIR=/opt/modules/hive-0.13.1-cdh5.3.6/conf

Install Mysql

	$ su - root
	# yum -y install mysql mysql-server mysql-devel
	# wget
	# rpm -ivh mysql-community-release-el7-5.noarch.rpm
	# yum -y install mysql-community-server

Start mysql service start mysqld.service

Modify mysql password mysqladmin-uroot password'123456'

Here are two ways to log in to MySQL

Modify some user privileges if other nodes want to access this mysql and give it corresponding privileges.

grant all on *.* to root@'' identified by '123456';

flush privileges; refresh configuration

grant: authorization
all: all rights
* *: Database name. Table name
root: User operating mysql
@'': Host name
Password: 123456

  <description>JDBC connect string for a JDBC metastore</description>

  <description>Driver class name for a JDBC metastore</description>

Pay attention to the lack of a property tag around 2785 lines, and remember to fill in, not under the official website, or you will make a mistake.

Modify Log Profile Name

mysql driver package

Put mysql driver packages in hive's lib directory

Open hadoop cluster before you operate hive, otherwise you can't operate it.

After hive is started, there is a metastore database in mysql. In fact, it's OK not to use MySQL database, but to use anything else. It's OK to configure the corresponding driver in the configuration file.

This directory is the directory that hive generates on hdfs to store data. It can also modify the address in the configuration file.

These two are to turn on some hints

Here's the hint.

Create a table and query the corresponding information. You can see that when you use select * it does not generate mapreduce programs, and the results are between. hive is string type, not varchar.

The latter t means that when double shooting is performed, hive divides fields according to t. If you use commas or something else in your text, hive is not recognized.

create table t1(eid int, name string, sex string) row format delimited fields terminated by '\t';

desc formatted t1; view table details

Cleaning data, such as company data is * separated, when the table is set up by t partition, then need to write a mapreduce program by t partition and then import the data into his

load data local inpath'File path'into table table table table name; if importing data on hdfs, remove local.

If the query statement executed is a conditional query, it is obvious that it has gone through the mapreduce program.

Click on history to see the mapreduce program that was previously executed

It's slow to convert a simple query statement into a MapReduce program every time it's executed. Modifying the following configuration will allow a simple statement not to execute mapreduce.

In this table of mysql's metastore database, the bijective relationship is generated.

Tags: Hadoop hive MySQL ssh

Posted on Mon, 22 Apr 2019 15:18:34 -0700 by Hexen