Archive for the ‘Database’ Category.

Apache Hadoop 生态圈成员介绍

  • Common: 一组分布文件系统和通用 I/O 组件与接口(序列化、Java RPC 和持久化数据结构)。
  • Avro: 一种支持高效、跨语言的 RPC 以及永久存储数据的序列化系统。
  • MapReduce: 分布式数据处理模型和执行环境、运行于大型商用机集群。
  • HDFS: 分布式文件系统,运行于大型商用机集群。
  • Pig: 一种数据流语言和运行环境,用以检索非常大的数据集。Pig 运行在 MapReduce 和 HDFS 的集群上。
  • Hive: 一个分布式、按列存储的数据仓库。 Hive 管理 HDFS 中存储的数据,并提供基于 SQL 的查询语言(由运行时引擎翻译成 MapReduce作业)用以查询数据。
  • HBase: 一个分布式、按列存储的数据仓库。HBase 使用 HDFS 作为底层存储,同时支持 MapReduce 的批量式计算和点查询(随机读取)。
  • ZooKeeper: 一个分布式、高可用的协调服务。ZooKeeper 提供分布式锁之类的基本服务用于构建分布式应用。
  • Sqoop: 在数据库和 HDFS 之间高效传输数据的工具。

关系型数据库与 MapReduce 的比较

  传统关系型数据库 MapReduce
数据大小 GB PB
访问 交互式和批处理 批处理
更新 多次读写 一次写入多次读取
结构 静态模式 动态模式
完整性
横向扩展 非线性 线性

HBase Shell Help

HBase Shell, version 0.90.4, r1150278, Sun Jul 24 15:53:29 PDT 2011
Type 'help "COMMAND"', (e.g. 'help "get"' -- the quotes are necessary) for help on a specific command.
Commands are grouped. Type 'help "COMMAND_GROUP"', (e.g. 'help "general"') for help on a command group.

COMMAND GROUPS:
  Group name: general
  Commands: status, version

  Group name: ddl
  Commands: alter, create, describe, disable, drop, enable, exists, is_disabled, is_enabled, list

  Group name: dml
  Commands: count, delete, deleteall, get, get_counter, incr, put, scan, truncate

  Group name: tools
  Commands: assign, balance_switch, balancer, close_region, compact, flush, major_compact, move, split, unassign, zk_dump

  Group name: replication
  Commands: add_peer, disable_peer, enable_peer, remove_peer, start_replication, stop_replication

SHELL USAGE:
Quote all names in HBase Shell such as table and column names.  Commas delimit
command parameters.  Type <RETURN> after entering a command to run it.
Dictionaries of configuration used in the creation and alteration of tables are
Ruby Hashes. They look like this:

  {'key1' => 'value1', 'key2' => 'value2', ...}

and are opened and closed with curley-braces.  Key/values are delimited by the
'=>' character combination.  Usually keys are predefined constants such as
NAME, VERSIONS, COMPRESSION, etc.  Constants do not need to be quoted.  Type
'Object.constants' to see a (messy) list of all constants in the environment.

If you are using binary keys or values and need to enter them in the shell, use
double-quote'd hexadecimal representation. For example:

  hbase> get 't1', "key\x03\x3f\xcd"
  hbase> get 't1', "key\003\023\011"
  hbase> put 't1', "test\xef\xff", 'f1:', "\x01\x33\x40"

The HBase shell is the (J)Ruby IRB with the above HBase-specific commands added.
For more on the HBase Shell, see http://hbase.apache.org/docs/current/book.html

HBase 简介

HBase 是 Hadoop 数据库. 想象它是一个超快的可靠的大型数据仓库.

何时使用 HBase

当需要随机、实时地读写访问大型数据的时候,可以使用 HBase. 该项目的目标就是托管超大型的表——数十亿行*数百万列 ——位于硬件集群之上。HBase 是开源的、分布式的、版本化的、面向列的仓库。它是山寨谷歌的 BigTable(一个分布式的结构化存储系统),创始人为Chang et al.就像 BigTable 依靠 Google File System 提供分布式存储,HBase 基于 Hadoop 和 HDFS 提供了类似于 BigTable 的功能。

FreeBSD Ports 方式安装 MySQL 注意事项

需要注意的几点:

make安装时候的参数
WITH_XCHARSET=all 不加这个的话会不支持GBK编码
BUILD_OPTIMIZED=yes
BUILD_STATIC=yes 这2项都是起到优化作用,都加上的好
mysql默认读取/etc目录下面的my.cnf,但是安装过程不会自动在这目录下创建本文件,默认这个文件在/usr/local/share/mysql目录下面,有3个版本:
my-large.cnf 一般高配置服务器或者mysql专用服务器用这个配置文件
my-medium.cnf 服务器配置并跑有其它应用时用这个配置文件
my-small.cnf 服务器资源紧张的就用这个好了
根据你的机器配置选择一个cp /usr/local/share//my-large.cnf /etc/my.cnf
安装过程并不会自动创建默认的数据库,需要手工创建
/usr/local/bin/mysql_install_db –user=mysql
并且需要更改数据库目录的权限,不然会启动不起来
chown -R mysql:mysql /var/db/mysql
启动mysql,好像第一次用脚本启动的话要使用
/usr/local/etc/rc.d/mysql-server onestart
使用/usr/local/etc/rc.d/mysql-server start不行
修改root密码,比如我们要修改成123456
mysqladmin -uroot -p password 123456
会提示你再次输入一次密码Enter password:,再输入一次123456即可(Fising注:这里应该是输入原来的老密码,而非确认新密码)
修改数据文件的默认目录
vi /etc/my.cnf中加入datadir=数据库的目录,记得把原/var/db/mysql中的文件都复制过去,再执行
chown -R mysql:mysql 数据库的目录
最后一点千万别忘记,要不然mysql又该启动不起来了
修改/usr/local/etc/rc.d/mysql-server文件中的mysql_dbdir=”/var/db/mysql”为你的新目录
或者在/etc/rc.conf中加入mysql_dbdir=”新目录”
最后在/etc/rc.conf加入mysql_enable=”yes”让mysql开机自启动

