Linux Centos7 installing Redis

Source: Internet
Author: User
Tags benchmark redis server

First look at the official tutorial: Http://redis.io/download

Download, extract and compile Redis with:

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

The binaries that is now compiled is available in the src directory. Run Redis with:

$ src/redis-server

You can interact with Redis using the built-in client:

$ src/redis-cliredis> set foo barOKredis> get foo"bar"
Place the compressed package in/usr/local/redis, do the above, and note that the make install is not executed

Make failed to report GCC error, requires installation of Gcc:yum install GCC
Error error:jemalloc/jemalloc.h:no such file or directory, execute the following statement
Make MALLOC=LIBC

Configuration:

Cd/usr/local/bin #查看是否有下面文件, if not, copy the following file to the/usr/local/bin directory

CD/USR/LOCAL/REDIS/REDIS-3.2.1/SRC Copy the following execution script to/usr/local/bin

Cp-p Redis-server/usr/local/bin

Cp-p Redis-benchmark/usr/local/bin

Cp-p Redis-cli/usr/local/bin

Cp-p Redis-check-dump/usr/local/bin

Cp-p Redis-check-aof/usr/local/bin

Ln-s/usr/local/redis/redis.conf/etc/redis.conf #添加配置文件软连接

Vi/etc/redis.conf #编辑

Daemonize Yes #设置后台启动redis, the default is no in the configuration file

: wq! #保存退出

Redis-server/etc/redis.conf #启动redis服务

REDIS-CLI shutdown #关闭redis

Vi/etc/sysctl.conf #编辑, add the following code to the last line

Vm.overcommit_memory = 1

: wq! #保存退出

Sysctl-p #使设置立即生效

4. Set up Redis boot

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

#!/bin/SH# Chkconfig:2345  - Ten# Description:redis is a persistent key-value database# redis Startup script forRedis processes# Processname:redisredis_path="/usr/local/bin/redis-server"redis_conf="/etc/redis.conf"Redis_pid="/var/run/redis.pid"# SourcefunctionLibrary:/etc/rc.d/init.d/functionstest-X $redis _path | | Exit0RETVAL=0Prog="Redis"# Start Daemons.start () {ifTEST-E $redis _pid-a! -Z $redis _pid; Then        Echo$prog"already running ...."Exit1    fi    Echo-N $"starting $prog"# Single Instance forAll caches $redis _path $redis _conf RETVAL=$?Test $RETVAL-eq0&& {        Touch/var/lock/subsys/$prog Success $"$prog"    }    Echoreturn $RETVAL}# Stop daemons.stop () {Echo-N $"stopping $prog"Killproc-DTen$redis _pathEchoTest $RETVAL=0&&RM-F $redis _pid/var/lock/subsys/$prog RETVAL=$?return $RETVAL}# See how we were called. Case " $" inchstart) Start; stop) stop;; Status) status $prog RETVAL=$?;; restart) stop start;; Condrestart)ifTest"x ' pidof redis '"! = x; ThenStop Startfi;;*)    Echo$"Usage: $ {Start|stop|status|restart|condrestart}"Exit1    EsacExit $RETVA

: 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.111cn.net warm reminder: qihang01 original content copyright, reproduced please indicate the source and the original link

5. 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 #重启

6. Test Redis Database

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

Set name 111cn.net #写数据

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 Centos7 installing 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.