Skip to content
On this page

Redis

源码解压方式安装

Redis官网下载地址

  1. 将下载好的 redis-5.0.14.tar.gz上传至/home/redis
  2. 解压:tar -zxvf redis-5.0.14.tar.gz
  3. 解压之后,依次执行如下命令进行安装
1. cd redis-5.0.14
# 编译之前测试环境
2. make test
# 执行编译与安装
3. make
# 执行安装之后,在/usr/local/redis目录下会有一个bin没目录
4. mkdir /usr/local/redis -p
5. make install PREFIX=/usr/local/redis
# 复制配置文件
6. cp redis.conf /usr/local/redis/redis.conf
7. mkdir /usr/local/redis/db -p
  1. 修改redis配置文件redis.conf:vi /usr/local/redis/redis.conf
# 以守护进程方式启动
1. daemonize no  -> daemonize yes
# 修改redis数据存储路径。创建数据存储目录:mkdir -p /usr/local/redis/db
2. dir ./  -> dir /usr/local/redis/db
# 开启远程可访问
3. bind 127.0.0.1  -> bind 0.0.0.0
# 开启密码
4. requirepass jiliang

开机启动redis配置(centos7.6)

  1. 创建开机启动文件:vim /lib/systemd/system/redis.service

    • 文件内容为一下代码,注意安装redis-server和redis.conf的路径
    [Unit]
    Description=Redis
    After=network.target
    
    [Service]
    Type=forking
    ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf
    ExecReload=/usr/local/redis/bin/redis-server -s reload
    ExecStop=/usr/local/redis/bin/redis-server -s stop
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target
  2. 刷新systemctl 进程:systemctl daemon-reload

  3. 将redis.service加入开机启动:systemctl enable redis

  4. 查看开机启动项是否有redis.servicesystemctl list-unit-files |grep enable

  5. 启动redis:systemctl start redis

  6. 查看是否启动成功:ps -ef | grep redis

# 开机配置
systemctl enable redis # 开机自动启动
systemctl disable redis # 关闭开机自动启动

# 启动redis
systemctl start redis

# 停止redis
systemctl stop redis

# 重启redis
systemctl reload redis

image-20220313180936139

异常处理

1、
make test报异常代码:You need tcl 8.5 or newer in order to run the Redis test
解决方案:下载tcl8.6.1-src.tar.gz:http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz
上传到linux后依次执行指令:
tar -zxvf tcl8.6.1-src.tar.gz  -> cd tcl8.6.1/unix/  -> ./configure  -> make -> make install

Docker方式安装

RedisSearch安装

  1. 安装git
1. yum install -y git
2. git version
  1. 执行如下命令:
1. 拉取RedisSearch:
git clone --recursive https://github.com/RediSearch/RediSearch.git
2. cd RediSearch
3. make setup

异常deps/readies/mk/main:6: *** GNU Make version is too old. Aborting.. Stop

# 下载4.3make版本
1. wget http://ftp.gnu.org/gnu/make/make-4.3.tar.gz
# 解压
2. tar -zxvf make-4.3.tar.gz
3. cd make-4.3
# 安装到指定目录
4. ./configure --prefix=/usr/local/make
5. make
6. make install
# 此时make -v 还是旧版本,因为环境变量make还是旧版本
# 查找make位置
7. whereis make
8. cd /usr/bin
# 备份旧版本的make
9. mv make make_bak
# 把默认的make改名
10. ln -sv /usr/local/make/bin/make /usr/bin/make
# 查看最终版本
11. make -v

异常:Permission denied

[root@MQ2 RediSearch]# make setup
/usr/bin/bash: /home/redis/RediSearch/deps/readies/bin/getpy2: Permission denied
/usr/bin/bash: /home/redis/RediSearch/deps/readies/mk/cc-have-opts: Permission denied
/usr/bin/bash: /home/redis/RediSearch/sbin/pack.sh: Permission denied
Setting up system...
/usr/bin/bash: ./deps/readies/bin/getpy2: Permission denied
make: *** [Makefile:425: setup] Error 126

分别执行:
chmod 777  /home/redis/RediSearch/deps/readies/bin/getpy2
chmod 777  /home/redis/RediSearch/deps/readies/mk/cc-have-opts
chmod 777  /home/redis/RediSearch/sbin/pack.sh