环境:
Ubuntu 16.04 (如果是CentOS,内核需要7以上)
Redis 4.0.1 (redis需要4以上)
cmake 3.13.3 (cmake需要3以上)
先安装cmake
apt install cmake
校验cmake是否安装成功
cmake -version
下载RediSearch源码:
git clone https://github.com/RedisLabsModules/RediSearch.git
进入RediSearch文件夹
cd RediSearch
创建build文件夹,并进入文件夹
mkdir build
cd build
使用cmake构建
cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo
注意:‘=’前后不能有空格,否则报错,如下图:
root@ubuntu:/program/RediSearch/build# cmake .. -DCMAKE_BUILD_TYPE = RelWithDebInfo
Parse error in command line argument: -DCMAKE_BUILD_TYPE
Should be: VAR:type=value
CMake Error: No cmake script provided.
CMake Error: Problem processing arguments. Aborting.
构建完成后,使用make编译
make
安装Redis(版本必须高于4)
$ wget http://download.redis.io/releases/redis-4.0.1.tar.gz
$ tar -zxvf redis-4.0.1.tar.gz
$ cd redis-4.0.1
$ make
查看redis版本
./redis-server -v
用redis-server启动RediSearch
./redis-server --loadmodule ../../../build/redisearch.so
启动成功
也可以把redis-server与redis-cli拷贝到redisearch.so同一目录下,便可直接启动
./redis-server --loadmodule ./redisearch.so
后台启动redisearch,将redis.conf也拷贝到redisearch.so同一目录下,将daemonize no 改为 daemonize yes,保存退出
# daemonize no
daemonize yes
后台启动redisearch
./redis-server ./redis.conf --loadmodule ./redisearch.so
使用redis-cli连接测试是否启动成功,--raw表示以存储形式显示
./redis-cli --raw
开启aof持久化,编辑redis.conf文件将appendonly no 改为 appendonly yes,保存退出
# appendonly no
appendonly yes
关闭并重启redisearch
root@ubuntu:/program/RediSearch/build# redis-cli -p 6379 shutdown
root@ubuntu:/program/RediSearch/build# ./redis-server ./redis.conf --loadmodule ./redisearch.so
13127:C 31 Jan 01:38:13.242 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
13127:C 31 Jan 01:38:13.242 # Redis version=4.0.1, bits=64, commit=18ea318e, modified=0, pid=13127, just started
13127:C 31 Jan 01:38:13.242 # Configuration loaded
测试生效
root@ubuntu:/program/RediSearch/build# ./redis-server ./redis.conf --loadmodule ./redisearch.so
13127:C 31 Jan 01:38:13.242 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
13127:C 31 Jan 01:38:13.242 # Redis version=4.0.1, bits=64, commit=18ea318e, modified=0, pid=13127, just started
13127:C 31 Jan 01:38:13.242 # Configuration loaded
root@ubuntu:/program/RediSearch/build# ./redis-cli --raw
127.0.0.1:6379> FT.CREATE myIdx SCHEMA title TEXT WEIGHT 5.0 body TEXT url TEXT
OK
127.0.0.1:6379> FT.ADD myIdx doc1 1.0 FIELDS title "hello world" body "lorem ipsum" url "http://redis.io"
OK
127.0.0.1:6379> ft.get myIdx doc1
title
hello world
body
lorem ipsum
url
http://redis.io
127.0.0.1:6379>
root@ubuntu:/program/RediSearch/build# redis-cli -p 6379 shutdown
root@ubuntu:/program/RediSearch/build# ./redis-server ./redis.conf --loadmodule ./redisearch.so
13161:C 31 Jan 01:40:10.845 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
13161:C 31 Jan 01:40:10.845 # Redis version=4.0.1, bits=64, commit=18ea318e, modified=0, pid=13161, just started
13161:C 31 Jan 01:40:10.845 # Configuration loaded
root@ubuntu:/program/RediSearch/build# ./redis-cli --raw127.0.0.1:6379> ft.get myIdx doc1
title
hello world
body
lorem ipsum
url
http://redis.io
127.0.0.1:6379>
指定日志文件,编辑redis.conf,找到 logfile "",在引号中添加绝对路径
logfile "/program/RediSearch/build/redis.log"