Centos7安装并配置redis

一、下载redis-5.0.5安装包

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

二、解压压缩包至指定目录

# mkdir -p /home/mark/tools
# tar zxvf redis-5.0.5.tar.gz -C /home/mark/tools/

三、转到redis解压目录

# cd redis-5.0.5/

四、编译安装

# make MALLOC=libc
/redis-5.0.5/src目录下的文件添加至/usr/local/bin目录
# cd src/ && make install

五、设置redis开机自启

修改redis.conf文件,配置文件比较大,我们通过ctrl + F  查找关键字
    daemonize no 改为 daemonize yes 开启守护进程
   bind 127.0.0.1 改为 bind 0.0.0.0  更改绑定IP或直接注掉
   protected-mode yes 改为 protected-mode no 关闭保护模式
# sed -i 's/daemonize no/daemonize yes/g' ../redis.conf 1、在/etc目录下新建redis目录 # mkdir -p /etc/redis 2、将/redis-5.0.5/redis.conf 文件复制一份到/etc/redis目录下,并命名为6379.conf  # cp /home/mark/tools/redis-5.0.5/redis.conf /etc/redis/6379.conf 3、将redis的启动脚本复制一份放到/etc/init.d目录下 # cp /home/mark/tools/redis-5.0.5/utils/redis_init_script /etc/init.d/redisd 4、设置开机自启 # systemctl enable redisd 5、开启服务&查看服务状态 # systemctl start redisd # systemctl status redisd.service ● redisd.service - LSB: Redis data structure server Loaded: loaded (/etc/rc.d/init.d/redisd; bad; vendor preset: disabled) Active: active (running) since 二 2020-06-09 17:50:19 CST; 7min ago Docs: man:systemd-sysv-generator(8) CGroup: /system.slice/redisd.service └─10153 /usr/local/bin/redis-server 127.0.0.1:6379

六、设置客户端登录密码

编辑redis.conf文件,搜索requirepass关键字,去掉注释后,把foobared替换为自己的密码即可;
# vim ../redis.conf
requirepass 123456

七、更改完客户端登录密码,Redis服务停止报错解决方案

1、修改redis服务脚本
    vi /etc/init.d/redis 
  #!/bin/sh # # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. ### BEGIN INIT INFO # Provides: redis_6379 # Default-Start: 2 3 4 5 # Default-Stop: 0 1 6 # Short-Description: Redis data structure server # Description: Redis data structure server. See https://redis.io ### END INIT INFO REDISPORT=6379 EXEC=/usr/local/bin/redis-server CLIEXEC=/usr/local/bin/redis-cli PIDFILE=/var/run/redis_${REDISPORT}.pid CONF="/etc/redis/${REDISPORT}.conf"

   RESDISPASSWORD=123456 #密码应该可以CONF读取密码但是不会

    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
            ;;
        stop)
            if [ ! -f $PIDFILE ]
            then
                    echo "$PIDFILE does not exist, process is not running"
            else
                    PID=$(cat $PIDFILE)
                    echo "Stopping ..."
                    $CLIEXEC -a $RESDISPASSWORD -p $REDISPORT shutdown
                    ###修改上面一行
                    while [ -x /proc/${PID} ]
                    do
                        echo "Waiting for Redis to shutdown ..."
                        sleep 1
                    done
                    echo "Redis stopped"
            fi
            ;;
        *)
            echo "Please use start or stop as first argument"
            ;;
重新加载服务配置文件
# systemctl daemon-reload
原文地址:https://www.cnblogs.com/daidechong/p/13100700.html