最近又机会接触hadoop,顺便分享一下同事的记录
一、主服务器设置
1.创建用户
#useradd hadoop
2.设置密码
#passwd hadoop
3.切换hadoop登录
#su - hadoop
4.解压hadoop压缩包
#tar zxvf hadoop-1.0.3.tar.gz
5.设置目录权限
#chown -R hadoop.hadoop hadoop-1.0.3
6.编辑环境变量
#vim hadoop-1.0.3/conf/hadoop-env.sh
编辑“JAVA_HOME”路径:
export JAVA_HOME=/usr/local/jdk1.7.0_05
增加一行(取消过时警告):
export HADOOP_HOME_WARN_SUPPRESS=1
7.编辑系统环境变量(使用root用户)
#vim /etc/profile
追加如下内容:
export JAVA_HOME=/usr/local/jdk1.7.0_05
export PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export HADOOP_HOME=/home/hadoop/hadoop-1.0.3
export PATH=$PATH:$HADOOP_HOME/bin
8.执行环境设置
#source /etc/profile
9.设置主IP
#vim hadoop-1.0.3/conf/masters
把localhost替换成192.168.1.247
10.设置从IP
#vim hadoop-1.0.3/conf/slaves
把localhost替换成192.168.1.248
11.设置hdfs
#vim hadoop-1.0.3/conf/hdfs-site.xml
增加如下内容:
<configuration>
<property>
<name>dfs.name.dir</name>
<value>/home/hadoop/hadoop-1.0.3/name</value>
</property>
<property>
<name>dfs.data.dir</name>
<value>/home/hadoop/hadoop-1.0.3/data</value>
</property>
<property>
<name>dfs.replication</name>
<value>3</value>
</property>
</configuration>
12.配置任务
#vim hadoop-1.0.3/conf/mapred-site.xml
增加如下内容:
<configuration>
<property>
<name>mapred.job.tracker</name>
<value> 192.168.1.247:9001</value>
</property>
<property>
<name>mapred.local.dir</name>
<value>/home/hadoop/hadoop-1.0.3/var</value>
</property>
</configuration>
13.配置核心文件
#vim hadoop-1.0.3/conf/core-site.xml
<configuration>
<property>
<name> fs.default.name</name>
<value>hdfs:// 192.168.1.247:9000</value>
</property>
<property>
<name>fs.checkpoint.period</name>
<value>3600</value>
</property>
<property>
<name>fs.checkpoint.size</name>
<value>
67108864</value>
</property>
<property>
<name>hadoop.tmp.dir</name>
<value>/home/hadoop/hadoop-1.0.3/tmp</value>
</property>
</configuration>
14.实现主从自动登录(单方向)
创建公钥:
#ssh-keygen -t rsa
自己可以ssh:
#cat .ssh/id_rsa.pub >> .ssh/authorized_keys
设置文件权限:
#chmod 700 .ssh/authorized_keys
测试一下,不需要密码就表示成功
#ssh localhost
#exit
二、从服务器设置
1.创建用户
#useradd hadoop
2.设置密码
#passwd hadoop
3.编辑系统环境变量(使用root用户)
#vim /etc/profile
追加如下内容:
export JAVA_HOME=/usr/local/jdk1.7.0_05
export PATH=$JAVA_HOME/bin:$ANT_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export HADOOP_HOME=/home/hadoop/hadoop-1.0.3
export PATH=$PATH:$HADOOP_HOME/bin
4.执行环境设置
#source /etc/profile
5.解压缩hadoop压缩包
#tar zxvf hadoop-1.0.3.tar.gz
6.设置目录权限
#chown -R hadoop.hadoop hadoop-1.0.3
三、回到主服务器
1.切换hadoop用户
#su - hadoop
2.复制公私到从服务器
3.测试
#ssh 192.168.1.248
配置正确的话是不需要密码就能登录的
4.向从服务器发送配置文件
5.格式化分布式文件系统
#hadoop-1.0.3/bin/hadoop namenode -format
6.启动hadoop服务
#hadoop-1.0.3/bin/start-dfs.sh
#hadoop-1.0.3/bin/start-mapred.sh
7.查看运行情况
web查询界面: http://192.168.1.247:50030
四、安装hive(主服务器)
1.压缩包装包(hadoop用户)
#tar zxvf hive-0.9.0.tar.gz
#mv hive-0.9.0 hadoop-1.0.3
2.配置hive环境变量
#cp hadoop-1.0.3/hive-0.9.0/conf/hive-env.sh.template hadoop-1.0.3/hive-0.9.0/conf/hive-env.sh
#vim hadoop-1.0.3/hive-0.9.0/conf/hive-env.sh
增加一行:
HADOOP_HOME=$HADOOP_HOME
3.配置hive元数据保存到mysql
建立数据数用户,数据库使用latin1字符集:
mysql>CREATE DATABASE hive CHARACTER SET latin1;
mysql>GRANT ALL PRIVILEGES ON hive.* TO 'hive'@'%' IDENTIFIED BY 'hivepasswd';
修改配置文件:
#cp hadoop-1.0.3/hive-0.9.0/conf/hive-default.xml.template hadoop-1.0.3/hive-0.9.0/conf/hive-site.xml
#vim hadoop-1.0.3/hive-0.9.0/conf/hive-site.xml
修改四个地方:
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql:// 192.168.1.247: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>hive</value>
<description>username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hivepasswd</value>
<description>password to use against metastore database</description>
</property>
5.复制mysql连接库包
#cp mysql-connector-java-5.1.11-bin.jar hadoop-1.0.3/hive-0.9.0/lib
4.启动hive
#hadoop-1.0.3/hive-0.9.0/bin/hive
5.去掉log4j过期警告
#cp hadoop-1.0.3/hive-0.9.0/conf/hive-log4j.properties.template hadoop-1.0.3/hive-0.9.0/conf/hive-log4j.properties
#vim hadoop-1.0.3/hive-0.9.0/conf/hive-log4j.properties
找到“log4j.appender.EventCounter”将他的值变更为:“org.apache.hadoop.log.metrics.EventCounter”
五、安装php访问hive数据库插件
1.解压缩thrift包
#tar zxvf thrift-0.8.0.tar.gz
2.不要ruby支持否则会报错
#cd thrift-0.8.0
#./configure --without-ruby
#make && make install
3.后台启动hive
#hadoop-1.0.3/hive-0.9.0/bin/hive --service hiveserver>/dev/null 2>&1 &
4.准备Thrifht库包放在/home/hadoop目录下,这个包可以在网上下载
5.编写php程序
- <?
- //php连接hive thrift依赖包路径
- $GLOBALS['THRIFT_ROOT'] = '/home/hadoop/Thrift/';
- //load the required files for connecting to Hive
- require_once $GLOBALS['THRIFT_ROOT'] . 'packages/hive_service/ThriftHive.php';
- require_once $GLOBALS['THRIFT_ROOT'] . 'transport/TSocket.php';
- require_once $GLOBALS['THRIFT_ROOT'] . 'protocol/TBinaryProtocol.php';
- //Set up the transport/protocol/client
- $transport = new TSocket('192.168.1.247', 10000);
- $protocol = new TBinaryProtocol($transport);
- $client = new ThriftHiveClient($protocol);
- $transport->open();
- //run queries, metadata calls etc
- $client->execute('show tables');
- var_dump($client->fetchAll());
- $transport->close();
- ?>