Redis Three boot settings boot

Source: Internet
Author: User
Tags redis root directory
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 
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.