以下操作全在ubuntu下完成
先查看下是否安装了tcl,因为在make test的时候需要它,否则会出现“You need ‘tclsh8.5′ in order to run the Redis test”
ldconfig -p | grep tcl
如果没有安装,那么就先安装tcl吧
sudo apt-get install tcl8.5
做好准备工作了,现在就可以开始redis的安装
wget http://redis.googlecode.com/files/redis-2.4.5.tar.gz
tar xzf redis-2.4.5.tar.gz
cd redis-2.4.5
make
make test
下面开始试用下redis
启动redis服务:src/redis-server
插入一条数据到redis:echo “test” | src/redis-cli -x set testkey
从redis取出一条数据:src/redis-cli get testkey
检查表
CHECK TABLE tbl_name [, tbl_name] [option]
option = {QUICK | FAST | MEDIUM | EXTENDED | CHANGED}
检查一个或多个表是否有错误,CHECK TABLE对MyISAM和InnoDB表有作用。
mysql> check table a;
+——–+——-+———-+———-+
| Table | Op | Msg_type | Msg_text |
+——–+——-+———-+———-+
| test.a | check | status | OK |
+——–+——-+———-+———-+
1 row in set (0.00 sec)
CHECK TABLE也可以检查视图是否有错误。
首先为表a创建一个视图v_a
mysql> create view v_a as select * from a;
Query OK, 0 rows affected (0.02 sec)
然后CHECK一下v_a视图
mysql> check table v_a;
+————-+——-+———-+———-+
| Table | Op | Msg_type | Msg_text |
+————-+——-+———-+———-+
| test.v_a | check | status | OK |
+————-+——-+———-+———-+
1 row in set (0.00 sec)
现在删掉视图v_a依赖的表a
mysql> drop table a;
Query OK, 0 rows affected (0.01 sec)
再CHECK一下刚才的视图,发现报错了
mysql> check table v_a\G;
*************************** 1. row ***************************
Table: test.v_a
Op: check
Msg_type: Error
Msg_text: Table ‘test.a’ doesn’t exist
*************************** 2. row ***************************
Table: test.v_a
Op: check
Msg_type: Error
Msg_text: View ‘test.v_a’ references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
*************************** 3. row ***************************
Table: test.v_a
Op: check
Msg_type: error
Msg_text: Corrupt
3 rows in set (0.00 sec)
ERROR:
No query specified
注意:无论是ANALYZE还是OPTIMIZE在执行期间将对表进行锁定,因此请注意这些操作要在数据库不繁忙的时候
分析表
ANALYZE [LOCAL | NO_WRITE_TO_BINLOG] TABLE tbl_name [, tbl_name]
本语句用来分析表的状态,在分析期间,使用一个读取锁对表进行锁定。该语句仅对MyISAM, BDB和InnoDB表有作用。对于MyISAM表,本语句相当于使用myisamchk -a的效果。
mysql> analyze table a;
+——–+———+———-+—————————–+
| Table | Op | Msg_type | Msg_text |
+——–+———+———-+—————————–+
| test.a | analyze | status | OK |
+——–+———+———-+—————————–+
1 row in set (0.00 sec)
优化表
OPTIMIZE [LOCAL | NO_WRITE_TO_BINLOG] TABLE tbl_name [, tbl_name]
如果您已经删除了表的一大部分,或者如果您已经对含有可变长度行的表(含有VARCHAR, BLOB或TEXT列的表)进行了很多更改,则应使用OPTIMIZE TABLE。被删除的记录被保持在链接清单中,后续的INSERT操作会重新使用旧的记录位置。您可以使用OPTIMIZE TABLE来重新利用未使用的空间,并整理数据文件的碎片。
在多数的设置中,您根本不需要运行OPTIMIZE TABLE。即使您对可变长度的行进行了大量的更新,您也不需要经常运行,每周一次或每月一次即可,只对特定的表运行。
OPTIMIZE TABLE只对MyISAM, BDB和InnoDB表起作用。
对于MyISAM表,OPTIMIZE TABLE按如下方式操作:
如果表已经删除或分解了行,则修复表。
如果未对索引页进行分类,则进行分类。
如果表的统计数据没有更新(并且通过对索引进行分类不能实现修复),则进行更新。
mysql> OPTIMIZE table a;
+——–+———-+———-+—————————–+
| Table | Op | Msg_type | Msg_text |
+——–+———-+———-+—————————–+
| test.a | optimize | status | OK |
+——–+———-+———-+—————————–+
1 row in set (0.00 sec)
注意:无论是ANALYZE还是OPTIMIZE在执行期间将对表进行锁定,因此请注意这些操作要在数据库不繁忙的时候
1:下载http://fastdl.mongodb.org/win32/mongodb-win32-i386-1.6.2.zip
2:将zip文件解压到一个目录,在这里我把它解压到E盘(E:\mongodb)
3:把mongodb的bin目录加到,windows系统的path(不是必须的)
4:打开cmd,输入mongo,看到了版本信息了,如果看到了,那么诸位恭喜你安装成功了
[code]
MongoDB shell version: 1.6.2
connecting to: test
Mon Sep 06 07:20:51 Error: couldn't connect to server 127.0.0.1} (anon):1137
exception: connect failed
[/code]
5:通过4的提示,我们可以看到报错信息,不急那是因为没有可以连接的服务。现在我们开始启动mongod服务,在cmd下输入
[java]
mongod.exe –dbpath=c:\db
[/java]
看到下面的内容了没,这就是服务启动后的提示,关于mongd的参数具体的还请看帮助
[code]
Mon Sep 06 07:26:35 MongoDB starting : pid=1944 port=27017 dbpath=c:\db 32-bit
** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data
** see http://blog.mongodb.org/post/137788967/32-bit-limitations
Mon Sep 06 07:26:35 db version v1.6.2, pdfile version 4.5
Mon Sep 06 07:26:35 git version: aef371ecf5d2a824f16ccdc3b745f3702165602f
Mon Sep 06 07:26:35 sys info: windows (5, 1, 2600, 2, 'Service Pack 3') BOOST_LI
B_VERSION=1_35
Mon Sep 06 07:26:35 [initandlisten] waiting for connections on port 27017
Mon Sep 06 07:26:35 [websvr] web admin interface listening on port 28017
[/code]
6:再新打开CMD输入:mongo,如果出现下面提示,那么您就可以开始mongo之旅了
[code]
MongoDB shell version: 1.6.2
connecting to: test
>
[/code]
今天的windows安装mongodb就到这里,具体使用及其他请听下回分解
搜索三大要素:数据来源、预处理、查询。
在Sphinx+MySQL的架构中,MySQL主要提供了数据来源和查询接口,真正进行全文索引建立和查询的是Sphinx。
MySQL里面存放真正的数据;Sphinx从MySQL中获取数据建立全文索引;应用程序使用相应的api与Sphinx交互以获得真正的数据(此处的api包含SQL接口、php接口,以及其他一些编程语言能够调用的接口)。
假设test库内有表test,结构如下:
CREATE TABLE `test` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`content` varchar(20000) DEFAULT NULL,
`gmt_create` datetime DEFAULT NULL,
`v` char(100) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
我们需要在content字段上面做全文索引。
根据以上信息配置Sphinx是一件相对容易的事情。在只涉及到单数据来源(MySQL)的情况下,我们只需要关注下面这几个参数:
source src1
{
# data source type. mandatory, no default value
# known types are mysql, pgsql, mssql, xmlpipe, xmlpipe2, odbc
type = mysql
#####################################################################
## SQL settings (for ‘mysql’ and ‘pgsql’ types)
#####################################################################
# some straightforward parameters for SQL source types
sql_host = 192.168.*.*
sql_user = realzyy
sql_pass = realzyy
sql_db = test
sql_port = 3306 # optional, default is 3306
# pre-query, executed before the main fetch query
# multi-value, optional, default is empty list of queries
#
sql_query_pre = SET NAMES utf8
# sql_query_pre = SET SESSION query_cache_type=OFF
# range query setup, query that must return min and max ID values
# optional, default is empty
#
# sql_query will need to reference $start and $end boundaries
# if using ranged query:
#
sql_query = \
SELECT id, gmt_create, content,v \
FROM test \
WHERE id>=$start AND id<=$end
sql_query_range = SELECT MIN(id),MAX(id) FROM test
# range query step
# optional, default is 1024
#
sql_range_step = 128
# UNIX timestamp attribute declaration
# multi-value (an arbitrary number of attributes is allowed), optional
# similar to integer, but can also be used in date functions
#
# sql_attr_timestamp = posted_ts
# sql_attr_timestamp = last_edited_ts
sql_attr_timestamp = gmt_create
# string ordinal attribute declaration
# multi-value (an arbitrary number of attributes is allowed), optional
# sorts strings (bytewise), and stores their indexes in the sorted list
# sorting by this attr is equivalent to sorting by the original strings
#
sql_attr_str2ordinal = v
# ranged query throttling, in milliseconds
# optional, default is 0 which means no delay
# enforces given delay before each query step
sql_ranged_throttle = 0
# document info query, ONLY for CLI search (ie. testing and debugging)
# optional, default is empty
# must contain $id macro and must fetch the document by that id
sql_query_info = SELECT * FROM test WHERE id=$id
}
因为这个表的字符集采用了utf8,所以还需要修改一下:
index test1
{
source = src1
# document source(s) to index
# multi-value, mandatory
# document IDs must be globally unique across all sources
source = src1
# index files path and file name, without extension
# mandatory, path must be writable, extensions will be auto-appended
path = /u01/sphinx/var/data/index_for_test
# document attribute values (docinfo) storage mode
# optional, default is ‘extern’
# known values are ‘none’, ‘extern’ and ‘inline’
docinfo = extern
# memory locking for cached data (.spa and .spi), to prevent swapping
# optional, default is 0 (do not mlock)
# requires searchd to be run from root
mlock = 0
# a list of morphology preprocessors to apply
# optional, default is empty
#
# builtin preprocessors are ‘none’, ‘stem_en’, ‘stem_ru’, ‘stem_enru’,
# ‘soundex’, and ‘metaphone’; additional preprocessors available from
# libstemmer are ‘libstemmer_XXX’, where XXX is algorithm code
# (see libstemmer_c/libstemmer/modules.txt)
#
# morphology = stem_en, stem_ru, soundex
# morphology = libstemmer_german
# morphology = libstemmer_sv
morphology = none
# minimum indexed word length
# default is 1 (index everything)
min_word_len = 1
# charset encoding type
# optional, default is ‘sbcs’
# known types are ‘sbcs’ (Single Byte CharSet) and ‘utf-8′
charset_type = utf-8
# charset definition and case folding rules “table”
# optional, default value depends on charset_type
#
# defaults are configured to include English and Russian characters only
# you need to change the table to include additional ones
# this behavior MAY change in future versions
#
# ‘sbcs’ default value is
# charset_table = 0..9, A..Z->a..z, _, a..z, U+A8->U+B8, U+B8, U+C0..U+DF->U+E0..U+FF, U+E0..U+FF
#
# ‘utf-8′ default value is
charset_table = 0..9, A..Z->a..z, _, a..z, U+410..U+42F->U+430..U+44F, U+430..U+44F
}
执行一下indexer创建全文索引;再执行searchd打开Sphinx的监听端口以便接收请求;最后可以用search去检测一下战果~
#indexer –all
#searchd
#search *****
查看mysql安装目录:rpm -ql mysql
找出所有的mysql安装版本包:rpm -qa | grep mysql
全部找出mysql的所有的文件:find / -name mysql
一个个全部删掉:rm -rf path
就彻底删除掉mysql
由于业务需求,需要在现有mysql中安装sphinx的存储引擎,要保证现有mysql运行的情况下完成。mysql也的确支持存储引擎的在线热插拔,下面介绍安装步骤:
1、查看现有mysql的运行版本
# mysqladmin -u user -p pwd version
…
Server version 5.1.47-log
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /data/mysql_db/mysql.sock
Uptime: 15 days 2 hours 17 min 40 sec
2、下载mysql和sphinx
mysql:wget ftp://ftp.ntu.edu.tw/pub/MySQL/Downloads/MySQL-5.1/mysql-5.1.47.tar.gz
sphinx:wget http://sphinxsearch.com/downloads/sphinx-0.9.9.tar.gz
注意:mysql源码包的版本一定要与当前运行的mysql版本一致!
解压
# tar -xzvf mysql-5.1.47.tar.gz
# tar -xzvf sphinx-0.9.9.tar.gz
3、将sphinx-0.9.9下的mysqlse目录复制到mysql目录中
#cp -r sphinx-0.9.9/mysqlse/ mysql-5.1.47/storage/sphinx
build
# cd mysql-5.1.47
# sh BUILD/autorun.sh
#./configure
# make
注意:这里到make这步即可,不用install
4、将make好的文件复制到当前运行的mysql目录中
# cp storage/sphinx/.libs/ha_sphinx.* /usr/local/mysql/lib/mysql/plugin
更改所有者
# chown mysql.mysql /usr/local/mysql/lib/mysql/plugin/*
注:我当前运行的mysql目录在/usr/local/mysql
5、登陆mysql加载sphinx引擎模块
#mysql -u root -p -h localhost
# mysql> INSTALL PLUGIN sphinx SONAME ‘ha_sphinx.so’;
检查引擎模块是否正常加载
mysql> show engines;
+————+———+—————————————————————-+————–+——+————+
| Engine | Support | Comment | Transactions | XA | Savepoints |
+————+———+—————————————————————-+————–+——+————+
| ndbcluster | NO | Clustered, fault-tolerant tables | NULL | NULL | NULL |
| MRG_MYISAM | YES | Collection of identical MyISAM tables | NO | NO | NO |
| BLACKHOLE | YES | /dev/null storage engine (anything you write to it disappears) | NO | NO | NO |
| InnoDB | YES | Supports transactions, row-level locking, and foreign keys | YES | YES | YES |
| SPHINX | YES | Sphinx storage engine 0.9.9 | NO | NO | NO |
| MyISAM | DEFAULT | Default engine as of MySQL 3.23 with great performance | NO | NO | NO |
| CSV | YES | CSV storage engine | NO | NO | NO |
| MEMORY | YES | Hash based, stored in memory, useful for temporary tables | NO | NO | NO |
+————+———+—————————————————————-+————–+——+————+
安装完成!如果要卸载存储模块使用
mysql> UNINSTALL PLUGIN sphinx;
在./configure后,make时出现以下错误:
make: *** No targets specified and no makefile found. stop.
在网上找到相关资料,确认是./configure出了问题,于是回头查看,果然发现问题:
最后几行出了错,完整错误信息如下:
checking for tgetent in -lncurses… no
checking for tgetent in -lcurses… no
checking for tgetent in -ltermcap… no
checking for tgetent in -ltinfo… no
checking for termcap functions library… configure: error: No curses/termcap library found
原因:
缺少ncurses安装包
解决办法:
下载安装相应软件包
一、如果你的系统是RedHat系列:
yum list|grep ncurses
yum -y install ncurses-devel
yum install ncurses-devel
二、如果你的系统是Ubuntu或Debian:
apt-cache search ncurses
apt-get install libncurses5-dev
待安装completed!之后,再./configure,顺利通过,然后make && make install,成功安装,一切OK!~~~
查看当前安装的mysql版本:mysqladmin -u user -p pwd version
查看当前安装的mysql状态:/etc/rc.d/init.d/mysqld status
启动mysql服务:/etc/init.d/mysqld start
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (111)
解决:在确定你安装好mysql client及server的基础上,应该是mysqld服务没有启动
因为ubuntu 10.04默认源里是没有cassandra的
所以第一步要设置源:
root@shutiao:~$sudo vi /etc/apt/sources.list
添加apache官方deb源:
保存完sources.list后,我们还要设置public keyserver,增加PUBLIC_KEY,不然会报如下错误
设置并添加public keyserver
root@shutiao:~$sudo gpg –keyserver wwwkeys.eu.pgp.net –recv-keys F758CE318D77295D
root@shutiao:~$ gpg –export –armor F758CE318D77295D | sudo apt-key add -
root@shutiao:~$ sudo apt-get update
完成源设置后,我们可以查看下是否有cassandra
root@shutiao:~$ sudo apt-cache search cassandra
现在我们可以利用强大的apt-get来安装cassandra
root@shutiao:~$ sudo apt-get install cassandra
完成安装后,我们可以执行
root@shutiao:~$ ps -ef | grep cassandra
查看cassandra进程信息
到这里我们就完成了cassandra的安装
Analytics Plugin created by Web Hosting