Friday, July 24, 2015

Installing Hive and Connecting to Hive services


                                  Installing Hive and Connecting to Hive services

Apache Hive™ is a data warehouse system for Hadoop that facilitates easy data summarization, ad-hoc queries, and the analysis of large datasets stored in Hadoop-compatible file systems. Hive provides a mechanism to project structure onto this data and query the data using a SQL-like language called HiveQL. At the same time this language also allows traditional map/reduce programmers to plug in their custom mappers and reducers when it is inconvenient or inefficient to express this logic in HiveQL.

Note : This post assumes you have MapR core packages installed and setup as described in my previous post "Install MapR Cluster"

Below post describes steps to follow to install hive , hive metastore and HS2 (version 12) on the same node.

1) List all version of hive packages available in yum repo.
yum search --showduplicates hive

2) Install hive , hive metastore and HS2  packages.
yum install mapr-hive-0.12.201502021326-1 mapr-hiveserver2-0.12.201502021326-1 mapr-hivemetastore-0.12.201502021326-1  -y

3) Run configure.sh for all hive packages to be listed under roles directory.
/opt/mapr/server/configure.sh -R
ls /opt/mapr/roles/

4) The metadata for Hive tables and partitions are stored in the Hive Metastore . By default, the Hive Metastore stores all Hive metadata in an embedded Apache Derby database in MapR-FS. Derby only allows one connection at a time; since we want multiple concurrent Hive sessions, we will use MySQL for the Hive Metastore. 

Installing MYSQL

i) Install mysql server package from the configured yum repo.
yum install mysql-server

ii)  Start mysql deamon .
service mysqld start

iii) Set password  for root user as "password".
/usr/bin/mysqladmin -u root password password

5) Modify hive-site.xml and add below config to the xml file.

vi /opt/mapr/hive/hive-0.12/conf/hive-site.xml
_________________________________________________________________
<configuration> 
 <property>
    <name>javax.jdo.option.ConnectionURL</name>
    <value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value>
    <description>JDBC connect string for a JDBC metastore</description>
</property>
 
 <property>
    <name>javax.jdo.option.ConnectionDriverName</name>
    <value>com.mysql.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>password</value>
    <description>password to use against metastore database</description>
 </property>
 
 <property>
    <name>hive.metastore.uris</name>
    <value>thrift://localhost:9083</value>
 </property>
_________________________________________________________________

6) Add "export METASTORE_PORT=9083" parameter to hive-env.sh

cp /opt/mapr/hive/hive-0.12/conf/hive-env.sh.template /opt/mapr/hive/hive-0.12/conf/hive-env.sh

vi hive-env.sh   ( Add below parameter )

export METASTORE_PORT=9083

7)  Now we can start the cluster.

service mapr-zookeeper start 
service mapr-zookeeper qstatus      ( verify status of zookeeper )
service mapr-warden start               

maprcli node services -name hivemeta -action restart -nodes `hostname`    ( is needed restart the hivemeta and check hive metastore logs to verify it started correctly )

view /tmp/mapr/hive.log                                   ( logs related to metastore are logged here )

maprcli node services -name hs2 -action restart -nodes `hostname -f`    ( is needed restart the HS2 and check hs2 logs to verify it started correctly in hive.log as well)


Once all the service are up there are 2 ways  to connect using hive cli or HS2 ( beeline ) .

i) HS1 / Hive cli : HiveServer is an optional service that allows a remote client to submit requests to Hive, using a variety of programming languages, and retrieve results. HiveServer cannot handle concurrent requests from more than one client . Below commands lists the commands to be run while working interactively via hive cli .

[root@311-HS2-1 ~]# hive
Logging initialized using configuration in jar:file:/opt/mapr/hive/hive-0.12/lib/hive-common-0.12-mapr-1501.jar!/hive-log4j.properties
hive> show tables;
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/mapr/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/mapr/hive/hive-0.12/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
OK
Time taken: 0.711 seconds
hive> 


ii) HS2 : HiveServer2 (HS2) is a server interface that enables remote clients to execute queries against Hive and retrieve the results. The current implementation, based on Thrift RPC, is an improved version of HiveServer and supports multi-client concurrency and authentication. Below list of commands depict way to connect to HS2 via beeline.


