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

CentOS 7.6 deployment of Redis database

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Brief introduction:

Redis is a key-value storage system. Similar to Memcached, it supports relatively more value types, including string (string), list (linked list), set (collection), zset (sorted set-ordered collection), and hash (hash type). These data types support push/pop, add/remove, and take intersection union and difference sets, and richer operations, and these operations are atomic. On this basis, redis supports a variety of different sorting methods. Like memcached, data is cached in memory for efficiency. The difference is that redis will periodically write updated data to disk or modify operations to additional record files, and on this basis to achieve master-slave (master-slave) synchronization.

Redis usage scenario

Login session storage: stored in redis, compared to memcached, data will not be lost.

Ranking / counter: for example, for some show projects, there are often some top anchors ranking. There are also some article reading technology, or the number of likes on Sina Weibo.

As a message queue: for example, celery uses redis as the middleman.

Current number of people online: or the previous show example, will show how many people are online in the current system.

Some commonly used data caching: for example, in our BBS forum, the section does not change often, but every time you visit the home page, you need to get it from mysql, which can be cached in redis without having to request the database every time.

Cache the first 200 articles or comments: if the average user browses the site and only browses some of the previous articles or comments, then the first 200 articles and the corresponding comments can be cached. If the user accesses more than that, he will access the database, and if there are more than 200 articles later, the previous articles will be deleted.

Friendship: Weibo's friendship is realized by redis.

Publish and subscribe function: can be used to do chat software.

Comparison between redis and memcached

Installation steps: 1. Get redis resources

Cd / usr/local

Wget http://download.redis.io/releases/redis-4.0.8.tar.gz

two。 Decompression

Tar xzvf redis-4.0.8.tar.gz

3. Compilation and installation

Cd redis-4.0.8

Make

Cd src

Make install PREFIX=/usr/local/redis

4. Move the configuration file to the installation directory

Cd.. /

Mkdir / usr/local/redis/etc

Mv redis.conf / usr/local/redis/etc

5. Configure redis to start in the background

Vim / usr/local/redis/etc/redis.conf

Change daemonize no to daemonize yes

6. Add redis to boot

Vim / etc/rc.local / / add content at the end:

/ usr/local/redis/bin/redis-server / usr/local/redis/etc/redis.conf # call the command to enable redis when booting

7. Turn on redis

/ usr/local/redis/bin/redis-server / usr/local/redis/etc/redis.conf

8. Set password 1. The first way (the current method of configuring redis passwords in linux is temporary, and the password will expire after redis restart)

(1) enter redis first. If redis is not enabled, you need to enable it first:

[root@test bin] # redis-cli-p 6379

127.0.0.1purl 6379 >

(2) check whether the current redis has set a password:

127.0.0.1 purl 6379 > config get requirepass

1) "requirepass"

2) "

(3) if there is no password as shown above, set the password now:

127.0.0.1 purl 6379 > config set requirepass abcdefg

OK

(4) if you check the current redis again, you will be prompted to need a password:

127.0.0.1 purl 6379 > config get requirepass

(error) NOAUTH Authentication required.

two。 The second way (permanent way)

Modify the redis.conf configuration:

Vim / usr/local/redis/etc/redis.conf piece

Requirepass password 12 words-set password

Note: online server password must be as complex as possible, otherwise it is very easy to get caught in the virus (I have encountered it), here to remind you!

Just restart redis after saving it

Common command

Redis-server / usr/local/redis/etc/redis.conf / / start redis

Pkill redis / / stop redis

Reference article:

1. Https://www.cnblogs.com/lauhp/p/8487029.html

2. Https://www.cnblogs.com/renshaoqi/p/10617238.html

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

Servers

Wechat

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

12
Report