Three ways to start Redis

Source: Internet
Author: User

Part I. Direct startDownload

Download website

Installation

Shell code 650) this.width=650; "class=" star "src=" Http://futeng.iteye.com/images/icon_star.png "alt=" Favorites code "/>

    1. Tar zxvf redis-2.8. 9. tar.gz

    2. CD redis-2.8. 9

    3. #直接make compilation

    4. Make

    5. #可使用root用户执行 ' make install ' to copy the executable file to the/usr/local/bin directory. This allows you to run the program directly by typing the name.

    6. Make install

Start

Shell code 650) this.width=650; "class=" star "src=" Http://futeng.iteye.com/images/icon_star.png "alt=" Favorites code "/>

    1. #加上 ' & ' makes Redis run as a daemon

    2. ./redis-server &

Detection

Shell code 650) this.width=650; "class=" star "src=" Http://futeng.iteye.com/images/icon_star.png "alt=" Favorites code "/>

  1. #检测后台进程是否存在

  2. Ps-ef |grep Redis

  3. #检测 the 6379 port is listening

  4. NETSTAT-LNTP | grep 6379

  5. #使用 ' redis-cli ' client detects if the connection is healthy

  6. ./redis-cli

  7. 127.0. 0.1:6379> Keys *

  8. (empty list or set)

  9. 127.0. 0.1:6379> Set key "Hello World"

  10. Ok

  11. 127.0. 0.1:6379> Get key

  12. "Hello World"

Stop it

Shell code 650) this.width=650; "class=" star "src=" Http://futeng.iteye.com/images/icon_star.png "alt=" Favorites code "/>

    1. #使用客户端

    2. REDIS-CLI shutdown

    3. #因为Redis可以妥善处理SIGTERM信号, so direct kill-9 is also possible.

    4. Kill-9 PID

Part Ii. starting by specifying a profileConfiguration file

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

Shell code 650) this.width=650; "class=" star "src=" Http://futeng.iteye.com/images/icon_star.png "alt=" Favorites code "/>

    1. #修改daemonize为yes, that is, the default way to run the program (remember to manually use & to force the background to run earlier).

    2. Daemonize No

    3. #可修改默认监听端口

    4. Port 6379

    5. #修改生成默认日志文件位置

    6. LogFile "/home/futeng/logs/redis.log"

    7. #配置持久化文件存放位置

    8. Dir/home/futeng/data/redisdata

Specify configuration file at startup

Shell code 650) this.width=650; "class=" star "src=" Http://futeng.iteye.com/images/icon_star.png "alt=" Favorites code "/>

    1. Redis-server./redis.conf

    2. #如果更改了端口, you also need to specify a port when using the ' redis-cli ' client connection, for example:

    3. Redis-cli-p 6380

other start-stop with Direct Start Way. 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 scriptsStartup 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 Redis /utils/ directory.

Shell code 650) this.width=650; "class=" star "src=" Http://futeng.iteye.com/images/icon_star.png "alt=" Favorites code "/>

    1. #大致浏览下该启动脚本, it is found that Redis habitually uses the port name of the listener as the configuration file, and we follow this convention later.

    2. #redis服务器监听的端口

    3. redisport=6379

    4. #服务端所处位置, the default storage and '/usr/local/bin/redis-server ' after make install, if not make install, you need to modify the path, the same as below.

    5. Exec=/usr/local/bin/redis-server

    6. #客户端位置

    7. Cliexec=/usr/local/bin/redis-cli

    8. #Redis的PID文件位置

    9. Pidfile=/var/run/redis_${redisport}.pid

    10. #配置文件位置, you need to modify

    11. 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.

Shell code 650) this.width=650; "class=" star "src=" Http://futeng.iteye.com/images/icon_star.png "alt=" Favorites code "/>

    1. Mkdir/etc/redis

    2. 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).

Shell code 650) this.width=650; "class=" star "src=" Http://futeng.iteye.com/images/icon_star.png "alt=" Favorites code "/>

    1. CP REDIS_INIT_SCRIPT/ETC/INIT.D/REDISD

3. set to boot from boot

The direct configuration here is to turn on self-booting chkconfig redisd on to report an 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:

Shell code 650) this.width=650; "class=" star "src=" Http://futeng.iteye.com/images/icon_star.png "alt=" Favorites code "/>

    1. #!/bin/sh

    2. # chkconfig: 2345

    3. # Description:redis is a persistent key-value database

    4. #

Set it again to succeed.

Shell code 650) this.width=650; "class=" star "src=" Http://futeng.iteye.com/images/icon_star.png "alt=" Favorites code "/>

    1. #设置为开机自启动服务器

    2. Chkconfig REDISD on

    3. #打开服务

    4. Service REDISD Start

    5. #关闭服务

    6. Service REDISD Stop

This article is from the "Technical Achievement Dream" blog, please be sure to keep this source http://pizibaidu.blog.51cto.com/1361909/1674290

Three ways to start Redis

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.