RichardXu's Blog

xu's home

RSS Richard Xu
  • HOME
  • 关于我
  • 图片

Ubuntu下安装HBase

  • 2011/08/30 15:34
  • 作者 iamacnhero

wget http://mirror.bjtu.edu.cn/apache/hbase/stable/hbase-0.90.4.tar.gz

编辑 hbase/conf/hbase-env.sh, 修改JAVA_HOME

启动守护进程: bin/start-hbase.sh

启动hbase hql shell: bin/hbase shell

查看当前Hbase信息: http://localhost:60010

启动Hbase REST服务: bin/hbase rest start

  • Hadoop
  •  , 
  • 0 条评论

Ubuntu下安装Hadoop

  • 2011/08/30 15:34
  • 作者 iamacnhero

参考:http://hadoop.apache.org/common/docs/stable/single_node_setup.html

到 http://hadoop.apache.org/common/releases.html 下面,下载hadoop:

安装JDK
cd /opt
wget http://labs.renren.com/apache-mirror//hadoop/common/stable/hadoop-0.20.203.0rc1.tar.gz
tar -zxvf hadoop-0.20.203.0rc1.tar.gz
ln -s hadoop-0.20.203.0 hadoop
设置环境变量,vi /etc/profile.d/hadoop.sh, 添加:
export HADOOP_INSTALL=/opt/hadoop/
export PATH=$PATH:$HADOOP_INSTALL/bin
export HADOOP_COMMON_HOME=$HADOOP_INSTALL
export HADOOP_CONF_DIR=$HADOOP_INSTALL/conf
运行 source /etc/profile,环境设置生效
设置hadoop JAVA_HOME,编辑 $HADOOP_INSTALL/conf/hadoop-env.sh,设置:export JAVA_HOME=/opt/java
添加hadoop用户并设置密码:useradd -s /bin/bash -d /home/hadoop hadoop; passwd hadoop
编辑 conf/core-site.xml:
<configuration>
        <property>
                <name>fs.default.name</name>
                <value>hdfs://localhost:9000</value>
        </property>
</configuration>

编辑 conf/hdfs-site.xml:
<configuration>
        <property>
                <name>dfs.replication</name>
                <value>1</value>
        </property>
</configuration>

编辑 conf/mapred-site.xml:
<configuration>
        <property>
                <name>mapred.job.tracker</name>
                <value>localhost:9001</value>
        </property>
</configuration>

设置无密码登陆:
ssh hadoop
ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa
cat ~/.ssh/id_rsa.pub >>~/.ssh/authorized_keys
格式化一个分布式文件系统: bin/hadoop namenode -format
在hadoop目录里建立一个logs目录,所有hadoop后台程序都将记录日志在这里:mkdir logs
启动hadoop: bin/start-all.sh
打开网页显示 NameNode 和 JobTracker,默认为:
NameNode:  http://localhost:50070/
JobTracker:  http://localhost:50030/
Copy the input files into the distributed filesystem: bin/hadoop fs -put conf input
Run some of the examples provided: bin/hadoop jar hadoop-examples-*.jar grep input output 'dfs[a-z.]+'
验证hadoop 进程: /opt/java/bin/jps
查看dfs文件系统中已有目录: hadoop dfs -ls


测试 wordcount:
上传文件到dfs文件系统的firstTest目录下: bin/hadoop dfs -copyFromLocal README.txt firstTest
执行wordcount: bin/hadoop jar hadoop-examples-0.20.203.0.jar wordcount firstTest result
查看结果: bin/hadoop dfs -cat result/part-r-00000

  • Hadoop
  •  , 
  • 0 条评论

HBase基本命令

  • 2011/08/30 15:31
  • 作者 iamacnhero

查看表: list
创建表: create '表名称', '列名称1', '列名称2','列名称N'
添加记录: put '表名称', '行名称', '列名称:', '值'
查看记录: get '表名称', '行名称'
查看表中的记录总数: count '表名称'
删除记录: delete '表名', '行名称', '列名称'
删除一张表: 先要屏蔽该表,才能对该表进行删除,第一步 disable '表名称' 第二步 drop '表名称'
查看所有记录: scan "表名称"
查看某个表某个列中所有数据: scan "表名称", ['列名称:']
查看表结构: describe '表名称'

