vlambda博客
学习文章列表

Redis 6.x单机安装详细步骤-CentOS


这是一篇Redis单机版的安装攻略,看本攻略之前注意以下两点:

  • 安装的Redis版本为 6.2.1

  • 安装过程若有问题,请看最后一章 安装常见问题


安装步骤

(1)进入待装目录(自定义)

cd /usr/local/src


(2)下载redis 6.2.1版本(也可上官网下载后上传:https://redis.io/download)

wget http://download.redis.io/releases/redis-6.2.1.tar.gz


(3)解压

tar zxf redis-6.2.1.tar.gz


(4)进入目录

cd redis-6.2.1


(5)执行编译

make


(6)安装

cd src && make install


(7)为了方便管理,将redis的conf配置文件和常用命令移动到统一文件中

mkdir -p /usr/local/redis-6.2.1/etcmkdir -p /usr/local/redis-6.2.1/bincp /usr/local/src/redis-6.2.1/src/redis-server /usr/local/redis-6.2.1/bincp /usr/local/src/redis-6.2.1/src/redis-benchmark /usr/local/redis-6.2.1/bincp /usr/local/src/redis-6.2.1/src/redis-check-rdb /usr/local/redis-6.2.1/bincp /usr/local/src/redis-6.2.1/src/redis-sentinel /usr/local/redis-6.2.1/bincp /usr/local/src/redis-6.2.1/src/redis-cli /usr/local/redis-6.2.1/bincp /usr/local/src/redis-6.2.1/src/redis-trib.rb /usr/local/redis-6.2.1/bincp /usr/local/src/redis-6.2.1/src/redis-check-aof /usr/local/redis-6.2.1/bincp /usr/local/src/redis-6.2.1/redis.conf /usr/local/redis-6.2.1/etc


(8)修改配置文件redis.conf

cd /usr/local/src/redis-6.2.1 && vi redis.conf

修改如下配置项:

  • 开启守护线程,后台运行:daemonize yes

  • 监听所有机器的请求(生产环境禁止这样配置):# bind 127.0.0.1 -::1

  • 设置密码(生产环境配置复杂密码):requirepass 123456


(9)启动Redis

cd /usr/local/redis-6.2.1/bin./redis-server /usr/local/redis-6.2.1/etc/redis.conf &


(10)查看是否启动成功

ps -ef|grep 6379


设置开机自启动

(1)创建启动命令脚本

vim /etc/init.d/redis-auto


(2)脚本中加入如下内容

#!/bin/sh#chkconfig: 2345 80 90#description:auto_run
REDISHOMEPATH=/usr/local/redis-6.2.1 #找到本机安装redis目录REDISBINPATH=${REDISHOMEPATH}/bin #REDIS bin目录REDISPORT=6379 #redis的默认端口EXEC=${REDISBINPATH}/redis-server #redis服务端的命令REDIS_CLI=${REDISBINPATH}/redis-cli #redis客户端的命令PIDFILE=/var/run/redis_${REDISPORT}.pid #reids的进程文件生成的位置CONF="${REDISHOMEPATH}/etc/redis.conf" #redis的配置文件所在的目录 #AUTH="1234" 这句没什么用可以不要
case "$1" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed." else echo "Starting Redis server..." $EXEC $CONF fi if [ "$?"="0" ] then echo "Redis is running..." fi ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE exists, process is not running." else PID=$(cat $PIDFILE) echo "Stopping..." $REDIS_CLI -p $REDISPORT SHUTDOWN sleep 2 while [ -x $PIDFILE ] do echo "Waiting for Redis to shutdown..." sleep 1 done echo "Redis stopped" fi ;; restart|force-reload) ${0} stop ${0} start ;; *) echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2 exit 1 esac


(3)设置文件redis-auto的权限,让Linux可以执行

chmod 755 /etc/init.d/redis-auto


(4)启动Redis服务测试

/etc/init.d/redis-auto start


(5)设置开机自启动

chkconfig redis-auto on


安装常见问题

(1)make编译时找不到gcc命令,则通过以下命令安装

yum install gcc-c++


(2)make编译出现:zmalloc.h:50:31: 致命错误:jemalloc/jemalloc.h:没有那个文件或目录。则换成以下以下命令执行:

make MALLOC=libc


(3)make test出现:You need tcl 8.5 or newer in order to run the Redis test。执行以下命令执行:

cd /optwget http://downloads.sourceforge.net/tcl/tcl8.6.1-src.tar.gz  sudo tar xzvf tcl8.6.1-src.tar.gz   cd  /opt/tcl8.6.1/unix/  sudo ./configure  sudo make  sudo make install


Redis 6.x单机安装详细步骤-CentOS

觉得有用,点个在看