目录:
准备工作
Centos安装 mysql
Centos安装Hadoop
Centos安装hive
JDBC远程连接Hive
Hbase和hive整合
Centos安装Hbase
准备工作:
配置/etc/hosts
127.0.0.1 localhost localhost.localdomain192.168.0.120 centos
集中修改/etc/profile
export JAVA_HOME=/usr/lib/jvm/jdk1.7.0_25/export JRE_HOME=/usr/lib/jvm/jdk1.7.0_25/jreexport CLASSPATH=.:$CLASSPATH:$JAVA_HOME/lib:$JRE_HOME/libexport PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/binexport HADOOP_HOME=/usr/local/hadoop-2.2.0export HBASE_HOME=/usr/local/hbaseexport HIVE_HOME=/usr/local/hiveexport PATH=$PATH:$HADOOP_HOME/:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HBASE_HOME/bin:$HIVE_HOME/bin
其他确认信息:
1.同步集群时间:集群之间的时间按差距不要超过30秒,因为如果不同步的话,后面hbase的regionServer的时候会报错的。
2.在hadoop用户下,确认环境变量。hostname。service iptables status等。
Centos安装 mysql
下载地址::http://dev.mysql.com/downloads/
http://mysql.mirror.kangaroot.net/Downloads/MySQL-5.7/
创建目用户及用户组权限
[root@localhost] groupadd mysql
[root@localhost] useradd -r -g mysql mysqlyum安装,如果需要更高版本可以自行下载
yum -y install mysql-server 安装版本较低
设置字符集和远程登录
vim /etc/my.cnf
[client]port=3306socket=/var/lib/mysql/mysql.sockdefault-character-set=utf8[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.sockuser=mysql# Disabling symbolic-links is recommended to prevent assorted security riskssymbolic-links=0default-character-set = utf8character-set-server=utf8collation-server=utf8_general_ciinit_connect='SET collation_connection=utf8_general_ci'init_connect='SET NAMES utf8'[mysqld_safe]log-error=/var/log/mysqld.logpid-file=/var/run/mysqld/mysqld.piddefault-charater-set=utf8
设置开机启动
chkconfig mysqld on
chkconfig --list mysqld
/etc/rc.d/init.d/mysqld start
为root设置密码
mysql -urootselect user,host,password from mysql.user;set password for root@localhost = password('123456');exit;重新登录看有没有生效。
打开远程连接
mysql> use mysql;mysql> desc user;mysql> GRANT ALL PRIVILEGES ON *.* TO root@"%" IDENTIFIED BY "root"; //为root添加远程连接的能力mysql> update user set Password = password('123456') where User='root'; //设置root用户密码mysql> select Host,User,Password from user where User='root';mysql> flush privileges;mysql> exit
若还不能进行远程连接,关闭防火墙
/etc/rc.d/init.d/iptables stop手动安装更高版本,可参考:
http://www.cnblogs.com/zhoulf/archive/2013/01/25/zhoulf.html
http://www.cnblogs.com/xiongpq/p/3384681.html
Centos安装Hadoop
要远程访问Hadoop,首先得关闭防火墙:
查看状态:/etc/init.d/iptables status
关闭:/etc/init.d/iptables stop
永久性关闭:
chkconfig --level 35 iptables off 再重启
选择性开放:重启后生效 或修改/etc/sysconfig/iptables
/sbin/iptables -l INPUT -p tcp -dport 80 -j ACCEPT
/sbin/iptables -l INPUT -p tcp -dport 22 -j ACCEPT
安装Hadoop
cd /usr/local
tar -zxvf hadoop-2.2.0.tar.gz
ln -s hadoop-2.2.0 hadoop
设置ssh无密码登陆
ssh-keygen -t rsa 直接回车cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keyschmod 700 ~/.sshchmod 644 ~/.ssh/authorized_keys
这样就可以了,再者修改/etc/hosts,将ip和hostname对应起来 修改文件: hadoop-env.sh
export HADOOP_IDENT_STRING=$USERexport JAVA_HOME=/usr/lib/jvm/jdk1.8.0_25export HADOOP_HOME=/usr/local/hadoop-2.2.0export PATH=$PATH:/usr/local/hadoop-2.2.0/bin
hdfs-site.xml
dfs.replication 1 dfs.name.dir /usr/local/hadoop-2.2.0/hdfs/name dfs.data.dir /usr/local/hadoop-2.2.0/hdfs/data dfs.permissions false dfs.datanode.max.xcievers 4096
注意:dfs.replication是系统重启之后,新加入文件就会按照这个备份系数来存放文件。要改变现有的文件的备份,可以在命令行下去设置。
记得要创建文件目录:
mkdir /usr/local/hadoop-2.2.0/hdfs/mkdir /usr/local/hadoop-2.2.0/hdfs/datamkdir /usr/local/hadoop-2.2.0/hdfs/name
core-site.xml
fs.defaultFS hdfs://192.168.0.120:8020 hadoop.tmp.dir /usr/local/hadoop-2.2.0/hadoop_tmp
注意:fs.defaultFS指定了HDFS的地址和端口,Hbase就能直接用此地址作为数据文件的根目录,如果不配置,默认的是在/tmp下,系统启动之后酒会没有了
mapred-site.xml
mapreduce.framework.name yarn mapred.system.dir /usr/local/hadoop-2.2.0/mapred/system true mapred.local.dir /usr/local/hadoop-2.2.0/mapred/local true
yarn-site.xml
yarn.nodemanager.aux-services mapreduce_shuffle yarn.nodemanager.aux-services.mapreduce.shuffle.class org.apache.hadoop.mapred.ShuffleHandler
slaves
192.168.0.120
start-all.sh jps
namenode datanode ResourceManager NodeManager SecondaryNameNode 必须有
注意:
如果是集群配置,则将目录拷贝到每一个datanode上。scp -r...
第一次启动记得要在Master hadoop上格式化文件爱你系统:hdfs namenode -format hdfs dfsadmin -report
远程myeclipse和eclipse连接hadoop,参考:
Centos安装hive
cd /usr/local
tar -zxvf hive-0.12.0.tar.gz
ln -s hive-0.12.0 hive 建立软连接
修改文件:
将conf下四个模板文件修改名称 cd /usr/local/hive/conf copy hive-default.xml.template hive-site.xml copy hive-env.sh.template hive-env.sh copy hive-exec-log4j.properties.template hive-exec-log4j.properties copy hive-log4j.properties.template hive-log4j.properties
在官方0.12.0的发布版本中的 hive-default.xml.template 中有 bug,在 2000行:
<value>auth</auth>
修改为:<value>auth</value>
hive-env.sh,在最后加:
export HIVE_CONF_DIR=$HIVE_HOME/confexport HIVE_AUX_JARS_PATH=$HIVE_HOME/lib
hive-site.xml:以下是需要修改的键值对,其余的默认
hive.metastore.local true javax.jdo.option.ConnectionURL jdbc:mysql://192.168.0.120:3306/hive?createDatabaseIfNotExist=true javax.jdo.option.ConnectionDriverName com.mysql.jdbc.Driver javax.jdo.option.ConnectionUserName hive javax.jdo.option.ConnectionPassword 123456 datanucleus.fixedDatastore false hive.exec.scratchdir /tmp/hive-${user.name} Scratch space for Hive jobs hive.metastore.warehouse.dir /user/hive/warehouse location of default database for the warehouse hive.metastore.uris thrift://centos:9083
建立mysql元数据库:
hive需要用到关系型数据库来存储元信息,目前只支持mysql,创建mysql 的是记得设置字符集为latin1,否则后期建表会出问题
默认meta数据库为derby ,为了避免使用默认的Derby数据库(有并发访问和性能的问题),通常还需要配置元数据库为MySQL
mysql -uroot -p123456
mysql> CREATE USER 'hive' IDENTIFIED BY 'mysql';mysql> GRANT ALL PRIVILEGES ON *.* TO 'hive'@'192.168.0.120' WITH GRANT OPTION;或者mysql> GRANT ALL PRIVILEGES ON *.* TO hive@"%" IDENTIFIED BY "123456"; //可以远程连接mysql> update user set Password = password('123456') where User='hive';mysql> flush privileges;建立hive专用的元数据库mysql> create database hive;
出现错误:Specified key was too long:max key is 767 bytes
解决办法:在hive数据库中执行:alter database hive character set latin1.hive元数据库的字符集为latin1.
配置HDFS中的目录和权限:
hive.metastore.warehouse.dir:(HDFS上的)数据目录
hive.exec.scratchdir:(HDFS上的)临时文件目录 hive.metastore.warehouse.dir默认值是/user/hive/warehouse hive.exec.scratchdir默认值是/tmp/hive-${user.name}在hive-site.xml中这些都是默认值,暂时不改。在hdfs上创建相应文件夹
hdfs dfs -mkdir /tmphdfs dfs -mkdir /user/hive/warehousehdfs dfs -chmod g+w /tmphdfs dfs -chmod g+w /user/hive/warehouse
用mysql当元数据库,别忘了找一个mysql的jdbcjar包mysql-connector-java-3.1.12-bin.jar也拷贝到hive-0.12.0/lib下。
在CLI命令行下运行Hive,并进行测试。
出现问题:ermission denied: user=root, access=EXECUTE, inode="/tmp":hadoop:supergroup:drwx-w----
解决办法:hdfs dfs -chmod 777 /tmp
JDBC远程连接Hive
如果需要通过jdbc/odbc的方式来连接hive,需要启动metastore shfift,因此必须配置hive.metastore.uris。
而hive.aux.jars.path是与hbase整合的时候需要用到的jar包,必须加上。
如果不加端口默认启动:hive --service metastore
,则默认监听端口是:9083 ,注意客户端中的端口配置需要和启动监听的端口一致。
服务端启动正常后,客户端就可以执行hive操作了。
hive --service metastore -p <port_num> 也可以自定义监听端口。
debug 模式启动hive服务:
hive --service metastore --hiveconf hive.root.logger=DEBUG,console
hive --service hiveserver --hiveconf hive.root.logger=DEBUG,console
启动服务,这样jdbc:hive就能连上,默认10000端口,后面的部分一定要带上,否则用eclipse连接不上的。
起来后我们在eclipse就可以使用jdbc:hive来连接了。如
Class.forName("org.apache.hadoop.hive.jdbc.HiveDriver"); //注意驱动名称不要写错了,有时是org.apache.hive.jdbc.HiveDriver Connection conn = DriverManager.getConnection("jdbc:hive://centos:10000/default","root","123456");//root 123456远程系统的账号和密码 return conn;
其实使用上和普通的数据库已经很相似了,除了建表的语句有一些差别。
注意:如果是hiveserver2的话,启动是相似的,接口:
public static Connection getConnection() { String driverName = "org.apache.hive.jdbc.HiveDriver"; Connection con = null; try { Class.forName(driverName); con = DriverManager.getConnection( "jdbc:hive2://192.168.0.120:10000/default", "root", "123456"); if (con != null) { System.out.println("connecte succ."); } } catch (Exception e) { e.printStackTrace(); } return con; }
Hbase和hive整合
而hive.aux.jars.path是与hbase整合的时候需要用到的jar包,必须加上。
将hbase的包拷贝到hive/lib下
[root@HADOOP7 hive]# cd /usr/lib/hbase/lib/
[root@HADOOP7 lib]# cp ./hbase-*.jar ./protobuf-*.jar ./zookeeper.*jar ./htrace-core-2.04.jar ../hive/lib
注意,如果hive/lib中存在zookeeper.jar,protobuf.jar,以hbase中的为准,移除到hive的备份目录去
修改hive配置文件
加载hive连接hbase需要的jar 包
在Ambari上直接修改 hive ——>configs——》
内容为:
file:///usr/lib/hive/lib/hive-hbase-handler-0.12.0.2.0.6.1-102.jar,file:///usr/lib/hive/lib/hbase-protocol-0.96.1.2.0.6.1-102-hadoop2.jar,file:///usr/lib/hbase/lib/protobuf-java-2.5.0.jar,file:///usr/lib/hbase/lib/hbase-client-0.96.1.2.0.6.1-102-hadoop2.jar,file:///usr/lib/hbase/lib/hbase-common-0.96.1.2.0.6.1-102-hadoop2.jar,file:///usr/lib/hbase/lib/zookeeper.jar,file:///usr/lib/hbase/lib/guava-12.0.1.jar,file:///usr/lib/hbase/lib/hbase-server-0.96.1.2.0.6.1-102-hadoop2.jar
如果在hive-site.xml中,对应加一项property.
将hbase-site.xml拷贝到hive/conf下
测试:
首先先启动hadoop和hbase,再启动hive元数据库:
hive --service metastore --hiveconf hive.root.logger=DEBUG,console
启动之后会一直卡住不动,放着不管,打开另外一个窗口即可。
如果直接hive会出现以下的错误:
Unable to instantiate org.apache.hadoop.hive。。。。
例子:
drop table hbase_detail3; CREATE TABLE hbase_detail3(key string, values string)STORED BY 'org.apache.hadoop.hive.hbase.HBaseStorageHandler'WITH SERDEPROPERTIES ("hbase.columns.mapping" = "values:val")TBLPROPERTIES("hbase.table.name" = "detail3");insert overwrite table hbase_detail3 select * from detail3;建外部表:CREATE EXTERNAL TABLE hbase_detail3.....后面一样,丹前提是hbase中已经存在表detail3
修改hdfs上hbase文件夹的权限
hadoop fs -chmod -R 755 /user/hbase
Centos安装Hbase
tar zxvf hbase-0.92.0.tar.gz
ln -s hbase-0.92.0 hbase 建立软链接的好处就是,在进行更新时,只需要重新建立软连接即可,而不用修改配置修改文件:(伪分布式)
hbase-env.sh:
export JAVA_HOME=/usr/java/jdk1.8.0_25 export HBASE_LOG_DIR=/usr/local/hbase
hbase-site.xml:
hbase.rootdir hdfs://192.168.0.120:8020/hbase hbase.cluster.distributed true dfs.replication 1 hbase.zookeeper.quorum 192.168.0.120
hbase.zookeeper.quorum一定要是奇数,要不然选举不出HR regionServer配置,真正存放数据信息的地方,伪分布式略。
hbase.rootdir中的地址要跟hadoop2.2.0中配置fs.defaultFS的目录相同,然后加上自己要新建的目录hbase
在命令行下启动hbase
start-hbase.sh
stop-hbase.h
web界面:http://master:60010/
jps:增加了3个进程,HRegionServer,HQnorumPeer,HMaster
注意:如果是由hbase自己管理zookeeper,需要设置export HBASE_MANAGES-ZK=true,如果不是,则需要再下载zookeeper进行配置
测试 hbase
1).登录hbase客户端./bin/hbase shell
2).新建数据表,并插入3条记录
hbase(main):003:0> create 'test', 'cf' 0 row(s) in 1.2200 seconds hbase(main):003:0> list 'table' test 1 row(s) in 0.0550 seconds hbase(main):004:0> put 'test', 'row1', 'cf:a', 'value1' 0 row(s) in 0.0560 seconds hbase(main):005:0> put 'test', 'row2', 'cf:b', 'value2' 0 row(s) in 0.0370 seconds hbase(main):006:0> put 'test', 'row3', 'cf:c', 'value3' 0 row(s) in 0.0450 seconds
3).查看插入的数据
hbase(main):007:0> scan 'test' ROW COLUMN+CELL row1 column=cf:a, timestamp=1288380727188, value=value1 row2 column=cf:b, timestamp=1288380738440, value=value2 row3 column=cf:c, timestamp=1288380747365, value=value3 3 row(s) in 0.0590 seconds
4).读取单条记录
hbase(main):008:0> get 'test', 'row1' COLUMN CELL cf:a timestamp=1288380727188, value=value1 1 row(s) in 0.0400 seconds
5).停用并删除数据表
hbase(main):012:0> disable 'test' 0 row(s) in 1.0930 seconds hbase(main):013:0> drop 'test' 0 row(s) in 0.0770 seconds
6).退出
hbase(main):014:0> exit
Centos安装sqoop
摘抄(Hbase分布式配置修改)
1.修改conf/hbase-env.sh,添加jdk支持
export JAVA_HOME=/usr/local/jdk export HBASE_MANAGES_ZK=true export HBASE_LOG_DIR=/data/logs/hbase
2. 修改conf/hbase-site.xml,
hbase.rootdir hdfs://master:9000/hbase hbase.cluster.distributed true hbase.master hdfs://master:60000 hbase.zookeeper.quorum slave-001,slave-002,slave-003 Comma separated list of servers in the ZooKeeper Quorum. For example, "host1.mydomain.com,host2.mydomain.com,host3.mydomain.com". By default this is set to localhost for local and pseudo-distributed modes of operation. For a fully-distributed setup, this should be set to a full list of ZooKeeper quorum servers. If HBASE_MANAGES_ZK is set in hbase-env.sh this is the list of servers which we will start/stop ZooKeeper on. hbase.zookeeper.property.dataDir /data/work/zookeeper Property from ZooKeeper's config zoo.cfg. The directory where the snapshot is stored. hbase.zookeeper.property.clientport 2181
hbase.rootdir设置hbase在hdfs上的目录,主机名为hdfs的namenode节点所在的主机
hbase.cluster.distributed设置为true,表明是完全分布式的hbase集群 hbase.master设置hbase的master主机名和端口 hbase.zookeeper.quorum设置zookeeper的主机,建议使用单数 3.修改hadoop的目录下的conf/hdfs-site.xmldfs.datanode.max.xcievers 4096
4.修改conf/regionservers
将所有的datanode添加到这个文件,类似与hadoop中slaves文件5.拷贝hbase到所有的节点
其他配置:
hbase-env.sh 如果想使用HBase自带的zookeeper,设置:
export HBASE_MANAGES_ZK=true(启用hbase管理zookeeper的形式)
Centos安装Sqoop
非常简单,五分钟搞定。
[root@centos local]# cp /home/kang/Desktop/temp/sqoop-1.4.5.bin__hadoop-2.0.4-alpha.tar.gz ./
tar -zxvf sqoop-1.4.5.bin__hadoop-2.0.4-alpha.tar.gzln -s sqoop-1.4.5.bin__hadoop-2.0.4-alpha/ sqoopvim /etc/profileexport SQOOP_HOME=/usr/local/sqoopexport PATH=$PATH:$HADOOP_HOME/:$HADOOP_HOME/bin:$HADOOP_HOME/sbin:$HBASE_HOME/bin:$HIVE_HOME/bin:$SQOOP_HOME/binsource /etc/profilemv sqoop-env.template.sh sqoop-env.shvim sqoop-env.sh:export HADOOP_COMMON_HOME=/usr/local/hadoop-2.2.0export HADOOP_MAPRED_HOME=/usr/local/hadoop-2.2.0/share/hadoop/mapreduceexport HBASE_HOME=/usr/local/hbase(不用可以不配置)export HIVE_HOME=/usr/local/hive(不用可以步配置)
sqoop list-databases --connect jdbc:mysql://centos:3306/ --username root --password 123456information_schemahivemysqltest
Centos安装Pig
tar -zxvf pig-0.12.1.tar.gz ln -s pig-0.12.1 pigvim /etc/profileexport PIG_HOME=/usr/local/pigexport PIG_CALSSPATH=$HADOOP_HOME/etc/hadoopexport PATH=.....$SQOOP_HOME/bin:$PIG_HOME/bincd pig/confvim pig.propertiesfs.default.name=hdfs://centos:8020/mapred.job.tracker=centos:8010运行:piggrunt> ls /