输入help加命令名称,就可以查看该命令帮助,如:help scan

> create 'scores', 'grade', 'course'
> describe 'scores'			# 查看表结构
> put 'scores', 'Tom', 'grade:', '1'		# 加入一行数据, 行名称为Tom列族grade的列名为"", 值为1
> put 'scores', 'Tom', 'course:math', '87'	# 加入一列<math, 87>
> put 'scores', 'Tom', 'course:art', '87'		# 加入一列<art, 87>
> put 'scores', 'Tom', 'course:art', '97'		# 更新<art, 87>为<art, 97>
> get 'scores', 'Tom'				# 查看scores表中Tom的相关数据
> put 'scores', 'Jerry', 'course:math', '100'
> put 'scores', 'Jerry', 'course:art', '80'
> scan 'scores'				# 查看表中所有数据
> scan 'scores', {COLUMNS=>'course'}		# 查看表中所有数据 courses 列族的所有数据
> scan 'scores', {COLUMNS=>'course:art'}		# 查看表中所有数据 courses 列族属性为art的所有数据

  • Hadoop
  •  , 
  • 0 条评论

自定义MySQL提示符

  • 2011/07/27 16:38
  • 作者 iamacnhero

\c     │ A counter that increments for each statement you issue
\D     │ The full current date
\h     │ The server host
\m     │ Minutes of the current time
\n     │ A newline character
\s     │ Seconds of the current time
\t     │ A tab character
\U     │  Your full user_name@host_name account name
\v     │ The server version

放在.my.cnf中的[mysql]块中:
prompt=\v | \c | \m:\\s \U >

分别是: MySQL版本 | 累计数 | 当前时间 | 用户名@主机 >

  • MySQL
  •  , 
  • 0 条评论

Schema Design Tips

  • 2011/07/26 16:01
  • 作者 iamacnhero

* 最佳数据类型 ( 节省磁盘空间 )
* 命名标准

不使用 BIGINT AUTO_INCREMENT,而是使用 INT UNSIGNED INCREMENT
BIGINT 8 bytes
INT 4 bytes
INT UNSIGNED: 0 to 4294967295.

* 使用 ENUM:
1. 值检测
2. 对静态数据很理想
3. 压缩 - 例如: 1 bytes for 'True', 'False'
4. 可读性强

  • MySQL
  •  , 
  • 0 条评论

如果不存在记录,插入记录;如果存在记录,更新记录(if not exists, insert; if exists, update)

  • 2011/07/15 16:38
  • 作者 iamacnhero

有一个很常用的需求,就是上面说的:如果不存在记录,插入记录;如果存在记录,更新记录,这时可以使用MySQL的 INSERT ... ON DUPLICATE KEY UPDATE  技术,示例:
CREATE TABLE click (
	id INT AUTO_INCREMENT,
	keyword VARCHAR(10),
	click INT,
	UNIQUE(keyword),
	PRIMARY KEY(Id)
)ENGINE=MYISAM DEFAULT CHARSET=utf8 COMMENT '关键词点击量';
记录有:
id   keyword   click
1 dxy.com 1
2 gmail.com 1
如果插入一条记录,不知道在不在已有的记录里,就可以使用INSERT ... ON DUPLICATE KEY UPDATE, 如:
INSERT INTO click(keyword, click) VALUES ('dxy.com', 1) ON DUPLICATE KEY UPDATE click=click+1;
INSERT INTO click(keyword, click) VALUES ('baidu.com', 1) ON DUPLICATE KEY UPDATE click=click+1;
现在表结果如下:
1 dxy.com 2
2 gmail.com 1
3 baidu.com 2

参考: http://dev.mysql.com/doc/refman/5.1/en/insert-on-duplicate.html

 

  • MySQL
  •  , 
  • 0 条评论

CSS Foundation

  • 2011/07/10 19:27
  • 作者 iamacnhero

DOCTYPE 声明:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

XML 声明:

<?xml version="1.0" encoding="utf8-8"?>

连接外部CSS文件:link方法:

<link rel="StyleSheet" href="stylesheet.css" type="text/css" media="all" />

