Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Installation and simple Application of redis

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

1. System environment: centos7.2-x861564

[root@salt1 ~] # cat / etc/centos-release

CentOS Linux release 7.2.1511 (Core)

[root@salt1] # uname-a

Linux salt1 3.10.0-327.el7.x86_64 # 1 SMP Thu Nov 19 22:10:57 UTC 2015 x86 "64 GNU/Linux

two。 Install redis

Prerequisites: install epel-release (epel source) first

[root@salt1 ~] # yum-y install epel-release

Then install redis

[root@salt1 ~] # yum-y install redis

[root@salt1] # rpm-Q redis

Redis-2.8.19-2.el7.x86_64

[root@salt1 ~] # redis-

Redis-benchmark redis-check-aof redis-check-dump redis-cli redis-sentinel redis-server redis-shutdown

Daemon launcher for redis-server:redis server

Redis-cli: redis command line client operation tool, which can also be operated with telnet according to its plain text protocol.

Redis-benchmark:redis performance testing tool to test the read and write performance of redis on your system and your configuration

Redis-check-aof: for update log appendonly.conf check, whether it is available, similar to the tool for checking mysql binlog

Redis-check-dump: for checking local database rdb files

3. Start the redis service

Back up the configuration file of redis first (personal habit, backup before operation)

[root@salt1 ~] # cp / etc/redis.conf {, .bak}

It is best to specify its configuration file when redis starts, because almost all the control of redis is in its configuration file.

Redis-server: daemon launcher for redis server

/ etc/redis.conf: configuration file for redis

&: start in the background

[root@salt1 ~] # redis-server / etc/redis.conf &

[1] 9462

[root@salt1 ~] # ps-ef | grep redis

Root 9462 2767 0 03:59 pts/0 00:00:00 redis-server 127.0.0.1:6379

Root 9466 2767 0 03:59 pts/0 00:00:00 grep-color=auto redis

Then take a look at the log.

[root@salt1] # tail-30 / var/log/redis/redis.log

[9462] 11 Aug 03 it was originally set to 59) 54.037 * Increased maximum number of open files to 10032.

_. _

_.-``_'-. _

_.-``` `_. '' -. _ Redis 2.8.19 (0000000 Redis 0) 64 bit

.-``.-```. ```\ / _, _'-. _

(',.-`|`,) Running in stand alone mode

| | `-. _` -.-`_ _.-.`` -. _ |'` _. -'| Port: 6379 |

| | `-. _`. _ / _. -'| PID: 9462 |

`-. _` -. _ `. /. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _ _. -'_. -'| http://redis.io |

`-. _` -. _ `. -'_. -'

| | `-. _ _. -'|

| | `-. _` -. _. -'_. -'|

`-. _` -. _ `. -'_. -'

`-. _`. _ _. -'_. -'

`-. _. -'

`-. _. -'

[9462] 11 Aug 03:59:54.038 # Server started, Redis version 2.8.19

[9462] 11 Aug 03:59:54.039 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory=1' to / etc/sysctl.conf and then reboot or run the command' sysctl vm.overcommit_memory=1' for this to take effect.

[9462] 11 Aug 03 support enabled in your kernel 59 support enabled in your kernel 54.039 # WARNING you have Transparent Huge Pages (THP). This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > / sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your / etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

[9462] 11 Aug 03:59:54.040 # WARNING: The TCP backlog setting of 511 cannot be enforced because / proc/sys/net/core/somaxconn is set to the lower value of 128.

[9462] 11 Aug 03 59 54 040 * The server is now ready to accept connections on port 6379

* * font is: problem

The red font is: solution

* * font explanation:

1. Background saving in low memory may fail

Vm.overcommit_memory parameter

Default value is 0

0: when user space requests more memory, the kernel tries to estimate the remaining available memory

1: the kernel allows overuse of memory until it is used up; mainly for scientific computing

2: the kernel uses an algorithm that never overuses memory, that is, the whole memory address space of the system cannot exceed the ram value of swap+50%, and the 50% parameter is set in overcommit_ratio.

two。 Enabled THP (page memory transparency) in your kernel specific explanation see the URL below, which explains http://os.51cto.com/art/201103/249821.htm in more detail.

3.tcp backlog set to 511 cannot be executed because / proc/sys/net/core/somaxconn is low

Backlog is the queue length of a certain state in the process of network connection. If the concurrency is high, the queue of backlog will be occupied, the server will lose other incoming connections, and then the client connection will fail.

Http://jingyan.baidu.com/article/84b4f565e60f8560f6da3227.html

So the corresponding operation will be performed at the bottom.

Note: the blue font is the place to pay attention to.

Echo "vm.overcommit_memory = 1" > > / etc/sysctl.confsysctl-p echo "echo never > / sys/kernel/mm/transparent_hugepage/enabled" > > / etc/rc.localecho "echo 511 > / proc/sys/net/core/somaxconn" > > / etc/rc.local

The following is a screenshot, which can be checked by partners who need to compare.

I believe that after the configuration of the above three lines, your redis will not report a similar warning. Of course, you also need to specify the amount of memory allowed by redis in the redis.conf file (described in the next chapter), otherwise your server will not last two days.

4. Turn off the redis service

1) redis-shutdown # will be closed after saving by default

2) redis-cli shutdown save #

5. Connect redis

[root@salt1 ~] # redis-cli

127.0.0.1purl 6379 >

6. Simple operation

127.0.0.1 6379 > set id 001 # create key-vlaue

OK

127.0.0.1 6379 > get id # find key

"001"

127.0.0.1 6379 > del id # Delete key

(integer) 1

127.0.0.1 purl 6379 > get id

(nil)

127.0.0.1 6379 > exists id # query whether id exists

(integer) 1

127.0.0.1 purl 6379 > del id

(integer) 1

127.0.0.1 purl 6379 > exists id

(integer) 0

127.0.0.1 6379 > keys * # get all key

127.0.0.1 6379 > set K1 v1

OK

127.0.0.1 6379 > set K2 v2

OK

127.0.0.1 6379 > set K3 v3

OK

127.0.0.1 6379 > keys * # get all key

1) "K2"

2) "K3"

3) "K1"

127.0.0.1 6379 > dbsize # get all key-value numbers

(integer) 3

Redis has 16 libraries by default, but it cannot be seen (how many libraries can be configured in redis.conf)

127.0.0.1 select 6379 > switch to the second library (count from 0)

OK

127.0.0.1 keys 6379 [1]

(empty list or set)

127.0.1 set name 6379 [1]

OK

127.0.0.1 keys 6379 [1]

1) "name"

127.0.1 select 6379 [1] >

OK

127.0.0.1 6379 > keys *

1) "K2"

2) "K3"

3) "K1"

127.0.0.1 6379 > select 15

OK

127.0.0.1 6379 > select 16

(error) ERR invalid DB index

All right, so much for the installation of redis.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report