原文:http://www.viyin.net/2010/04/freebsd-ports-mysql.html

Redis 简介

Redis 是一个开源的高级键值数据库。它经常被作为数据结构服务器提及,因为它可以存储 字符串哈希列表集合 和 有序集合.

你可以对这些类型进行原子操作,例如追加字符串增加哈希中的值压入列表计算交集并集差异;或者获取有序列表中排行最高的成员

为了达到其卓越的性能,Redis 使用内存数据集。根据不同的使用条件,你可以每隔一段时间就把数据集dump到磁盘,或者将命令追加到log文件 以便持久化数据。

Redis 也支持主从复制、具有非常快速无阻塞的第一次同步、当网路切分(? 原文为 net split )时会自动重新连接等等。

其他功能例如简单的检查和配置机制发布/订阅和配置设置使得Redis像cache那样工作。

你可以从大多数编程语言中使用Redis.

Redis 由 ANSI C 写成,可以运行于大多数POSIX系统例如Linux, *BSD, OS X 和 Solaris 而无需任何外部依赖。Windows 构建没有官方的支持,虽然有 一些 选项

本文翻译Redis自官方网站:http://redis.io/topics/introduction

后台运行 MongoDB 服务进程 mongod

在 UNIX/Linux 系统中,通过 ./bin/mongod 启动 MongoDB 服务时,屏幕会输出很多运行信息,并不会回到 shell 提示符。除非 Ctrl + C,但是这样会停止 MongoDB 服务进程。

那么如何使 MongoDB 后台运行呢?可以使用下面的办法:

# 方法1:(推荐)
# --fork 选项将会通知 mongod 在后台运行
/path/to/MongoDB_Dir/bin/mongod --logpath /path/to/file.log --logappend --fork

# 方法2:
# 将输出重定向到 file.log 文件
# & 将该进程置于后台运行
/path/to/MongoDB_Dir/bin/mongod >> /path/to/file.log &

# 还可以这样运行(不记录日志)
# 因为所有重定向到位桶文件 /dev/null 的信息都会被丢弃
/path/to/MongoDB_Dir/bin/mongod >> /dev/null &

安装 PHP 的 MongoDB 数据库驱动 / 扩展

cd /tmp/download
wget http://pecl.php.net/get/mongo-1.2.3.tgz

tar xzvf mongo-1.2.3.tgz
cd mongo-1.2.3

/usr/local/php/bin/phpize
./configure --with-php-config=/usr/local/php/bin/php-config
make install

在 php.ini 末尾添加:

[MongoDB]
extension=mongo.so

重启PHP.

打开浏览器,如果可以在phpinfo页面看到这么一段,就说明安装成功了:

php-mongodb-extension

php-mongodb-extension

see also: http://www.php.net/manual/zh/book.mongo.php

MongoDB shell commands

db.help()                    help on db methods
db.mycoll.help()             help on collection methods
rs.help()                    help on replica set methods
help connect                 connecting to a db help
help admin                   administrative help
help misc                    misc things to know
help mr                      mapreduce help

show dbs                     show database names
show collections             show collections in current database
show users                   show users in current database
show profile                 show most recent system.profile entries with time >= 1ms
use <db_name>                set current database
db.foo.find()                list objects in collection foo
db.foo.find( { a : 1 } )     list objects in foo where a == 1
it                           result of the last line evaluated; use to further iterate
DBQuery.shellBatchSize = x   set default number of items to display on shell
exit                         quit the mongo shell

在 Linux 平台安装 MongoDB 1.8.2

1. 下载 MongoDB 二进制安装包

cd /tmp/downloads
wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-1.8.2.tgz

2. 解压 MongoDB 并移动到目标位置

tar xzvf mongodb-linux-i686-1.8.2.tgz
mkdir -p /usr/local/MongoDB
cd mongodb-linux-i686-1.8.2
cp -R ./* /usr/local/MongoDB

如此,就安装好了。
3. 创建数据存放目录

mkdir -p /data/db
chown `id -u` /data/db

4. 启动 MongoDB 服务进程

./usr/local/MongoDB/bin/mongod

5. 测试安装

新开启一个终端,打开 MongoDB 的交互式 shell,默认情况下,该 shell 连接到本地服务器localhost

/usr/local/MongoDB/bin/mongo

如果能看到以下内容:

MongoDB shell version: 1.8.2
connecting to: test
>

就说明我们连接成功了。下面可以来测试一下:

> db.foo.save( { a : 1 } )
> db.foo.find()
{ "_id" : ObjectId("4e4dbf7666b2bac2ef36b89e"), "a" : 1 }
>

说明测试正常。安装过程就完成了。