Linux系统之使用yum安装Redis数据库

2023-11-10 17:30:43 浏览数 (1)

一、redis介绍

1.redis解释

Redis(Remote Dictionary Server ),即远程字典服务,是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。

2.redis特点

1.性能极高 – Redis能读的速度是110000次/s,写的速度是81000次/s 。

2.丰富的数据类型

3.redis使用场景

代码语言:shell复制
1.缓存——热数据
2.分布式锁与单线程机制
3.队列
4.排行榜

二、检查系统版本

1.检查系统版本

代码语言:shell复制
[root@server ~]# cat /etc/os-release 
NAME="CentOS Linux"
VERSION="7 (Core)"
ID="centos"
ID_LIKE="rhel fedora"
VERSION_ID="7"
PRETTY_NAME="CentOS Linux 7 (Core)"
ANSI_COLOR="0;31"
CPE_NAME="cpe:/o:centos:centos:7"
HOME_URL="https://www.centos.org/"
BUG_REPORT_URL="https://bugs.centos.org/"

CENTOS_MANTISBT_PROJECT="CentOS-7"
CENTOS_MANTISBT_PROJECT_VERSION="7"
REDHAT_SUPPORT_PRODUCT="centos"
REDHAT_SUPPORT_PRODUCT_VERSION="7"

2.检查内核版本

代码语言:shell复制
[root@server ~]# uname -r 
3.10.0-957.21.3.el7.x86_64

三、检查yum仓库状态

检查yum仓库是否配置,可以使用阿里的仓库源配置。

代码语言:shell复制
[root@server ~]# yum repolist all |grep  enable
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
!appnode/x86_64                      AppNode's RPM repository fo enabled:  4,266
!appnode-agent/x86_64                AppNode Agent Repository -  enabled:    332
!appnode-ccenter/x86_64              AppNode CCenter Repository  enabled:     71
!appnode-extras/x86_64               AppNode Extras Repository - enabled:     88
!base/7/x86_64                       CentOS-7 - Base - mirrors.a enabled: 10,072
!docker-ce-stable/7/x86_64           Docker CE Stable - x86_64   enabled:    169
!epel/x86_64                         Extra Packages for Enterpri enabled: 13,735
!extras/7/x86_64                     CentOS-7 - Extras - mirrors enabled:    515
!updates/7/x86_64                    CentOS-7 - Updates - mirror enabled:  4,300

四、查看系统默认提供的redis版本

代码语言:shell复制
[root@server ~]# yum info redis
Loaded plugins: fastestmirror
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Available Packages
Name        : redis
Arch        : x86_64
Version     : 3.2.12
Release     : 2.el7
Size        : 544 k
Repo        : epel/x86_64
Summary     : A persistent key-value database
URL         : http://redis.io
License     : BSD
Description : Redis is an advanced key-value store. It is often referred to as a data
            : structure server since keys can contain strings, hashes, lists, sets and
            : sorted sets.
            : 
            : You can run atomic operations on these types, like appending to a string;
            : incrementing the value in a hash; pushing to a list; computing set
            : intersection, union and difference; or getting the member with highest
            : ranking in a sorted set.
            : 
            : In order to achieve its outstanding performance, Redis works with an
            : in-memory dataset. Depending on your use case, you can persist it either
            : by dumping the dataset to disk every once in a while, or by appending
            : each command to a log.
            : 
            : Redis also supports trivial-to-setup master-slave replication, with very
            : fast non-blocking first synchronization, auto-reconnection on net split
            : and so forth.
            : 
            : Other features include Transactions, Pub/Sub, Lua scripting, Keys with a
            : limited time-to-live, and configuration settings to make Redis behave like
            : a cache.
            : 
            : You can use Redis from most programming languages also.

五、安装redis

1.安装redis

开始安装redis。

