转 redis服务启动和中止(NOAUTH Authentication required)

redis服务启动和中止(NOAUTH Authentication required)html

2017年05月02日 10:50:51redis

阅读数:8581安全

Redis安装配置完成后,启动过程很是简单,执行命令/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf便可(在Linux里通常执行 ./redis-server ../redis.conf)。中止Redis的最简单的方法是在启动实例的session中,直接使用Control-C命令。固然还能够经过客户端来中止服务,如能够用shutdown来中止Redis实例,具体命令为src/redis-cli shutdown。服务器

Redis的三种启动方式
I. 直接启动session

启动工具

#加上`&`号使redis之后台程序方式运行
./redis-server &
  • 1
  • 2

检测ui

#检测后台进程是否存在
ps -ef |grep redis

#检测6379端口是否在监听
netstat -lntp | grep 6379

#使用`redis-cli`客户端检测链接是否正常
./redis-cli -h 127.0.0.1 -p 6379 -a 123456
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379> set key "hello world"
OK
127.0.0.1:6379> get key
"hello world"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14

中止日志

#使用客户端
redis-cli shutdown
#由于Redis能够妥善处理SIGTERM信号,因此直接kill -9也是能够的
kill -9 PID
  • 1
  • 2
  • 3
  • 4

II. 经过指定配置文件启动code

配置文件server

可为Redis服务启动指定配置文件,配置文件 redis.conf

在Redis根目录下。

#修改daemonize为yes,即默认之后台程序方式运行(还记得前面手动使用&号强制后台运行吗)。
daemonize no
#可修改默认监听端口
port 6379
#修改生成默认日志文件位置
logfile "/home/futeng/logs/redis.log"
#配置持久化文件存放位置
dir /home/futeng/data/redisData
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8

启动时指定配置文件

redis-server ./redis.conf
redis-cli -p 6380
  • 1
  • 2

其余启停同 直接启动 方式。配置文件是很是重要的配置工具,随着使用的逐渐深刻将显得尤其重要,推荐在一开始就使用配置文件。
III. 使用Redis启动脚本设置开机自启动

启动脚本

推荐在生产环境中使用启动脚本方式启动redis服务。启动脚本redis_init_script

位于位于Redis的 /utils/ 目录下。

#大体浏览下该启动脚本,发现redis习惯性用监听的端口名做为配置文件等命名,咱们后面也遵循这个约定。
#redis服务器监听的端口
REDISPORT=6379
#服务端所处位置,在make install后默认存放与`/usr/local/bin/redis-server`,若是未make install则须要修改该路径,下同。
EXEC=/usr/local/bin/redis-server
#客户端位置
CLIEXEC=/usr/local/bin/redis-cli
#Redis的PID文件位置
PIDFILE=/var/run/redis_${REDISPORT}.pid
#配置文件位置,须要修改
CONF="/etc/redis/${REDISPORT}.conf"
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

配置环境

  1. 根据启动脚本要求,将修改好的配置文件以端口为名复制一份到指定目录。需使用root用户。
mkdir /etc/redis
cp redis.conf /etc/redis/6379.conf
  • 1
  • 2

2 将启动脚本复制到/etc/init.d目录下,本例将启动脚本命名为redisd(一般都以d结尾表示是后台自启动服务)。

p redis_init_script /etc/init.d/redisd
  • 1
  1. 设置为开机自启动

此处直接配置开启自启动 chkconfig redisd on
将报错误: service redisd does not support chkconfig
参照 此篇文章 ,在启动脚本开头添加以下两行注释以修改其运行级别:

#!/bin/sh
# chkconfig:   2345 90 10
# description:  Redis is a persistent key-value database
#
  • 1
  • 2
  • 3
  • 4

再设置便可成功

#设置为开机自启动服务器
chkconfig redisd on
#打开服务
service redisd start
#关闭服务
service redisd stop
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

若是配置了安全认证中止redisd服务时报
service redis stop
Stopping …
OK
(error) NOAUTH Authentication required.
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
Waiting for Redis to shutdown …
参照此篇文章

相关文章
相关标签/搜索