Oracle Linux上安装Redis

淳于熙云
2023-12-01

源代码安装可参考官网,Yum安装参考此文档

YUM安装

$ yum search redis
========================================== N/S matched: redis ===========================================
collectd-redis.x86_64 : Redis plugin for collectd
collectd-write_redis.x86_64 : Redis output plugin for collectd
hiredis.x86_64 : Minimalistic C client library for Redis
hiredis-devel.x86_64 : Development files for hiredis
opensips-redis.x86_64 : Redis connector
pcp-pmda-redis.x86_64 : Performance Co-Pilot (PCP) metrics for Redis
perl-Apache-Session-Redis.noarch : Redis driver for Apache::Session::NoSQL
perl-Redis.noarch : Perl binding for Redis database
php-nrk-Predis.noarch : PHP client library for Redis
php-pecl-redis.x86_64 : Extension for communicating with the Redis key-value store
php-phpiredis.x86_64 : Client extension for Redis
python-redis.noarch : Python 2 interface to the Redis key-value store
python-trollius-redis.noarch : Redis client for the Python event loop PEP3156 for Trollius.
python2-django-redis.noarch : Full featured redis cache backend for Django
python2-redis.noarch : Python 2 interface to the Redis key-value store
redis-trib.noarch : Cluster management script for Redis
rh-redis32.x86_64 : Package that installs Redis 3.2
rh-redis32-runtime.x86_64 : Package that handles rh-redis32 Software Collection.
rh-redis32-scldevel.x86_64 : Package shipping development files for rh-redis32
rh-redis5.x86_64 : Package that installs Redis 5
rh-redis5-runtime.x86_64 : Package that handles rh-redis5 Software Collection.
rh-redis5-scldevel.x86_64 : Package shipping development files for rh-redis5
rubygem-redis.noarch : A Ruby client library for Redis
rubygem-redis-doc.noarch : Documentation for rubygem-redis
syslog-ng-redis.x86_64 : redis support for syslog-ng
uwsgi-logger-redis.x86_64 : uWSGI - redislog logger plugin
uwsgi-router-redis.x86_64 : uWSGI - Plugin for Redis router support
redis.x86_64 : A persistent key-value database
rh-redis32-redis.x86_64 : A persistent key-value database
rh-redis5-redis.x86_64 : A persistent key-value database

  Name and summary matches only, use "search all" for everything.
  
$ sudo yum install -y redis
mongodb-org-4.4                                                                   | 2.5 kB  00:00:00
ol7_UEKR5                                                                         | 2.5 kB  00:00:00
ol7_addons                                                                        | 2.5 kB  00:00:00
ol7_developer                                                                     | 2.5 kB  00:00:00
ol7_developer_EPEL                                                                | 2.7 kB  00:00:00
ol7_latest                                                                        | 2.7 kB  00:00:00
ol7_optional_latest                                                               | 2.5 kB  00:00:00
ol7_software_collections                                                          | 2.5 kB  00:00:00
(1/8): ol7_developer/x86_64/primary_db                                            | 699 kB  00:00:01
(2/8): ol7_developer/x86_64/updateinfo                                            | 7.9 kB  00:00:03
(3/8): ol7_optional_latest/x86_64/updateinfo                                      | 1.2 MB  00:00:03
(4/8): ol7_latest/x86_64/updateinfo                                               | 3.1 MB  00:00:04
(5/8): ol7_latest/x86_64/primary_db                                               |  31 MB  00:00:04
(6/8): ol7_software_collections/x86_64/updateinfo                                 | 8.6 kB  00:00:01
(7/8): ol7_optional_latest/x86_64/primary_db                                      | 5.6 MB  00:00:03
(8/8): ol7_software_collections/x86_64/primary_db                                 | 5.3 MB  00:00:02
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               ol7_developer_EPEL             543 k
Installing for dependencies:
 jemalloc             x86_64             3.6.0-1.el7                ol7_developer_EPEL             105 k

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

