Part I. Direct-Start download
Download website
Installation
The tar zxvf redis-2.8.9.tar.gzcd redis-2.8.9# Direct make compilation make# can use the root user to execute ' do install ' and copy the executable file to the/usr/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# detects if Port 6379 is listening NETSTAT-LNTP | grep 6379# uses the ' redis-cli ' client to detect if the connection is normal ./redis-cli127.0.0.1:6379> keys * (empty list or set) 127.0.0.1:6379> set Key " Hello world "ok127.0.0.1:6379> get Key" Hello World "
Stop it
#使用客户端redis-cli shutdown# because Redis can properly handle sigterm signal, so direct kill-9 is also possible kill-9 PID
Part Ii. To launch a configuration file by specifying a profile
The specified configuration file can be started for the Redis service, and the configuration file is 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# can modify the default listening port 6379# Modify generate default log file location logfile "/home/futeng/logs/redis.log" #配置持久化文件存放位置dir/home/futeng/data /redisdata
Specify configuration file at startup
Redis-server./redis.conf# If you change the port, 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. To set up a boot startup script using Redis startup scripts
It is recommended that you start the Redis service in a production environment using startup scripting. Startup script redis_init_script
is located in /utils/
directory.
#大致浏览下该启动脚本, 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 the location of the =6379# server, the default is to store and '/usr/local/bin/redis-server ' after make install, and if you do not install it, you need to modify the path. exec=/usr/local/bin/redis-server# the PID file location of the client location Cliexec=/usr/local/bin/redis-cli#redis pidfile=/var/run/redis_${ redisport}.pid# configuration file location, need to modify conf= "/etc/redis/${redisport}.conf"
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/REDISCP 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 directly configure the Open self-boot chkconfig REDISD on
will report error: service REDISD does not support Chkconfig
Reference This article add the following two lines of comments at the beginning of the startup script to modify its runlevel:
#!/bin/sh# chkconfig:2345 10# Description:redis is a persistent key-value database# where 2345 represents power-on startup at the 2,3,4,5 run level, 90 and 10 represents the boot sequence of power-on and shutdown, the higher the value is the lower the priority to start the general to start off, the parameters can be adjusted with your preference description content can be written at will
Set it again to succeed.
#设置为开机自启动服务器chkconfig REDISD on# Open Service services REDISD start# shut down services service REDISD stop
This article is from the "Dream to Reality" blog, please be sure to keep this source http://lookingdream.blog.51cto.com/5177800/1790962
Three ways to start Redis