启动redis服务

一、默认redis.conf文件没修改的话

1、直接进入默认路径目录

cd /usr/local/redis

2、开启服务

redis-server redis.conf

3、关闭服务

redis-cli shutdown

二、更改redis.conf,如果不知道自己的redis.conf文件在哪

1、可以全局搜索一下

find -name redis.conf

 2、进入到redis.conf所在目录

cd /softwares/myredis/

3、开启服务

redis-server redis.conf 

4、确认是否开启,输入ping回应pong表示成功了

redis-cli

错误:Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnect

原因:可能是redis.conf配置文件未修改

解决:修改以下属性:

1.把文件中的daemonize属性改为yes(表明需要在后台运行)

daemonize yes

2.把 redis.conf配置文件中的 bind 127.0.0.1 这一行给注释掉,这里的bind指的是只有指定的网段才能远程访问这个redis,注释掉后,就没有这个限制了。

#bind 127.0.0.1

3.把 redis.conf配置文件中的 protected-mode 设置成no(默认是设置成yes的, 防止了远程访问,在redis3.2.3版本后)

protected-mode no

其他:配置开机自启动

进入文件夹,编写自启动脚本

[root@localhost ~]# vim /etc/init.d/redis

脚本内容如下:

#!/bin/sh

# chkconfig: 2345 10 90

# description: Start and Stop redis

REDISPORT=6379 #默认端口

EXEC=/usr/local/redis-6.0.7/bin/redis-server #EXEC:redis文件夹所在的redis-server所在路径

CLIEXEC=/usr/local/redis-6.0.7/bin/redis-cli #CLIEXEC:redis文件夹所在的redis-cli所在路径

PIDFILE=/var/run/redis_${REDISPORT}.pid

CONF="/usr/local/redis-6.0.7/etc/redis.conf" #CONF:redis启动所用的配置文件

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 shutdown

while [ -x /proc/${PID} ]

do

echo "Waiting for Redis to shutdown ..."

sleep 1

done

echo "Redis stopped"

fi

;;

restart)

"$0" stop

sleep 3

"$0" start

;;

*)

echo "Please use start or stop or restart as first argument"

;;

esac

完成之后,添加权限:

[root@localhost ~]# chmod 777 /etc/init.d/redis

设置开机自启动:

[root@localhost ~]# chkconfig redis on

启动redis命令:

[root@localhost ~]# service redis start

测试:打开RedisDesktopManager,测试服务是否开启 以及 是否可以远程访问Redis

  • 6
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值