文章目录

RediSearch安装-基于Redis的全文检索

由 jafucong 发布

安装前准备

  1. 安装CentOS7.8 2003 最小系统版
  2. 更新软件包:yum -y upgrade
  3. 安装宝塔(可选)
    yum install -y wget && wget -O install.sh http://download.bt.cn/install/install_6.0.sh && sh install.sh
    安装完成后,修改宝塔配置:

    • 绑定管理IP地址
    • 取消管理登录地址后面的数字
    • 修改宝塔用户名密码
  4. 安装Redis6.0.5

    a. 编译安装redis

yum -y install gcc
6.0以上的redis需要升级gcc
gcc -v                             # 查看gcc版本
yum -y install centos-release-scl  # 升级到9.1版本
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash

以上为临时启用,如果要长期使用gcc 9.1的话:
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile

make PREFIX=/usr/local/redis install
cp -p /home/redis-6.0.5/redis.conf /usr/local/redis/

自启动:
在 /etc/rc.d/init.d/下增加一下脚本
chkconfig --add redis

redis 自启动脚本 /etc/rc.d/init.d/redis

#!/bin/sh
# chkconfig: 2345 56 26
# description: Redis Service

# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

CONF="/usr/local/redis/redis.conf"
REDIS_PORT=$(cat $CONF |grep port|grep -v '#'|awk '{print $2}')
REDIS_PASS=$(cat $CONF |grep requirepass|grep -v '#'|awk '{print $2}')
REDIS_HOST=$(cat $CONF |grep bind|grep -v '#'|awk '{print $2}')
if [ "$REDIS_PASS" != "" ];then
        REDIS_PASS=" -a $REDIS_PASS"
fi
STAR_PORT="6379"
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC="/usr/local/redis/bin/redis-cli -h ${REDIS_HOST} -p ${STAR_PORT}${REDIS_PASS}"
PIDFILE="/var/run/redis_${STAR_PORT}.pid"

redis_start(){
        if [ -f $PIDFILE ]; then
                ps -p $(cat ${PIDFILE}) > /dev/null 2>&1
                if [ $? -ne "0" ]; then
                        echo Redis is not running, buy pid file is exits ${PIDFILE}
                        exit 1
                else
                        echo "redis is running! ($(cat ${PIDFILE}))"
                        exit 0
                fi
        fi
        echo "Starting redis server..."
        sudo -u root $EXEC $CONF
        echo ${REDIS_PORT}
        echo "Starting redis success!"
}
redis_status(){
        if [ -f $PIDFILE ]; then
                ps -p $(cat ${PIDFILE}) > /dev/null 2>&1
                if [ $? -ne "0" ]; then
                        echo "Redis is not running, buy pid file is exits ${PIDFILE}"
                        exit 1
                else
                        echo "redis is running! ($(cat ${PIDFILE}))"
                        exit 0
                fi
        else
                echo "redis is stopped"
                exit 0
        fi
}
redis_stop(){
        echo "Stopping ..."
        $CLIEXEC shutdown
        sleep 1
        pkill -9 redis-server
        rm -f ${PIDFILE}
        echo "Redis stopped"
}

case "$1" in
        start)
                redis_start
                ;;
        stop)
                redis_stop
                ;;
        status)
                redis_status
                ;;
        restart|reload)
                redis_stop
                sleep 0.3
                redis_start
                ;;
        *)
                echo "Please use start or stop as first argument"
                ;;
esac

b. 安装宝塔后只需要修改配置

redis.conf

# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

loadmodule /usr/local/redis/bin/redisearch.so

bind 127.0.0.1 192.168.3.49

daemonize yes 

dir /root/
  1. 编译安装RedisSearch
git clone --recursive https://github.com/RediSearch/RediSearch.git
cd RediSearch
git tag
git checkout v2.0.5
make 
cp -p src/redisearch.so /usr/local/redis/bin/





#安装 python(可选)
./deps/readies/bin/getpy2
yum install -y python-pip
pip install -U pip
#初始化环境(可选)
./system-setup.py

暂无评论

发表评论