Total download size: 648 k
Installed size: 1.7 M
Downloading packages:
(1/2): jemalloc-3.6.0-1.el7.x86_64.rpm                                            | 105 kB  00:00:01
(2/2): redis-3.2.12-2.el7.x86_64.rpm                                              | 543 kB  00:00:03
---------------------------------------------------------------------------------------------------------
Total                                                                    162 kB/s | 648 kB  00:00:03
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!

$ systemctl status redis
● redis.service - Redis persistent key-value database
   Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/redis.service.d
           └─limit.conf
   Active: inactive (dead)

$ systemctl start redis
Failed to start redis.service: The name org.freedesktop.PolicyKit1 was not provided by any .service files
See system logs and 'systemctl status redis.service' for details.
[vagrant@ol7-vagrant ~]$ sudo systemctl start redis
[vagrant@ol7-vagrant ~]$ sudo systemctl status redis
● redis.service - Redis persistent key-value database
   Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/redis.service.d
           └─limit.conf
   Active: active (running) since Mon 2020-11-23 03:19:01 UTC; 3s ago
 Main PID: 3929 (redis-server)
   CGroup: /system.slice/redis.service
           └─3929 /usr/bin/redis-server 127.0.0.1:6379

Nov 23 03:19:01 ol7-vagrant systemd[1]: Starting Redis persistent key-value database...
Nov 23 03:19:01 ol7-vagrant systemd[1]: Started Redis persistent key-value database.

$ redis-cli ping
PONG

redis默认只在localhost监听,可修改配置文件/etc/redis.conf增加监听地址。以下可知其监听端口默认为6379:

$ netstat -antup | grep -i 6379
(No info could be read for "-p": geteuid()=1000 but you should be root.)
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN  

此安装还创建了用户redis:

$ id redis
uid=993(redis) gid=993(redis) groups=993(redis)

连接到数据库:

$ redis-cli
127.0.0.1:6379>

显示redis基本信息:

127.0.0.1:6379> INFO
# Server
redis_version:
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:a3cb4c2bb6b6dbfd
redis_mode:standalone
os:Linux 4.14.35-1902.301.1.el7uek.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.5
process_id:4934
run_id:83328f0f9fe42fd41b1f15fcf4f4fc3699b2b180
tcp_port:6379
uptime_in_seconds:620
uptime_in_days:0
hz:10
lru_clock:12279199
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:813576
used_memory_human:794.51K
used_memory_rss:7913472
used_memory_rss_human:7.55M
used_memory_peak:813576
used_memory_peak_human:794.51K
total_system_memory:1809174528
total_system_memory_human:1.68G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:9.73
mem_allocator:jemalloc-3.6.0

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1606114099
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:2
total_commands_processed:4
instantaneous_ops_per_sec:0
total_net_input_bytes:172
total_net_output_bytes:20003
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.55
used_cpu_user:0.34
used_cpu_sys_children:0.00
used_cpu_user_children:0.00

# Cluster
cluster_enabled:0

# Keyspace

卸载

sudo systemctl stop redis
sudo systemctl disable redis
sudo yum remove redis
sudo rm -fr /var/lib/redis /var/log/redis /etc/logrotate.d/redis
sudo userdel redis

源代码安装

由于Yum安装的版本只是3.2.12,并不是最新,因此还是测试了源代码安装。

wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make

编译在make时遇到了问题,原因是我Linux 7中gcc版本过低,需要4.9以上:

$ gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-44.0.3)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

最简单的方法就是换到Linux 8。如果仍保持Linux 7,可以参照How to get gcc version >= 8 installed解决:

$ sudo yum install devtoolset-9
$ scl enable devtoolset-9 -- make

然后make test需要安装tcl8:

sudo yum install tcl.x86_64
make test

启动redis并连接:

$ export PATH=$PATH:~/redis-stable/src/
$ redis-server &
$ redis-cli info server | grep -i version
redis_version:6.0.9
gcc_version:8.3.1

 类似资料: