Linux-nosql's Redis

Source: Internet
Author: User
Tags chmod memcached redis redis server

1.Redis Introduction

Redis is a key-value storage system. Similar to memcached, it supports storing more value types, including string (string), list (linked list), set (set), Zset (sorted set-ordered collection), and hash (hash type). These data types support Push/pop, Add/remove, and intersection-set and difference sets, and richer operations, and these operations are atomic. Based on this, Redis supports sorting in a variety of different ways. As with memcached, data is cached in memory to ensure efficiency. The difference is that Redis periodically writes the updated data to disk or writes the modified operation to the appended record file, and Master-slave (Master-Slave) synchronization is implemented on this basis.

Redis is a high-performance Key-value database.

2.Redis Installation

Cd/usr/local/src

$ wget http://download.redis.io/releases/redis-2.8.21.tar.gz$ tar xzf redis-2.8.21.tar.gz$ cd redis-2.8.21$ make

wget http://download.redis.io/releases/redis-2.8.21.tar.gz

Make Prefix=/usr/local/redis Install

Mkdir/usr/local/redis/etc

Cp/usr/local/src/redis-2.8.21/redis.conf/usr/local/redis/etc

wget Http://www.apelearn.com/study_v2/.redis_conf-O/usr/local/redis/etc/redis.conf 2>/dev/null

Update==>

Startup scripts

wget Http://www.apelearn.com/study_v2/.redis_init-O/etc/init.d/redis 2>/dev/null

Useradd-s/sbin/nologin Redis

Mkdir/usr/local/redis/var

chmod 777/usr/local/redis/var

chmod 755/etc/init.d/redis

3. Start Redis

Vi/etc/init.d/redis #编辑, add the following code

#!/bin/sh

# chkconfig:2345 90 10

# Description:redis is a persistent key-value database

# redis Startup script for Redis processes

# Processname:redis

Redis_path= "/usr/local/bin/redis-server"

redis_conf= "/etc/redis.conf"

Redis_pid= "/var/run/redis.pid"

# Source function library.

. /etc/rc.d/init.d/functions

[-X $redis _path] | | Exit 0

Retval=0

Prog= "Redis"

# Start Daemons.

Start () {

If [-e $redis _pid-a!-Z $redis _pid];then

Echo $prog "already running ..."

Exit 1

Fi

Echo-n $ "Starting $prog"

# Instance for all caches

$redis _path $redis _conf

Retval=$?

[$RETVAL-eq 0] && {

touch/var/lock/subsys/$prog

Success $ "$prog"

}

Echo

Return $RETVAL

}

# Stop Daemons.

Stop () {

Echo-n $ "Stopping $prog"

killproc-d $redis _path

Echo

[$RETVAL = 0] && rm-f $redis _pid/var/lock/subsys/$prog

Retval=$?

Return $RETVAL

}

# See how we were called.

Case "$" in

Start

Start

;;

Stop

Stop

;;

Status

Status $prog

Retval=$?

;;

Restart

Stop

Start

;;

Condrestart)

if test "x ' pidof redis '"! = x; Then

Stop

Start

Fi

;;

*)

echo $ "Usage: $ {Start|stop|status|restart|condrestart}"

Exit 1

Esac

Exit $RETVAL

: wq! #保存退出

chmod 755/etc/init.d/redis #添加脚本执行权限

Chkconfig--add Redis #添加开启启动

Chkconfig--level 2345 Redis on #设置启动级别

Chkconfig--list Redis #查看启动级别

Service Redis Restart #重新启动redis

System operation and maintenance www.osyunwei.com warm reminder: qihang01 original content copyright, reproduced please indicate the source and the original link

4. Setting Redis profile Parameters

Mkdir-p/usr/local/redis/var #创建redis数据库存放目录

Vi/etc/redis.conf #编辑

Daemonize Yes #以后台daemon方式运行redis

Pidfile "/var/run/redis.pid" #redis以后台运行, default PID file path/var/run/redis.pid

Port 6379 #默认端口

Bind 127.0.0.1 #默认绑定本机所有ip地址, in order to be safe, can only listen to intranet IP

Timeout #客户端超时设置, unit of seconds

LogLevel verbose #设置日志级别, supports four levels: debug, notice, verbose, warning

LogFile stdout #日志记录方式, default to standard output, logs not write file, output to empty device/deb/null

LogFile "/usr/local/redis/var/redis.log" #可以指定日志文件路径

Databases #开启数据库的数量

Save 900 1

Save 300 10

Save 60 10000

Create a local database snapshot, format: Save * *

1 write operations in 900 seconds

10 write operations in 300 seconds

10,000 write operations in 60 seconds

Rdbcompression Yes #启用数据库lzf压缩, can also be set to No

Dbfilename Dump.rdb #本地快照数据库名称

Dir "/usr/local/redis/var/" #本地快照数据库存放目录

Requirepass 123456 #设置redis数据库连接密码

MaxClients 10000 #同一时间最大客户端连接数, 0 for unrestricted

MaxMemory 1024MB #设定redis最大使用内存, the value is less than the physical memory and must be set

AppendOnly Yes #开启日志记录, equivalent to MySQL's Binlog

Appendfilename "Appendonly.aof" #日志文件名, note: Not a directory path

Appendfsync everysec #每秒执行同步, there are two parameters always, no is generally set to everysec, the equivalent of the MySQL thing log writing method

: wq! #保存退出

Service Redis Restart #重启

5. Test Redis Database

Redis-cli-a 123456 #连接redis数据库, note:-A followed by a Redis database password

Set name Osyunwei.com #写数据

Get name #读取数据

Exit #退出redis数据库控制台

Redis-benchmark-h 127.0.0.1-p 6379-c 1000-n 100000 #1000个并发连接, 100,000 requests, testing Redis server performance with 127.0.0.1 Port 6379

Linux-nosql's 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.