代码语言:shell复制
[root@server ~]# yum install -y redis
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
appnode                                                                                                                     | 3.0 kB  00:00:00     
appnode-agent                                                                                                               | 2.9 kB  00:00:00     
appnode-ccenter                                                                                                             | 2.9 kB  00:00:00     
appnode-extras                                                                                                              | 2.9 kB  00:00:00     
base                                                                                                                        | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                            | 3.5 kB  00:00:00     
epel                                                                                                                        | 4.7 kB  00:00:00     
extras                                                                                                                      | 2.9 kB  00:00:00     
updates                                                                                                                     | 2.9 kB  00:00:00     
(1/5): epel/x86_64/group_gz                                                                                                 |  98 kB  00:00:00     
(2/5): epel/x86_64/updateinfo                                                                                               | 1.0 MB  00:00:00     
(3/5): docker-ce-stable/7/x86_64/primary_db                                                                                 |  87 kB  00:00:00     
(4/5): updates/7/x86_64/primary_db                                                                                          |  17 MB  00:00:01     
(5/5): epel/x86_64/primary_db                                                                                               | 7.0 MB  00:00:01     
Resolving Dependencies
--> Running transaction check
---> Package redis.x86_64 0:3.2.12-2.el7 will be installed
--> Processing Dependency: libjemalloc.so.1()(64bit) for package: redis-3.2.12-2.el7.x86_64
--> Running transaction check
---> Package jemalloc.x86_64 0:3.6.0-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================================
 Package                           Arch                            Version                                  Repository                        Size
===================================================================================================================================================
Installing:
 redis                             x86_64                          3.2.12-2.el7                             epel                             544 k
Installing for dependencies:
 jemalloc                          x86_64                          3.6.0-1.el7                              appnode                          107 k

Transaction Summary
===================================================================================================================================================
Install  1 Package ( 1 Dependent package)

Total download size: 651 k
Installed size: 1.7 M
Downloading packages:
(1/2): redis-3.2.12-2.el7.x86_64.rpm                                                                                        | 544 kB  00:00:00     
(2/2): jemalloc-3.6.0-1.el7.x86_64.rpm                                                                                      | 107 kB  00:00:00     
---------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                              2.3 MB/s | 651 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : jemalloc-3.6.0-1.el7.x86_64                                                                                                     1/2 
  Installing : redis-3.2.12-2.el7.x86_64                                                                                                       2/2 
  Verifying  : redis-3.2.12-2.el7.x86_64                                                                                                       1/2 
  Verifying  : jemalloc-3.6.0-1.el7.x86_64                                                                                                     2/2 

Installed:
  redis.x86_64 0:3.2.12-2.el7                                                                                                                      

Dependency Installed:
  jemalloc.x86_64 0:3.6.0-1.el7                                                                                                                    

Complete!

2.启动redis服务

代码语言:shell复制
[root@server ~]# systemctl enable --now redis
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /usr/lib/systemd/system/redis.service.

六、连接redis

测试本地连接redis,查看redis数据库详细信息。

代码语言:shell复制
[root@server ~]# redis-cli
127.0.0.1:6379> info
# Server
redis_version:3.2.12
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:7897e7d0e13773f
redis_mode:standalone
os:Linux 3.10.0-957.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.5
process_id:17174
run_id:0db6caf4f1e1f630fded8256fcf2d032fc9e0ad7
tcp_port:6379
uptime_in_seconds:21
uptime_in_days:0
hz:10
lru_clock:6804044
executable:/usr/bin/redis-server
config_file:/etc/redis.conf

# Clients
connected_clients:1
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Memory
used_memory:813448
used_memory_human:794.38K
used_memory_rss:2523136
used_memory_rss_human:2.41M
used_memory_peak:813448
used_memory_peak_human:794.38K
total_system_memory:7968645120
total_system_memory_human:7.42G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:3.10
mem_allocator:jemalloc-3.6.0

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1667748407
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok

# Stats
total_connections_received:1
total_commands_processed:1
instantaneous_ops_per_sec:0
total_net_input_bytes:31
total_net_output_bytes:9928
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
migrate_cached_sockets:0

# Replication
role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

# CPU
used_cpu_sys:0.04
used_cpu_user:0.01
used_cpu_sys_children:0.00
used_cpu_user_children:0.00

# Cluster
cluster_enabled:0

# Keyspace

我正在参与2023腾讯技术创作特训营第三期有奖征文,组队打卡瓜分大奖!

0 人点赞