[root@311-HS2-1 ~]# hive --service beeline
Beeline version 0.12-mapr-1501 by Apache Hive
beeline> !connect jdbc:hive2://127.0.0.1:10000/default
scan complete in 3ms
Connecting to jdbc:hive2://127.0.0.1:10000/default
Enter username for jdbc:hive2://127.0.0.1:10000/default: mapr
Enter password for jdbc:hive2://127.0.0.1:10000/default: ****
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/mapr/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/mapr/hive/hive-0.12/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
Connected to: Hive (version 0.12-mapr-1501)
Driver: Hive (version 0.12-mapr-1501)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://127.0.0.1:10000/default> show tables;
[HiveQueryResultSet/next] 0
+-----------+
| tab_name  |
+-----------+
+-----------+
No rows selected (0.638 seconds)
0: jdbc:hive2://127.0.0.1:10000/default>





Monday, July 20, 2015

Installing Oozie and running Sample Job

                          Oozie Installation and Sample job walkthrough.


Apache Oozie™ is a workflow scheduler system to manage Apache Hadoop jobs.  Using Oozie, you can set up workflows that execute MapReduce jobs and coordinators that manage workflows.

This post assumes you have MapR 4.1 cluster installed and configured on the system with warden and ZK services stopped to install and configure Oozie .

1) Now setup correct Ecosystem Repo. Edit /etc/yum.repos.d/maprtech.repo and add ecosystem link as seen below.


[maprtech]
name=MapR Technologies
baseurl=http://package.mapr.com/releases/v4.1.0/redhat/
enabled=1
gpgcheck=0
protect=1

[maprecosystem]
name=MapR Technologies
baseurl=http://package.mapr.com/releases/ecosystem-4.x/redhat
enabled=1
gpgcheck=0
protect=1

2) Install Oozie 


 yum install mapr-oozie

3) For non-secure clusters, add the following two properties to the core-site.xml

( For MR1 cluster /opt/mapr/hadoop/hadoop-0.20.2/conf/core-site.xml )


<configuration>
<property>
  <name>hadoop.proxyuser.mapr.hosts</name>
  <value>*</value>
</property>
<property>
  <name>hadoop.proxyuser.mapr.groups</name>
  <value>*</value>
</property>
</configuration>


4) Start the cluster

service mapr-zookeeper start      

Now,  service mapr-zookeeper qstatus   ( to check status of ZK )

service mapr-warden start            

5) Export the Oozie URL to your environment with the following command:
export OOZIE_URL='http://<Oozie_node>:11000/oozie'
6) Get into below path and check Oozie’s status with the following command .    ( You should see below relevant messages )

cd /opt/mapr/oozie/oozie-4.1.0/bin/


./oozie admin -status
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/mapr/oozie/oozie-4.1.0/lib/slf4j-simple-1.6.6.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/mapr/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.SimpleLoggerFactory]
System mode: NORMAL

Above indicates normal operation

Now Enabling the Oozie Web UI

The Oozie web UI can display your job status, logs, and other related information. The oozie.war file must include the extjs library to enable the web UI. After installing Oozie, perform the following steps to add the ExtJS library to your oozie.war file


1)  Download the extjs library under /root .

cd /root/
wget dev.sencha.com/deploy/ext-2.2.zip

2) If Oozie is running, shut it down:
maprcli node services -name oozie -action stop -nodes <space delimited list of nodes>
3)  Run the oozie-setup.sh script and specify the path to the extjs file.

cd /opt/mapr/oozie/oozie-4.1.0/
./bin/oozie-setup.sh prepare-war -extjs ~/ext-2.2.zip

4) Start Oozie.

maprcli node services -name oozie -action start -nodes <space delimited list of nodes>


Point your browser to http://<oozie_node>:11000/oozie (To review the web UI for Oozie)

Setup and Run Oozie Example .

After verifying the status of Oozie, set up and we can try the example to get familiar with Oozie.

1)  Extract the oozie examples archive oozie-examples.tar.gz

cd /opt/mapr/oozie/oozie-4.1.0/
gunzip oozie-examples.tar.gz ; tar xvf ./oozie-examples.tar -C /opt/mapr/oozie/oozie-4.1.0/

2) Copy the examples to MapR-FS. 

 hadoop fs -put examples /user/root/examples

