Original address: Http://futeng.iteye.com/blog/2071867?utm_source=tuicool
Redis Source Download Address: http://download.csdn.net/detail/haitunxiaomo/8647255
Part I. Direct start
installation
Shell code:
The tar zxvf redis-2.8.9.tar.gz
cd redis-2.8.9
#直接make
compile
make #可使用root用户执行 ' do install ' to copy the executable file to/usr The/local/bin directory. So you can just hit the name and run the program. Make
Install
Start
Shell code:
#加上 ' & ' allows Redis to run in a background program
./redis-server &
DetectionShell Code
#检测后台进程是否存在
ps-ef |grep redis
#检测6379端口是否在监听
netstat-lntp | grep 6379
#使用 ' redis-cli ' client detects 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"
StopShell Code
#使用客户端
redis-cli shutdown
#因为Redis可以妥善处理SIGTERM信号, so direct kill-9 is also possible
kill-9 PID
Part Ii. starting by specifying a configuration file
configuration file
You can start the specified profile for the Redis service, and the configuration file redis.conf in the Redis root directory.
Shell Code
#修改daemonize为yes, that is, the default way to run the program (remember to force the background to run manually using the & number).
daemonize No
#可修改默认监听端口
Port 6379
#修改生成默认日志文件位置
logfile "/home/futeng/logs/redis.log"
# Configure persistent file storage location
Dir/home/futeng/data/redisdata
Specify profile at startup
Shell Code
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 and stop with the same direct starting mode. The configuration file is a very important configuration tool, and it is particularly important to use it gradually, and it is recommended that you use the configuration file in the first place.
Part Iii. Use the Redis startup script to set the boot up Startup script
It is recommended that you start the Redis service in a production environment using a startup script. The startup script Redis_init_script is located in the/utils/directory located in Redis.
Shell Code
#大致浏览下该启动脚本, it is found that Redis habitually uses the listener's port name as a configuration file, and we follow this convention later.
#redis服务器监听的端口
redisport=6379
#服务端所处位置, the default storage after make install and '/usr/local/bin/redis-server ', if not make install need to modify the path, the same below.
exec=/usr/local/bin/redis-server
#客户端位置
cliexec=/usr/local/bin/redis-cli
#Redis的PID文件位置
Pidfile=/var/run/redis_${redisport}.pid
#配置文件位置, need to modify
conf= "/etc/redis/${redisport}.conf"
Configuring the Environment
1. Copy the modified profile to the specified directory in the name of the port according to the startup script requirements. You need to use the root user.
Shell Code
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 as REDISD (usually at the end of D as the background self-boot service).
Shell Code
CP REDIS_INIT_SCRIPT/ETC/INIT.D/REDISD
3. Set to power-on self-starter
Direct configuration to open from boot 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 run level:
Shell Code
#!/bin/sh
# chkconfig: 2345 #
Description: Redis is a persistent key-value database
#
You can then set it to success.
Shell Code
#设置为开机自启动服务器
chkconfig REDISD on
#打开服务
service REDISD start
#关闭服务
service REDISD stop