Redis_安装与配置

1/18/2021 Redis

# Redis安装&配置

安装包中ReadMe文件有详细的安装和配置说明

# 安装

# 下载安装包
wget  http://download.redis.io/releases/redis-5.0.5.tar.gz
# 解压
tar -zxvf redis-5.0.5.tar.gz
mv redis-5.0.5 /opt/src/
cd /opt/src/redis-5.0.5
make
make install PREFIX=/opt/redis5
1
2
3
4
5
6
7
8

# 配置环境变量

修改/etc/profile文件加入如下行

export REDIS_HOME=/opt/redis5
export PATH=$PATH:$REDIS_HOME/bin
1
2

# 配置安装server

  • 利用官方提供的utils配置安装一个server并配置成服务

    cd utils
    ./install_server.sh
    
    1
    2

Welcome to the redis service installer This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379] Selecting default: 6379 Please select the redis config file name [/etc/redis/6379.conf] Selected default - /etc/redis/6379.conf Please select the redis log file name [/var/log/redis_6379.log] Selected default - /var/log/redis_6379.log Please select the data directory for this instance [/var/lib/redis/6379] Selected default - /var/lib/redis/6379 Please select the redis executable path [] /opt/redis5/bin/redis-server Selected config: Port : 6379 Config file : /etc/redis/6379.conf Log file : /var/log/redis_6379.log Data dir : /var/lib/redis/6379 Executable : /opt/redis5/bin/redis-server Cli Executable : /opt/redis5/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/6379.conf => /etc/init.d/redis_6379 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... Installation successful!

# 维护server

# 启动Redis服务
service redis_6379 start
# 关闭Redis服务
service redis_6379 stop
# 通过redis-cli工具发送关闭命令关闭redis
redis-cli -p 6379 shutdown
1
2
3
4
5
6

# 客户端连接

redis-cli [OPTIONS] [cmd [arg [arg ...]]]

redis-cli -h

redis-cli -n

redis-cli --raw   #超过ascii的限制时触发编码集显示

"help @<group>" to get a list of commands in <group>
"help <command>" for help on <command>
"help <tab>" to get a list of possible help topics
1
2
3
4
5
6
7
8
9
10
11

# Q&A

  • make test报错 You need tcl 8.5 or newer in order to run the Redis test 解决方法 yum install tcl

  • mac上执行utils/install_server.sh脚本会报错

    • Mmmmm... the default config is missing. Did you switch to the utils directory?

      • 原因:Mac不识别install_server.sh中readlink命令,所以无法找到默认配置文件redis.conf在哪儿

      • 解决方案:

    • ERROR: Could not copy redis init script to /etc/init.d/redis_6379. Aborting!

      • 原因:mac里面的服务启动文件不在/etc/init.d目录下

      • 解决方案:不开机启动,注释掉相关代码

        cp $TMP_FILE $INIT_SCRIPT_DEST && \
        	chmod +x $INIT_SCRIPT_DEST || die "Could not copy redis init script to $INIT_SCRIPT_DEST"
        echo "Copied $TMP_FILE => $INIT_SCRIPT_DEST"
        
        ...
        /etc/init.d/redis_$REDIS_PORT start || die "Failed starting service..."
        
        1
        2
        3
        4
        5
        6
      • 启动

        redis-server /etc/redis/6379.conf