3) Copy the input data to MapR-FS.

hadoop fs -put examples/input-data maprfs:///user/root/input-data

4) Change permissions on the examples to make them accessible to all users.

hadoop fs -chmod -R 777 /user/root/examples
hadoop fs -chmod -R 777 /user/root/input-data

5) Run an example with the oozie job command as below . 
First copy the Map-reduce example folder to MapR-FS and then run the Map-Reduce job as below.

hadoop fs -put /opt/mapr/oozie/oozie-4.1.0/examples/apps/map-reduce /user/root/examples/apps/

/opt/mapr/oozie/oozie-4.1.0/bin/oozie job -config /opt/mapr/oozie/oozie-4.1.0/examples/apps/map-reduce/job.properties -run


You can verify the JOB was successful in Oozie UI or via below command

/opt/mapr/oozie/oozie-4.1.0/bin/oozie job -info <job id>





Monday, July 6, 2015

How to Install, configure and use Clush

                                        How to Install, configure and use Clush

Clush is an open source tool that allows you to execute commands in parallel across the nodes in the cluster. This blog describes how to install clush, configure and use clush to run commands on multiple nodes in parallel.
This blog assumes you have ssh trust created from node 1 (10.10.70.106) to rest of nodes (node2-node4) .
The clush utility need to be only installed on one node, usually the primary node (10.10.70.106) in the cluster where we will run commands in parallel and gather stats .

Installation :
Installation of clush utility is simple and straightforward, i.e enable EPEL repo ( as per your OS version) and yum install the package as listed in 3 steps below.
1)  wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
2)  rpm -Uvh epel-release-6*.rpm
3)  yum install clustershell -y 

Configuration :
I have a 4 node mapr cluster as listed below. 
[root@node1 ~]# maprcli node list -columns configuredservice
hostname  configuredservice                                ip          
node1     tasktracker,webserver,cldb,fileserver,hoststats  10.10.70.106
node2     tasktracker,cldb,fileserver,hoststats            10.10.70.107
node3     fileserver,tasktracker,hoststats,jobtracker      10.10.70.108
node4     fileserver,tasktracker,hoststats,jobtracker      10.10.70.109
[root@node1 ~]#


Now edit "/etc/clustershell/groups" file to group the nodes which has same services installed.

[root@node1 ~]# cat /etc/clustershell/groups
all: node[1-4]
zk: 10.10.70.106 10.10.70.107 10.10.70.108
jt: 10.10.70.108,10.10.70.109
web: 10.10.70.106
cldb: 10.10.70.106,10.10.70.107
[root@node1 ~]#



Execution/Utilization :

1) To run the command in parallel on all 4 nodes
[root@node1 ~]# clush -a date
node1: Mon Jul  6 14:26:37 PDT 2015
node4: Mon Jul  6 14:26:37 PDT 2015
node3: Mon Jul  6 14:26:37 PDT 2015
node2: Mon Jul  6 14:26:37 PDT 2015
[root@node1 ~]#


2) To get cleaner way output where same output for nodes is grouped.
[root@node1 ~]# clush -ab date
---------------
node[1-4] (4)
---------------
Mon Jul  6 14:28:41 PDT 2015
[root@node1 ~]#

3) To get into interactive cluster shell and get ouput for all nodes you can use "clush -a"


[root@node1 ~]# clush -a
Enter 'quit' to leave this interactive mode
Working with nodes: node[1-4]
clush> date
node1: Mon Jul  6 14:29:42 PDT 2015
node3: Mon Jul  6 14:29:42 PDT 2015
node2: Mon Jul  6 14:29:42 PDT 2015
node4: Mon Jul  6 14:29:42 PDT 2015
clush> uname -a
node2: Linux node2.mycluster.com 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
node4: Linux node4.mycluster.com 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
node1: Linux node1.mycluster.com 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
node3: Linux node3.mycluster.com 2.6.32-431.el6.x86_64 #1 SMP Fri Nov 22 03:15:09 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
clush>

4) To copy file /root/abi to all cluster nodes .

[root@node1 ~]# clush -a -c /root/abi 
[root@node1 ~]#



