redis服务启动和停止

harry发布

redis服务启动和停止

 

 

针对 

/alidata/redis-3.2.9/src 路径使用配置文件启动

 

 

 

cd  /alidata/redis-3.2.9/src 

执行

./redis-server   /alidata/redis-3.2.9/redis.conf &

使用配置文件 后台启动。

目录结构如下面两个图

%title插图%num

 

 

 

%title插图%num

 

 

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

 

 

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

./redis-server   /alidata/redis-3.2.9/redis.conf &

 

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

 

 

 

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

 

 

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

/alidata/redis-3.2.9/src

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

/alidata/redis-3.2.9/src

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

 

 

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

/alidata/redis-3.2.9/src

 

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

 

 

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

/alidata/redis-3.2.9/src 
 

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

 

 

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

/alidata/redis-3.2.9/src 

 

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

 

 

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

[root@iZ23tkclljpZ src]# ps -ef|grep redis
root     12472 12214  0 14:45 pts/1    00:00:00 ./redis-server *:6379                         
root     12518 12214  0 14:46 pts/1    00:00:00 grep –color=auto redis
[root@iZ23tkclljpZ src]# kill -9 12472
[1]+  Killed                  ./redis-server /alidata/redis-3.2.9/redis.conf
[root@iZ23tkclljpZ src]# ps -ef|grep redis
root     12570 12214  0 14:48 pts/1    00:00:00 grep –color=auto redis
[root@iZ23tkclljpZ src]# ./redis-server   /alidata/redis-3.2.9/redis.conf &

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

 

 

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

[root@iZ23tkclljpZ src]# ps -ef|grep redis
root     12472 12214  0 14:45 pts/1    00:00:00 ./redis-server *:6379                         
root     12518 12214  0 14:46 pts/1    00:00:00 grep –color=auto redis
[root@iZ23tkclljpZ src]# kill -9 12472
[1]+  Killed                  ./redis-server /alidata/redis-3.2.9/redis.conf
[root@iZ23tkclljpZ src]# ps -ef|grep redis
root     12570 12214  0 14:48 pts/1    00:00:00 grep –color=auto redis
[root@iZ23tkclljpZ src]# ./redis-server   /alidata/redis-3.2.9/redis.conf &

 

 

—————————————————————————————–

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。

 

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

 

 

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

 

 

 

 

 

 

ps:转载下redis的开机自启动

 

Redis的三种启动方式

时间 2014-05-26 22:05:39  ITeye-博客

原文  http://futeng.iteye.com/blog/2071867

主题 Redis

Part I. 直接启动

下载

官网下载

安装

tar zxvf redis-2.8.9.tar.gz
cd redis-2.8.9
#直接make 编译
make
#可使用root用户执行`make install`,将可执行文件拷贝到/usr/local/bin目录下。这样就可以直接敲名字运行程序了。
make install#直接make 编译
make
#可使用root用户执行`make install`,将可执行文件拷贝到/usr/local/bin目录下。这样就可以直接敲名字运行程序了。
make install

启动

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

检测

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

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

#使用`redis-cli`客户端检测连接是否正常
./redis-cli
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"
ps -ef |grep redis

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

#使用`redis-cli`客户端检测连接是否正常
./redis-cli
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"

停止

#使用客户端
redis-cli shutdown
#因为Redis可以妥善处理SIGTERM信号,所以直接kill -9也是可以的
kill -9 PID
redis-cli shutdown
#因为Redis可以妥善处理SIGTERM信号,所以直接kill -9也是可以的
kill -9 PID

Part II. 通过指定配置文件启动

配置文件

可为redis服务启动指定配置文件,配置文件 redis.conf 在Redis根目录下。

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

启动时指定配置文件

redis-server ./redis.conf
#如果更改了端口,使用`redis-cli`客户端连接时,也需要指定端口,例如:
redis-cli -p 6380#如果更改了端口,使用`redis-cli`客户端连接时,也需要指定端口,例如:
redis-cli -p 6380

其他启停同 直接启动 方式。配置文件是非常重要的配置工具,随着使用的逐渐深入将显得尤为重要,推荐在一开始就使用配置文件。

Part 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"
#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. 根据启动脚本要求,将修改好的配置文件以端口为名复制一份到指定目录。需使用root用户。

mkdir /etc/redis
cp redis.conf /etc/redis/6379.conf /etc/redis
cp redis.conf /etc/redis/6379.conf

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

cp redis_init_script /etc/init.d/redisd

 3.  设置为开机自启动

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

#!/bin/sh
# chkconfig:   2345 90 10
# description:  Redis is a persistent key-value database
#
# chkconfig:   2345 90 10
# description:  Redis is a persistent key-value database
#

 再设置即可成功。

#设置为开机自启动服务器
chkconfig redisd on
#打开服务
service redisd start
#关闭服务
service redisd stop
chkconfig redisd on
#打开服务
service redisd start
#关闭服务
service redisd stop

转载请标明作者和原

 

%title插图%num

 

部分赠送视频如下:

%title插图%num

%title插图%num

 

 

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。

 

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

 

 

root@iZ23tkclljpZ:/usr/bin# redis-cli shutdown
[10171] 03 Jun 18:13:45.577 # User requested shutdown...
[10171] 03 Jun 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] 03 Jun 18:13:45.580 * DB saved on disk
[10171] 03 Jun 18:13:45.580 # Redis is now ready to exit, bye bye...
[1]-  Done                    ./redis-server
root@iZ23tkclljpZ:/usr/bin# ps -ef|grep redis
root     12909  9997  0 18:13 pts/2    00:00:00 grep --color=auto redis

 

文章来源于互联网:redis服务启动和停止


0 条评论

发表回复

Avatar placeholder

您的电子邮箱地址不会被公开。 必填项已用*标注