或者 @import 方法:

<script type="text/css" media="all">
/* <![CDATA[ */
@import url(stylesheet.css);
/* ]]> /*
</script>

连接favicons:

<link rel="shortcut icon" href="favicon.ico" type="image/x-con"/>

连接JavaScript:

<script type="text/javascript" src="javascriptfile.js"></script>

将所有元素的内外边距设置为0:

* {
    margin: 0;
    padding: 0;
}

 body设置(默认字体和颜色,以及背景):

 

body {
    color: #000000;
    background-color: #ffffff;
    font: Tahoma,Helvetica,SimSun,sans-serif;
}

 

  • CSS
  •  , 
  • 0 条评论

Python监控MySQL Master Slave 状态

  • 2011/05/06 13:34
  • 作者 iamacnhero

 

import os
import sys
import MySQLdb

def getStatus(conn):
    query = " SHOW SLAVE STATUS "
            
    # print query
    cursor = conn.cursor()
    cursor.execute(query)
    result = cursor.fetchall()
    return result[0]

def resolve(conn):
    cursor = conn.cursor()
    query1 = "set global sql_slave_skip_counter=1"
    query2 = "START SLAVE"
    query3 = "SHOW SLAVE STATUS"
    
    cursor.execute(query1)
    cursor.execute(query2)
    cursor.execute(query3)
    conn.commit()
    
if __name__ == '__main__':
    conn = MySQLdb.connect(read_default_file="~/.my.cnf", db="", port=3306, charset="utf8")
    status = getStatus(conn)
    print "Master_Log_File: %s" % status[5]
    print "Read_Master_Log_Pos: %s" % status[6]
    print "Seconds_Behind_Master: %s" % status[-1]

    if status[32] is None:
        resolve(conn)
    else:
        print 'resolved'

 

  • MySQL
  •  , 
  • 0 条评论

关于 information_schema 库

  • 2011/04/07 12:05
  • 作者 iamacnhero

information_schema 没有物理文件,大多数表都是MEMORY表,只有COLUMNS, ROUTINES, TRIGGERS, VIEWS 这4张表是MYISAM表。

 

  • MySQL
  •  , 
  • 0 条评论

MySQL日志文件

  • 2011/03/30 08:53
  • 作者 iamacnhero

1. 错误日志:

# 定位错误日志, 或使用SELECT @@global.log_error;
mysql> SHOW VARIABLES LIKE 'log_error';
mysql> system hostname; # 查看主机名
 
  • MySQL
  • MySQL log , 
  • 0 条评论
  • 〉〉

公告栏

最近文章

  • Ubuntu下安装HBase(355)
  • Ubuntu下安装Hadoop(426)
  • HBase基本命令(345)
  • 自定义MySQL提示符(220)
  • Schema Design Tips(307)
  • 如果不存在记录,插入记录;如果存在记录,更新记录(if not exists, insert; if exists, update)(338)
  • CSS Foundation(262)
  • Python监控MySQL Master Slave 状态(406)

热门文章

  • jQuery解析Json数组(465)
  • Ubuntu下安装Hadoop(426)
  • erlang 入门示例(424)
  • Python监控MySQL Master Slave 状态(406)
  • 音的概念(405)
  • erlang 入门示例(388)
  • Ubuntu下安装HBase(355)
  • 《Angel》 天使之城插曲(349)

最近评论

标签

MySQL log jQuery

分类

  • jQuery(1)
  • Guitar(1)
  • 乐理(1)
  • Erlang(3)
  • Video(2)
  • MySQL(6)
  • CSS(1)
  • Hadoop(3)

存档

  • 2011Y08M(3)Articles
  • 2011Y07M(4)Articles
  • 2011Y05M(1)Articles
  • 2011Y04M(1)Articles
  • 2011Y03M(1)Articles
  • 2011Y02M(2)Articles
  • 2011Y01M(7)Articles
  • 2010Y11M(1)Articles

友情连接

  • 徐明的博客
  • 网站分析在中国
  • lsk
  • 老甘

功能

  • Article RSS
  • Sitemap
  • Valid XHTML
  • RichardXu's Blog
  • Powered by Google App Engine
  • Micolog 0.74
  • .
回到顶部