Verify :
[root@node1 ~]# clush -a ls /root/abi
node1: /root/abi
node4: /root/abi
node3: /root/abi
node2: /root/abi
[root@node1 ~]#

5) To remove file /root/abi to all cluster nodes


[root@node1 ~]# clush -a rm -rf /root/abi
[root@node1 ~]#

Verify :

[root@node1 ~]#clush -a ls /root/abi
node1: ls: cannot access /root/abi: No such file or directory
clush: node1: exited with exit code 2
node3: ls: cannot access /root/abi: No such file or directory
clush: node3: exited with exit code 2
node2: ls: cannot access /root/abi: No such file or directory
clush: node2: exited with exit code 2
node4: ls: cannot access /root/abi: No such file or directory
clush: node4: exited with exit code 2
[root@node1 ~]#



6)  To copy the file to different destination on nodes via clush and then verify.
[root@node1 ~]# clush -a -c /root/abi --dest /tmp
[root@node1 ~]# clush -a ls /tmp/abi
node2: /tmp/abi
node1: /tmp/abi
node4: /tmp/abi
node3: /tmp/abi
[root@node1 ~]#

7) To run specific command on group of nodes described in "/etc/clustershell/groups" file.


[root@node1 ~]# clush -g zk date
10.10.70.106: Mon Jul  6 14:40:24 PDT 2015
10.10.70.108: Mon Jul  6 14:40:24 PDT 2015
10.10.70.107: Mon Jul  6 14:40:24 PDT 2015
[root@node1 ~]# clush -g jt date
10.10.70.108: Mon Jul  6 14:40:33 PDT 2015
10.10.70.109: Mon Jul  6 14:40:33 PDT 2015
[root@node1 ~]#





Creating SSH trust quickly


                                                        Creating SSH trust quickly


For various reasons we would need to create ssh trust between 2 nodes for specific user Id's in this post I will describe a quick way to create trust using "ssh-copy-id". We are using "ssh-copy-id" since this will save significant time and effort to copy keys around to create the trust.

1) Run below command to check lists of public key parameters of all identities currently represented by the agent


ssh-add -L

If you get below output it means agent doesn't have public key for the user.


[root@node1 ~]# ssh-add -L
Could not open a connection to your authentication agent.
[root@node1 ~]#


2) Generate rsa keys for the user via below step and ensure rsa key is generated under ".ssh" folder .

[root@node1 .ssh]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
fc:e6:d0:05:bd:b2:8e:c3:fb:05:31:e9:ec:ef:fa:81 root@node1.mycluster.com
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|           o     |
|          = .    |
|       . o + .   |
|        S = o    |
|         + *     |
|       .. E o    |
|        o* o .   |
|        o+=++    |
+-----------------+
[root@node1 .ssh]# ls
id_rsa  id_rsa.pub  known_hosts
[root@node1 .ssh]#

3) Now add RSA identities to authentication agent and then verify public key parameters for user is currently represented by the agent

[root@node1 .ssh]# ssh-add
Identity added: /root/.ssh/id_rsa (/root/.ssh/id_rsa)
[root@node1 .ssh]# ssh-add -L
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAwJMQfl9uq0saggFvyEkRE9+FfSAcTjhrKm/OCrG3zudOF5S63W0SSTmn6LdjKspIN+4pewVswVCOfAvbAeHojZu//5020kQt+OY76TvtUFU/YXFaKJElqKs9x9UvPCnCkIDDCJaaYC9nwAbuK6gEf78rqVIbN2uCrKyeA8WNg6EFnaFX/uCnxuikRYZCo88008KnAjvI1guF8AjDRfodJBnrYVdKRaxgwY2VVZ8MkEquTAVRnR2emnGcnZuwy4+4mByMzPKu5c+0zqB/vCFAvVL8uqB8RpEzuz91knenNtYB5sYyFdr0QEZXNTrlAOPJ1gYRHoWEn9Gdqd4jqtyyvw== /root/.ssh/id_rsa

NOTE: - If for some specific reason your ssh shell cannot make connection with authentication agent use below command which will start the agent and pid gets assigned to it.
eval "$(ssh-agent)"


[root@node1 .ssh]# eval "$(ssh-agent)"
Agent pid 2334
[root@node1 .ssh]#


4) Use ssh-copy-id to install public key form local node in a remote machine’s authorized_keys. It will ask the password once while the trust is being created.

