启动redis服务

📅 发布时间:2026/7/10 22:18:12 👁️ 浏览次数:
启动redis服务
一、默认redis.conf文件没修改的话1、直接进入默认路径目录cd /usr/local/redis2、开启服务redis-server redis.conf3、关闭服务redis-cli shutdown二、更改redis.conf如果不知道自己的redis.conf文件在哪1、可以全局搜索一下find -name redis.conf2、进入到redis.conf所在目录cd /softwares/myredis/3、开启服务redis-server redis.conf4、确认是否开启输入ping回应pong表示成功了redis-cli错误Unable to connect to Redis nested exception is io.lettuce.core.RedisConnect原因可能是redis.conf配置文件未修改解决修改以下属性1.把文件中的daemonize属性改为yes(表明需要在后台运行)daemonize yes2.把 redis.conf配置文件中的 bind 127.0.0.1 这一行给注释掉这里的bind指的是只有指定的网段才能远程访问这个redis注释掉后就没有这个限制了。#bind 127.0.0.13.把 redis.conf配置文件中的 protected-mode 设置成no(默认是设置成yes的 防止了远程访问在redis3.2.3版本后)protected-mode no其他配置开机自启动进入文件夹编写自启动脚本[rootlocalhost ~]# vim /etc/init.d/redis脚本内容如下#!/bin/sh# chkconfig: 2345 10 90# description: Start and Stop redisREDISPORT6379 #默认端口EXEC/usr/local/redis-6.0.7/bin/redis-server #EXECredis文件夹所在的redis-server所在路径CLIEXEC/usr/local/redis-6.0.7/bin/redis-cli #CLIEXECredis文件夹所在的redis-cli所在路径PIDFILE/var/run/redis_${REDISPORT}.pidCONF“/usr/local/redis-6.0.7/etc/redis.conf” #CONFredis启动所用的配置文件case “$1” instart)if [ -f $PIDFILE ]thenecho “$PIDFILE exists, process is already running or crashed”elseecho “Starting Redis server…”$EXEC $CONF fi;;stop)if [ ! -f $PIDFILE ]thenecho “$PIDFILE does not exist, process is not running”elsePID$(cat $PIDFILE)echo “Stopping …”$CLIEXEC -p $REDISPORT shutdownwhile [ -x /proc/${PID} ]doecho “Waiting for Redis to shutdown …”sleep 1doneecho “Redis stopped”fi;;restart)“$0” stopsleep 3“$0” start;;*)echo “Please use start or stop or restart as first argument”;;esac完成之后添加权限[rootlocalhost ~]# chmod 777 /etc/init.d/redis设置开机自启动[rootlocalhost ~]# chkconfig redis on启动redis命令[rootlocalhost ~]# service redis start测试打开RedisDesktopManager测试服务是否开启 以及 是否可以远程访问Redis