redis安装

1. redis下载
redis可以在redis官网下载。
https://redis.io/

2. 上传至服务器并解压编译源码
3. tar xzvf /opt/redis-5.0.7.tar.gz
cd /opt/redis-5.0.7
make install
4. 新建redis用户和用户组
groupadd redis
useradd -r -g redis redis
5. 在/home下创建文件夹redis,并将3生成的src文件夹下生成的脚本和上一层目录的redis.conf文件拷贝到该/home/redis下
6. 给redis文件夹修改用户组
Chown -R redis:redis /home/redis
7. 将redis文件夹建立软链接到/usr/local/redis下
ln -s /home/redis /usr/local/redis

8. 设置开机自启动
配置开机自启动脚本/etc/init.d/redis
REDISPORT=6379
EXEC=/usr/local/redis/redis-server
REDIS_CLI=/usr/local/redis/redis-cli

PIDFILE=/usr/local/redis/redis.pid
CONF="/usr/local/redis/redis.conf"
AUTH="Test_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
    sleep 3
    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
9. 系统添加redis服务
systemctl unmask redis
10. 启动redis服务
root用户下/etc/init.d/redis start

11. 这样redis配置文件修改好之后,放到/usr/local/redis下,就可以启动redis服务了。
要配置redis登录使用密码,就可以在redis.config下解开了参数requirepass test123。
12. 密码登录
redis-cli -h 192.166.21.151 -a test123

posted @ 2020-08-24 18:55  飞鱼厅  阅读(186)  评论(0编辑  收藏  举报