Introduction to Redis and Redis installation under Linux (super detailed, fool-like tutorial)

Introduction to Redis

Redis ( Remote DicƟ onary Server ), the remote dictionary service.
Redis is a completely open source, BSD- compliant, high-performance key-value database written in C language.

 

BSD is the abbreviation of " Berkeley Software Distribution " , which means "Berkeley Software Distribution".
The BSD open source protocol is a protocol that gives users a lot of freedom. You can freely use it, modify the source code, or convert it to
The modified code is re-released as open source or proprietary software. BSD encourages code sharing, but the copyright of the code author needs to be respected.
Authorship. Because BSD allows users to modify and redistribute code, it also allows users to develop commercial software based on BSD code.
software, so BSD is a very friendly protocol for commercial integration.
Let’s first have an overall understanding of redis through an e-commerce business scenario.
1. Basic product information (name, price, manufacturer), stored in MySQL
2. Product additional information (description, details, comments), stored in MongoDB
3. Image information, stored in distributed file system
4. Search keywords, ES, Lucene , solr
5. Hotspot information, high frequency, and band characteristics are stored in redis
(1) For example, in early 2020, “mask” was a hot topic
(2) For example, around Valentine’s Day, “roses” and “chocolate” are hot messages.
The overall model diagram looks like this:

 

Features of redis

1. Single-threaded, Redis is single-threaded (using multiplexing technology, that is, one thread manages multiple connections), so
All individual operations in Redis are atomic. Multiple operations can also be guaranteed atomically by transactions (via MULTI and
EXEC instructions), so there is no need to consider the impact of concurrency at the redis level.
2. Extremely high performance, reading 110000/s and writing 81000/s (this result can only occur when the hardware meets the standards)
3. Rich data types: String, List , Hash , Set and Ordered Set
4. Support persistence
5. Support horizontal expansion (
redis can be clustered)
6. Rich features, redis also supports publish/subscribe , notifications, key expiration and other features
7. The maximum size of a single key and value of redis is 512M.

redis installation

1. No matter what you install, first configure Alibaba’s yum source! Remember to install wget through yum first . The following is for CentOS7

wget -O /etc/yum.repos.d/CentOS-Base.repo
http://mirrors.aliyun.com/repo/Centos-7.repo

2. Since redis is developed in C language, you need to download gcc before installing redis .

        Note: The default gcc version of Centos 7 is 4.8. Sometimes a higher version is required. Here is an example of upgrading to version 9.3.1.

        Just execute the following three commands respectively. There is no need to manually download the source code and compile it.

 1. Install centos-release-scl                                                                                

sudo yum install centos-release-scl

2. Install devtoolset. Note that if you want to install version 7, change it to devtoolset-7-gcc, and so on.

sudo yum install devtoolset-9-gcc*

3. Activate the corresponding devtoolset, so you can install multiple versions of devtoolset at one time. Use the following command to switch to the corresponding version when needed.

scl enable devtoolset-9 bash

4. Done, check the gcc version

gcc -v

3. Download the redis installation package. You can choose the stable version by yourself. Here we take version 6.0.8 as an example. The online download speed is slightly slower (you can also choose the offline download method) and you need to wait for about 6 minutes.

Online download method:

Specify download path:

cd /opt #进入opt目录
mkdir redis #创建redis目录

 I have already installed it. The above is just to show you the specific operation commands.

Online download: Go to the created redis directory cd /opt/redis

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

 I have already installed it. The above is just to show you the specific operation commands.

Offline download method:

4. After downloading, decompress and compile

Note: The offline download method requires the downloaded package to be uploaded to the specified path using tools such as XShell or MobaXterm (you can specify it yourself, usually uploaded to /opt/redis). If you are not familiar with it, you can directly download it online. The compressed package is very small. Download soon

tar xzf redis-6.0.8.tar.gz
cd redis-6.0.8
make

5. Install redis to the specified directory

make PREFIX=/usr/local/redis install
Note: PREFIX must be capitalized, and Linux will automatically create the /usr/local/redis directory for us
After executing the make command, the compiled redis service program redis-server will appear in the redis-6.0.8 directory, as well as the client program redis-cli for testing:

 

6. After installation, test it

     1. Start the redis service

redis-server #记得在/opt/redis/redis-6.0.8目录下执行该命令

2. At this time, you need to open another terminal to connect to the redis service

redis-cli #记得在/opt/redis/redis-6.0.8目录下执行该命令

 After connecting to the client, ping it. If it enters PONG normally, the connection is successful.

Note: The above method of starting the redis service is to start it in the foreground, which will put the terminal in a blocked state. It is recommended to start the redis server in the backend. This requires the help of the configuration file redis.conf located in the redis decompression directory . It is recommended to copy the configuration file to the redis installation directory

cp /redis.conf /usr/local/redis/ #在redis所在的压缩包目录下执行该命令

A brief description of redis.conf configuration
1. redis默认不是后台运行的,可以通过修改该配置项为yes,让
redis在后台运行
daemonize no
2. 当redis以守护进程方式运行时,redis会把pid写
入/var/run/redis_6379.pid文件中,也可以自己指定写入的位置
pidfile /var/run/redis_6379.pid
3. redis监听的端口
port 6379
4. 设置redis连接密码,如果配置了连接密码,则客户端在连接redis
时需要通过AUTH <passowrd> 命令来提供密码
requirepass foobared
5. 绑定的主机地址,目前这样的配置这意味着只有当前机器才能连
接redis服务
bind 127.0.0.1
如果设置bind为0.0.0.0则表示运行任何远程机器访问当前redis服务
Modify the redis.conf configuration file, enable background operation, set bind to 0.0.0.0 , and then start the redis service again.
When starting the redis service this time, you need to specify the location of the redis configuration file.
cd /usr/local/redis/ redis-server redis.conf

This time you can see that it is started in the background

Then use the redis client to connect to the redis service 

redis-cli -h 192.168.195.130 -p 6379 #记得在/usr/local/redis目录下执行该命令

Here -h 192.168.195.130 can specify your own IP address (provided that the bind of the redis.conf configuration file is changed to 0.0.0.0) -p is followed by the port of the redis service

The above is the introduction and installation of redis. If you have any questions during the installation process, you can leave a message in the comment area to discuss. Tutorials on Linux installation of JDK, tomcat, mybatis, nginx, etc. will be published later. Thank you for previewing

Guess you like

Origin blog.csdn.net/FebruaryQ/article/details/131301457