下载redis-7.0.5.tar.gz,放置于/usr/local
解压tar,修改文件名redis-7.0.5为redis
cd到redis目录,make
cd到src目录,make install PREFIX=/usr/local/redis/redis
修改配置文件 1.密码requirepass 2.daemonize改为yes 3.bind127 注释掉
bin目录下,redis-server xxx/redis.conf启动redis

修改密码:修改配置文件中的密码,然后重启redis即可

开机自启动:
redis.conf中daemonize设置成yes
修改redis_init_script脚本,这是redis提供的开机自启动脚本,脚本里的路径修改成真实路径即可
cp redis_init_script /etc/init.d/redis
chmod +x /etc/init.d/redis
chkconfig redis on或者使用systemctl的enable命令

redis_init_script解释:
EXEC和CLIEXEC的路径是redis-server和redis-cli的实际路径
PIDFILE可能是文件默认路径,也可能是别的路径比如/run/redis_${REDISPORT}.pid,需要用find命令查询一下实际路径
CONF是redis.conf的路径
如果redis有密码,需要在stop的脚本里用-a添加密码 $CLIEXEC -p $REDISPORT -a root shutdown

redis-cli命令:
1 无密码本地登录
redis-cli
2 指定ip、端口、密码
redis-cli -h [ip] -p [port] -a [pwd]
3 指定ip、端口、密码并清理redis缓存
redis-cli -h [ip] -p [port] -a [pwd] flushall
4 指定ip、端口、密码、数据库
redis-cli -h [ip] -p [port] -a [pwd] -n [db_number]

#!/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/redis/redis/bin/redis-server
CLIEXEC=/usr/local/redis/redis/bin/redis-cli

PIDFILE=/run/redis_${REDISPORT}.pid
CONF="/usr/local/redis/redis.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 -p $REDISPORT -a root 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"
        ;;
esac