[root@node1 .ssh]# ssh-copy-id -i root@10.10.70.108
root@10.10.70.108's password: 
Now try logging into the machine, with "ssh 'root@10.10.70.108'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

[root@node1 .ssh]#

5) Verify trust does work.  Below we can see we can directly ssh to 10.10.70.108 node without entering password.

[root@node1 .ssh]# ssh 10.10.70.108
Last login: Mon Jul  6 12:21:25 2015 from node1
[root@node3 ~]#


Friday, July 3, 2015

System Resource utilization

                         System Resource utilization



  To quickly overview of the system you would need a tool to give you some system stats which you can read and interpret which resource is causing the bottleneck, Vmstat is good tool which reports information about processes, memory, swap I/O, block IO, system, and cpu activity in just one line.   There are other tool which report system utilization stats as well but reason i prefer vmstat is because the output of vmstat command is easy to read and can be used effectively for preliminary check to help identify any system bottlenecks but later to gain more insight into suspected issues, a different kind of tool is required i.e a tool capable of more in-depth data collection for analysis.
  In this post we will talk about only Vmstat and what each column represents to effectively determine if issue is due to High CPU utilization/ Disk IO / system Swapping etc. 


Here is an output of vmstat command from my test node:

$ vmstat 1 3            ( Here I get stats every 1 second for 3 times only)



[root@ip-10-128-160-140 ~]# vmstat 1 3
procs -----------memory----------         ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free   buff             cache   si   so     bi    bo     in   cs    us sy id wa st
 0  0      0 23940396 178804 5127788    0    0     0     5    3      6     0 0 100  0  0
 0  0      0 23940396 178804 5127788    0    0     0     0  161  278   0  0 100  0  0
 0  0      0 23940396 178804 5127788    0    0     0    32  374  329  1  1 98  0  0
[root@ip-10-128-160-140 ~]#

  

The fist line lists six different categories for which stats will be displayed. The consecutive lines gives all data you need to interpret if you are running into any system level bottlenecks. All the data collected is in "kb" by default.

  Below info in from "man vmstat" and self explanatory which gives details of every column for which stats are collected.



FIELD DESCRIPTION FOR VM MODE
   Procs
       r: The number of processes waiting for run time.
       b: The number of processes in uninterruptible sleep.

   Memory
       swpd: the amount of virtual memory used.
       free: the amount of idle memory.
       buff: the amount of memory used as buffers.
       cache: the amount of memory used as cache.
       inact: the amount of inactive memory. (-a option)
       active: the amount of active memory. (-a option)

   Swap
       si: Amount of memory swapped in from disk (/s).
       so: Amount of memory swapped to disk (/s).

   IO
       bi: Blocks received from a block device (blocks/s).
       bo: Blocks sent to a block device (blocks/s).

   System
       in: The number of interrupts per second, including the clock.
       cs: The number of context switches per second.

   CPU
       These are percentages of total CPU time.
       us: Time spent running non-kernel code. (user time, including nice time)
       sy: Time spent running kernel code. (system time)
       id: Time spent idle. Prior to Linux 2.5.41, this includes IO-wait time.
       wa: Time spent waiting for IO. Prior to Linux 2.5.41, included in idle.
       st: Time stolen from a virtual machine. Prior to Linux 2.6.11, unknown.


  With systems who have larger memory its worth running the command with "-S" option and specifying "M" which would capture stats in "MB" which is more human readable.



[root@ip-10-128-160-140 ~]# vmstat -S M 1 3
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
 r  b   swpd   free   buff  cache   si   so       bi    bo   in   cs      us sy id wa st
 0  0      0  23386    174   5000    0    0      0     5      3    6       0  0 100  0  0
 0  0      0  23386    174   5000    0    0      0     0     262  299  0  0 100  0  0
 0  0      0  23386    174   5000    0    0      0     0     140  256  0  0 100  0  0
[root@ip-10-128-160-140 ~]#

  
With above info a system administrators can identify system bottlenecks or atleast get a data point on where he needs to dig deeper to get to the RC of the performance problem they are troubleshooting. I plan to write another post with examples where i will manually stimulate system bottlenecks and run vmstat in parallel to get data points which wold point to the problem .