Redis Service start and stop

Source: Internet
Author: User
Tags redis


Using a configuration file for/alidata/redis-3.2.9/src path startup



Cd/alidata/redis-3.2.9/src execution./redis-server/alidata/redis-3.2.9/redis.conf &

Use the configuration file to start the background. The directory structure is as below two graphs







root@iz23tkclljpz:/usr/bin# redis-cli shutdown
[10171] June 18:13:45.577 # User requested shutdown ...
[10171] June 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] June 18:13:45.580 * DB saved on disk
[10171] June 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] June 18:13:45.577 # User requested shutdown ...
[10171] June 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] June 18:13:45.580 * DB saved on disk
[10171] June 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] June 18:13:45.577 # User requested shutdown ...
[10171] June 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] June 18:13:45.580 * DB saved on disk
[10171] June 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] June 18:13:45.577 # User requested shutdown ...
[10171] June 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] June 18:13:45.580 * DB saved on disk
[10171] June 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] June 18:13:45.577 # User requested shutdown ...
[10171] June 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] June 18:13:45.580 * DB saved on disk
[10171] June 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] June 18:13:45.577 # User requested shutdown ...
[10171] June 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] June 18:13:45.580 * DB saved on disk
[10171] June 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] June 18:13:45.577 # User requested shutdown ...
[10171] June 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] June 18:13:45.580 * DB saved on disk
[10171] June 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] June 18:13:45.577 # User requested shutdown ...
[10171] June 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] June 18:13:45.580 * DB saved on disk
[10171] June 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] June 18:13:45.577 # User requested shutdown ...
[10171] June 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] June 18:13:45.580 * DB saved on disk
[10171] June 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] June 18:13:45.577 # User requested shutdown ...
[10171] June 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] June 18:13:45.580 * DB saved on disk
[10171] June 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] June 18:13:45.577 # User requested shutdown ...
[10171] June 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] June 18:13:45.580 * DB saved on disk
[10171] June 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] June 18:13:45.577 # User requested shutdown ...
[10171] June 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] June 18:13:45.580 * DB saved on disk
[10171] June 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] June 18:13:45.577 # User requested shutdown ...
[10171] June 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] June 18:13:45.580 * DB saved on disk
[10171] June 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] June 18:13:45.577 # User requested shutdown ...
[10171] June 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] June 18:13:45.580 * DB saved on disk
[10171] June 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] June 18:13:45.577 # User requested shutdown ...
[10171] June 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] June 18:13:45.580 * DB saved on disk
[10171] June 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] June 18:13:45.577 # User requested shutdown ...
[10171] June 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] June 18:13:45.580 * DB saved on disk
[10171] June 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 &


-----------------------------------------------------------------------------------------

After the Redis installation configuration is complete, the boot process is very simple and executes the command/usr/local/redis/bin/redis-server/usr/local/redis/etc/redis.conf (which is generally performed in Linux). Redis-server. /redis.conf). The simplest way to stop Redis is to use the CONTROL-C command directly in the session that launches the instance. Of course, you can also stop the service through the client, such as you can use shutdown to stop the Redis instance, the specific command is SRC/REDIS-CLI shutdown.



root@iz23tkclljpz:/usr/bin# redis-cli shutdown
[10171] June 18:13:45.577 # User requested shutdown ...
[10171] June 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] June 18:13:45.580 * DB saved on disk
[10171] June 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] June 18:13:45.577 # User requested shutdown ...
[10171] June 18:13:45.577 * Saving the final RDB snapshot before exiting.
[10171] June 18:13:45.580 * DB saved on disk
[10171] June 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: Reproduced under Redis's boot from the boot
three ways to start RedisTime 2014-05-26 22:05:39 iteye-blog Original http://futeng.iteye.com/blog/2071867 theme Redis Part I. Direct start Download

Download and install the website

Tar zxvf redis-2.8.9.tar.gz
cd redis-2.8.9
#直接make compile
make #可使用root用户执行 ' do install ' to copy the executable to/usr The/local/bin directory. This allows you to run the program directly by typing the name. Make
Install
Start
#加上 ' & ' allows Redis to run in a daemon fashion
./redis-server &
Detection
#检测后台进程是否存在
ps-ef |grep redis

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

#使用 ' redis-cli ' client to detect the connection is normal
./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"
Stop
#使用客户端
redis-cli shutdown
#因为Redis可以妥善处理SIGTERM信号, so direct kill-9 is also possible
kill-9 PID
Part Ii. starting by specifying a profile configuration file

The specified configuration file can be started for the Redis service, and the configuration file redis.conf under the Redis root directory.

#修改daemonize为yes, that is, the default way to run the program (remember to manually use & to force the background to run earlier).
daemonize No
#可修改默认监听端口
Port 6379
#修改生成默认日志文件位置
logfile "/home/futeng/logs/redis.log"
# Configure persistent file storage location
Dir/home/futeng/data/redisdata
specify configuration file at startup
Redis-server./redis.conf
#如果更改了端口, you also need to specify a port when using the ' redis-cli ' client connection, for example:
redis-cli-p 6380

Other start-stop and direct starting mode. Configuration files are a very important configuration tool, and it is important to use the configuration files in the first place as they become progressively more intensive. Part iii. setting up boot-up with Redis startup scripts Startup Scripts

It is recommended that you start the Redis service in a production environment using startup scripting. The startup script Redis_init_script is located in the/utils/directory located in Redis.

#大致浏览下该启动脚本, it is found that Redis habitually uses the port name of the listener as the configuration file, and we follow this convention later.
#redis服务器监听的端口
redisport=6379
#服务端所处位置, after make install the default storage and '/usr/local/bin/redis-server ', if not make install will need to modify the path, the same.
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" needs to be modified
Configuring the Environment

1. According to the startup script requirements, copy the modified configuration file to the specified directory with the name of the port. Need to use root user.

Mkdir/etc/redis
CP redis.conf/etc/redis/6379.conf

2. Copy the startup script to the/ETC/INIT.D directory, this example names the startup script REDISD (usually ending with D as the background self-starting service).

CP REDIS_INIT_SCRIPT/ETC/INIT.D/REDISD

3. Set to boot from boot

Here the direct configuration turns on self-booting chkconfig REDISD on will report error: Service REDISD does not support Chkconfig
Referring to this article, add the following two lines of comments at the beginning of the startup script to modify its runlevel:

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

Set it again to succeed.

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

Reprint please indicate the author and the original

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.