In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "how to install Redis with yum under CentOS7". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to install Redis with yum under CentOS7.
(1) Overview of Redis
Redis is an open source log, Key-Value (key) database (non-relational database) that is written in ANSI C language, supports the network, can be based on memory and can be persisted, and provides API in multiple languages.
Redis is a high-performance Key-Value database. The emergence of it largely compensates for the deficiency of Key- value-based storage such as Memc++ached, and can play a good complementary role to relational database in some cases. It provides clients such as Java, PHP, JavaScript, Perl, Object-C, Python, Ruby, Erlang, etc., which are easy to use.
Redis supports master-slave synchronization, and Redis can monitor master-slave nodes with the help of Sentinel (Sentinel, Redis). When the master node fails, it will promote another slave node to become a new master node.
1) supported data types
Similar to Memcached, but it supports relatively more Value types for storage, including String (string), List (list), Sets (collection), Sorted
Sets (ordered set) and Hash (hash type, associative array), Bitmaps (bitmap) and HyperLoglog.
2) performance
1 million smaller key storage strings that consume about 100m of memory
Because Redis is single-threaded, if there are multiple CPU on the server host, only one can be used, but that does not mean that CPU will become a bottleneck, because Redis is a relatively simple Kmuri V data store, CPU usually will not become a bottleneck.
On common linux servers, the concurrency of 500K (500000) only needs to be processed in one second. If the host hardware is good, it can reach millions of concurrency per second.
3) comparison between Redis and Memcache
Memcache can only use memory to cache objects. In addition to using memory to cache objects, Redis can also periodically save the data to disk and store the data permanently. When the server suddenly loses power or crashes
Redis recovers based on data on disk
Redis is a single-threaded server with only one thread responding to all requests. Memcache is multithreaded
Redis supports more data types.
(2)。 Installation
When yum installs redis, it is recommended to use Remi
Repository source. Because the Remi source provides the latest version of Redis, you can use YUM to install the latest version of Redis from this source. It also provides the latest yum sources for PHP and MySQL, as well as related services.
1) the Remi repository source depends on the epel source, so you need to install the epel source first
one
[root@youxi1 ~] # yum-y install
Epel-release
2) install Remi repository source
one
two
three
four
five
six
seven
[root@youxi1 ~] # yum-y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
[root@youxi1 ~] # ls
/ etc/yum.repos.d/ after the download is completed, there will be many yum sources for remi. Remi.repo will be used here.
CentOS-Base.repo CentOS-Sources.repo remi-glpi92.repo
Remi-php70.repo remi-safe.repo
CentOS-CR.repo CentOS-Vault.repo remi-glpi93.repo
Remi-php71.repo
CentOS-Debuginfo.repo epel.repo remi-glpi94.repo
Remi-php72.repo
CentOS-fasttrack.repo epel-testing.repo
Remi-modular.repo remi-php73.repo
CentOS-Media.repo remi-glpi91.repo remi-php54.repo
Remi.repo
3) install Redis using the specified yum source
one
two
three
[root@youxi1] # yum-- enablerepo=remi install-y
Redis / /-- enablerepo specifies the yum source
[root@youxi1 ~] # redis-cli
-- version / / use the command to check the version after the installation is complete
Redis-cli
5.0.5
Note: after the installation of the remi source is completed, the default is not to start, and remi is used when required.
When the repository source installer is installed, the requirements-enablerepo=remi option specifies the use of remi
The repository source can be used and then installed.
4) start Redis and set self-boot
one
two
three
[root@youxi1 ~] # systemctl start
Redis
[root@youxi1 ~] # systemctl enable
Redis
Created symlink from / etc/systemd/system/multi-user.target.wants/redis.service
To
/ usr/lib/systemd/system/redis.service.
Note: the port number of Redis is 6379
(3)。 Profile Information
Under Linux, the configuration file for Redis is stored in redis.conf in the / etc/ directory. List the parameters that may be used as follows:
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen
sixteen
seventeen
eighteen
nineteen
twenty
twenty-one
twenty-two
twenty-three
twenty-four
twenty-five
twenty-six
twenty-seven
twenty-eight
twenty-nine
thirty
thirty-one
thirty-two
thirty-three
thirty-four
thirty-five
thirty-six
thirty-seven
thirty-eight
thirty-nine
forty
forty-one
forty-two
forty-three
forty-four
forty-five
forty-six
forty-seven
forty-eight
forty-nine
fifty
fifty-one
fifty-two
fifty-three
fifty-four
fifty-five
fifty-six
fifty-seven
fifty-eight
fifty-nine
sixty
sixty-one
sixty-two
sixty-three
sixty-four
sixty-five
sixty-six
sixty-seven
sixty-eight
sixty-nine
seventy
seventy-one
seventy-two
seventy-three
seventy-four
seventy-five
seventy-six
seventy-seven
seventy-eight
seventy-nine
eighty
eighty-one
eighty-two
eighty-three
eighty-four
eighty-five
eighty-six
eighty-seven
eighty-eight
eighty-nine
ninety
ninety-one
ninety-two
ninety-three
/ / Line 69, the address of the Redis monitor
Bind 127.0.0.1
/ / Line 88, security mode, whether to disable public network access Redis,yes means enabled, and can only be accessed locally
Protected-mode yes
/ / Line 92, the port number of the monitor
Port 6379
/ * Line 101, specify the tcp-backlog length. Tcp-backlog is a waiting queue.
*
When a large number of requests need to be processed by Redis, the request queues that need to wait are cached through backlog.
* the number of backlog determines the number of queues that can be cached
, /
Tcp-backlog 511
Line 109, specifying the use of sock file communication and the sock file location. If the server and client are on the same host, it is recommended to open it. Sock communication can be exchanged directly in memory without going through the TCP/IP protocol stack for encapsulation and unpacking.
# unixsocket / tmp/redis.sock
/ / Line 110, defining the permissions of the sock file
# unixsocketperm 700
Line 113 indicates how long the client has been idle and timed out (inactive, no data interaction) after the client has successfully connected. 0 indicates that this feature is not enabled
Timeout 0
/ / Line 130, the time to maintain a long link (in seconds)
Tcp-keepalive 300
Line 136, whether to run the daemon in the background. If you start with a redis service script, a daemon runs even if it is no. General setting yes
Daemonize no
Line 147, whether upstart or systemd will take over the redis process. By default, there is no supervised interaction and no modification is required.
Supervised no
/ / Line 158, pid file address
Pidfile / var/run/redis_6379.pid
/ / Line 166, log level
Loglevel notice
/ / Line 174, log file location
Logfile / var/log/redis/redis.log
Line 186, the number of databases by default. But in a distributed environment, there can only be one
Databases 16
/ * Line 218 to 220, snapshot storage strategy, persistence strategy for saving to disk
* the first number is the unit time in seconds, and the second number is the number of times the key value has changed.
* for example, if the first key value changes at least once in 900 seconds, take a snapshot (persistence)
* the second is to take a snapshot (persistence) if the key value changes at least 10 times in 300 seconds.
* all conditions are juxtaposed, and use rules are selected according to different key values.
, /
Save 900 1
Save 300 10
Save 60 10000
/ / Line 235, when making a snapshot backup, the default yes can be used if an error occurs and whether to stop.
Stop-writes-on-bgsave-error yes
Line 241, which specifies whether the RDB file is compressed. Yes means compression, which consumes CPU resources.
Rdbcompression yes
/ * Line 250, whether to check the check code for the RDB file.
* this item defines whether the check code for the file is checked when the RDB file is loaded when redis starts, the check information is generated when the RDB file is generated by redis, and whether the check information is detected when redis starts or loads the RDB file again.
* if the detection takes time, it will cause the redis to start slowly, but you can judge whether the RDB file has an error.
, /
Rdbchecksum yes
/ / Line 253, RDB file name
Dbfilename dump.rdb
/ / Line 263, the path where the RDB file is stored
Dir / var/lib/redis
/ / Line 286, which defines the IP and port of the Master server and the configuration information of master-slave replication
# replicaof
/ / Line 293, which defines the password of the Master server and the configuration information of master-slave replication
# masterauth
Line 308, when the slave disconnects from the master during master-slave replication, yes means to continue to provide services, even though the data may not be up-to-date; no indicates that an error message is returned for the request
Replica-serve-stale-data yes
/ / Line 324, read-only from the end
Replica-read-only yes
/ / Line 355. Diskless (no disk) synchronization is not used by default.
Repl-diskless-sync no
/ / Line 367, there will be a delay before data transfer in diskless (diskless) mode, so that the client can proceed to the destination queue to be transferred. Default is 5 seconds.
Repl-diskless-sync-delay 5
/ / Line 373, the interval between sending ping from the end to the master. Default is 10 seconds.
# repl-ping-replica-period 10
/ / Line 385, set the timeout
# repl-timeout 60
/ * Line 400, whether to enable TCP_NODELAY.
* if enabled, a small amount of TCP packets and bandwidth will be used for data transfer to the slave end, which is slow.
* if it is not enabled, more bandwidth is used for data transmission, which is faster.
, /
Repl-disable-tcp-nodelay no
/ * Line 413, set the size of backlog. Backlog is a buffer that stores data to be synchronized to the slave side when the slave side is lost.
*
Therefore, when reconnecting from the slave end, there is generally no need for full synchronization. The larger the backlog, the longer it takes to lose contact from the end (relatively speaking)
, /
# repl-backlog-size 1mb
Line 426, after a period of time, the slave side is not connected to the master, then the memory of the backlog (buffer) will be freed. 0 means never release. Default is 3600 seconds.
# repl-backlog-ttl 3600
Line 441, from the priority setting of the slave end, the smaller the number, the higher the priority. The master failure is recovered according to the high priority slave. If 0 is set, the slave will never be selected
Replica-priority 100
Lines 457 to 458, when the number of available slaves on the master side is less than 3 or the network delay island is 10 seconds, the master side refuses to receive the user's write request.
# min-replicas-to-write 3
# min-replicas-max-lag 10
/ / Line 507, specify the authentication password and do not start by default
# requirepass foobared
/ / Line 539, and the maximum number of simultaneous connections to redis
# maxclients
10000
Pay special attention to: bind on line 69, protected-mode on line 88, daemonize on line 136, maxclients on line 539, and all configuration parameters copied from the master and slave.
(4) simple use of .redis
The easiest to use: redis-cli-h [IP address]-p
[Port number]. If the connection is local, both-h and-p can be omitted.
1) Reids string operation
Key naming rules: you can use ASCII characters; the length of the key is not too long, the longer the length of the key, the more space consumed; in the same library (namespace), the name of the key must not be repeated, if you copy the name of the key, it is actually to modify the value in the key; in different libraries (namespaces), multiple names of the key can be repeated; the key can automatically expire.
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
[root@youxi1 ~] # redis-cli
127.0.0.1 purl 6379 > set system
Centos / / create key value
OK
127.0.0.1 6379 > get system / / get key value
"centos"
127.0.0.1 purl 6379 > exit
[root@youxi1 ~] # systemctl restart
Redis / / restart
[root@youxi1 ~] # redis-cli
127.0.0.1 6379 > get system / / you can see that the key value exists
"centos"
127.0.0.1 EX 6379 > set name "youxi"
10 / / if set like this, it means that the key value exists for 10 seconds
OK
127.0.0.1 get name 6379 > check again after 10 seconds. This is a temporary key value.
(nil)
2) if the authentication function is enabled
First, modify the configuration file to enable the authentication function.
one
two
three
[root@youxi1 ~] # vim / etc/redis.conf
Requirepass 123456 / / on line 507, remove comments and set authentication password
[root@youxi1 ~] # systemctl restart
Redis
Use redis again at this time
one
two
three
four
five
six
seven
[root@youxi1 ~] # redis-cli
127.0.0.1 get system 6379 > if there is no authentication, an error will be reported
(error) NOAUTH Authentication
Required.
127.0.0.1 6379 > auth 123456 / / Authentication
OK
127.0.0.1 get system 6379 > after authentication, get the key value again, which is successful
"centos"
(5)。 Configuration persistence
When Redis works, all data sets are stored in memory. If the Redis crashes or power goes down, all data will be lost, so Redis provides persistence to ensure the reliability of the data. There are two ways to implement Redis persistence: RDB and AOF.
RDB: data files stored in binary format, which is the persistence mechanism started by default; data is saved to disk periodically according to a pre-customized strategy.
AOF:Append Only File is similar to MySQL's binary log, which records every redis write command and appends it to the end of the specified file in a sequential IO manner. It is implemented by appending, which is also called a persistence mechanism of additional log types. Because each operation is recorded, the capacity of the file increases over time, and some recorded commands are redundant. However, the redis process can automatically scan the corresponding AOF file and merge some redundant operations into one, so as to restore the data at one time in the future.
In fact, the configuration of RDB has been explained above. I will copy it again here, as follows. There are only six configuration points in total.
one
two
three
four
five
six
seven
eight
nine
ten
eleven
twelve
thirteen
fourteen
fifteen
sixteen
seventeen
eighteen
nineteen
twenty
twenty-one
twenty-two
twenty-three
/ *
* Line 218 to 220, snapshot storage strategy, persistence strategy for saving to disk
* the first number is the unit time in seconds, and the second number is the number of times the key value has changed.
* for example, if the first key value changes at least once in 900 seconds, take a snapshot (persistence)
* the second is to take a snapshot (persistence) if the key value changes at least 10 times in 300 seconds.
* all conditions are juxtaposed, and use rules are selected according to different key values.
, /
Save 900 1
Save 300 10
Save 60 10000
/ / Line 235, when making a snapshot backup, the default yes can be used if an error occurs and whether to stop.
Stop-writes-on-bgsave-error yes
Line 241, which specifies whether the RDB file is compressed. Yes means compression, which consumes CPU resources.
Rdbcompression yes
/ * Line 250, whether to check the check code for the RDB file.
* this item defines whether the check code for the file is checked when the RDB file is loaded when redis starts, the check information is generated when the RDB file is generated by redis, and whether the check information is detected when redis starts or loads the RDB file again.
* if the detection takes time, it will cause the redis to start slowly, but you can judge whether the RDB file has an error.
, /
Rdbchecksum yes
/ / Line 253, RDB file name
Dbfilename dump.rdb
/ / Line 263, the path where the RDB file is stored
Dir / var/lib/redis
At this point, I believe you have a deeper understanding of "how to install Redis with yum under CentOS7". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.