1. Installation
TARXF redis-3.2.5.tar.gz
CD redis-3.2.5
Make
Mkdir-p/usr/local/redis/bin
The files under the SRC directory function as follows
Redis-server:redis Server Daemon Startup program
Redis-cli:redis command-line operation tool. You can also use Telnet to operate on its plain text protocol
Redis-benchmark:redis Performance Testing tool to test the read and write performance of Redis in your system and in your configuration.
CP Redis-benchmark redis-check-aof REDIS-CLI redis-server/usr/local/redis/bin/
Mkdir-p/usr/local/redis/conf
CP redis.conf/usr/local/redis/conf
Vim/usr/local/redis/etc/redis.conf
Modifying a configuration file
daemonize No change to Daemonize Yes// whether to put Redis-server start in the background, default is " No " . If you change to Yes, a PID file is generated
bind 127.0.0.1 change to bind 0.0.0.0// accessible to any host
Other look needs to be modified
Pkill Redis
Make a connection
Ln-s/usr/local/redis/bin/*/usr/local/bin
Start the service
Redis-server/usr/local/redis/conf/redis.conf
To see if it starts:
NETSTAT-ANPT |grep Redis
TCP 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 46390/redis-serve
After the Redis boot succeeds, the following warning message will appear at the end:
WARNING Overcommit_memory isSetTo0! BackgroundSave may failUnderLowMemory condition.To fix this issueAdd' Vm.overcommit_memory = 1 'To/etc/sysctl.confandThen rebootor run the command ' sysctl vm.overcommit_memory=1 '
So we do a bit of processing after starting the Redis process
[[email protected] redis-2.8.9]# pkill redis[[email protected] redis-2.8.9]# sysctl vm.overcommit_memory=1vm.overcommit_memory = 1再启动 redis-server /usr/local/redis/conf/redis.conf &
After processing, there is no warning to start Redis again.
Vm.overcommit_memory parameter Description:
According to the kernel document, this parameter has three values, namely:
0: When the user space requests more memory, the kernel attempts to estimate the remaining available memory.
1: When set to this parameter value of 1 o'clock, the kernel allows excessive use of memory until the end of use, mainly for scientific calculation
2: When set this parameter value is 2 o'clock, the kernel will use an algorithm that never overuse memory, that is, the whole memory address space of the system cannot exceed swap+50% 's RAM value, and the 50% parameter setting is set in Overcommit_ratio.
redis-cli shutdown
Close the Redis process
2. Working with the Redis database through the client
Let's take a quick look at the database. Insert data: Set a Key-value pair
[Email protected] redis-2.8.9]#REDIS-CLI #通过客户端连接本地Redis 127.0.0.1:6379>SetID 001 #写入一条数据KeyID),Value (001)OK127.0.0.1:6379>GetID #取值KeyID) "001" #显示Key corresponds to a value of 127.0.0.1:6379>DelID #删除KeyID) (Integer) 1#1表示成功127.0.0.1:6379>ExistsID #验证If key exists (Integer) 0#0表示不存在127.0.0.1:6379>GetID #取The value of key (Nil) #报错信息127.0.0.1:6379>Setuser001BenetOK127.0.0.1:6379>Setuser002YunjisuanOK127.0.0.1:6379>Setuser003Yun123OK127.0.0.1:6379>get user001 " Benet "127.0.0 .1:6379> get user002 " Yunjisuan "127.0.0 .1:6379> keys * #查看 redis All key1) "user003" 2) "user002" 3) " user001 "
REDIS-CLI Client remote connection and non-interactive operation database
[Email protected] redis-2.8.9]#Redis-cli-H 10.0.0.135-P 637910.0.0.135:6379>quit[[email protected] redis-2.8.9]# redis-cli -h 10.0< Span class= "Hljs-selector-class" >.0.135 -p 6379 set aaa 111OK< Span class= "hljs-selector-attr" >[[email protected] redis-2.8.9]# redis-cli Span class= "Hljs-selector-tag" >-h 10.0.0< Span class= "Hljs-selector-class" >.135 -p 6379 get Span class= "Hljs-selector-tag" >AAA "111"
You can also connect to the Redis database via Telnet
telnet 10.0.0.135 6379
3.redis Security
(1) Setting external link passwords for Redis clients
Warning: because Redis is very fast, an external user can make tens of thousands of password attempts in 1 seconds under a better server, which means you need to specify a very strong password to prevent brute force.
[Email protected] redis-2.8.9]# grep-n requirepass/usr/local/redis/conf/redis.conf #修改redis配置文件, add password198:# If The master is password protected (using the "Requirepass" configuration339:# requirepass Foobared[[email protected] redis-2.8. 9]# sed-i ' 339 [email protected]# requirepass foobared@requirepass yunjisuan@g ' #密码是yunjisuan/usr/local/ Redis/conf/redis.conf[[email protected] redis-2.8. 9]# grep-n requirepass/usr/local/redis/conf/redis.conf 198:# If The master is password protected (US ing the "requirepass" Configuration339: Requirepass Yunjisuan
Restart Redis Post Test
#重启redis进程 [[Email protected] redis-2.8.9]# Ps-ef | grep Redis | Grep-v Greproot34421288013:pts/000:00:Redis-server *:6379 [[Email protected] redis-2.8.9]# REDIS-CLI shutdown[3442]The OCT18:17:03.370# User requested shutdown ... [3442]The OCT18:17:03.370 * Saving the final RDB snapshot before exiting. [3442]The OCT18:17:03.380 * DB saved on disk[3442]The OCT18:17:03.380# Redis is now ready to exit, Bye bye ... [1]+ done Redis-server/usr/local/redis/conf/redis.conf[[email protected] redis-2.8.9]# Ps-ef | grep Redis | Grep-v Grep[[email protected] redis-2.8.9]# redis-server/usr/local/redis/conf/redis.conf &[[email protected] redis-2.8.9]# Ps-ef | grep Redis | Grep-v Greproot38431288018:pts/000:00:Redis-server *:6379#测试验证效果#第一种登陆验证方式 [[Email protected] redis-2.8.9]# REDIS-CLI #登陆本地redis127.0.0.1:6379> Set Name3333#存数据 (Error) Noauth authentication required.#没有验证权限127.0.0.1:6379> keys *#查看所有key (Error) Noauth authentication required.#没有验证权限127.0.0.1:6379> Auth Yunjisuan#提交验证密码OK#验证通过127.0.0.1:6379> keys *#查看所有keys1) "user003" 2) "AB" 3) "user002" 4) "AAA" 5) "user001" #第二种登录验证方式 [[email protected] Redis-2.8. 9]# redis-cli-a Yunjisuan #登陆时提交密码 127.0.0.1:6379> keys *1) "user003" 2) "AB" 3) "user002" 4) "AAA" 5) "user001"
Special Note: Redis does not have a user concept, only the connection password can be set, and the Redis connection is very fast. So the password needs to be set up very complex to be safe.
Installation and configuration of the Redis cache database (1)