Linux系统之源码编译部署Redis数据库

Linux系统之源码编译部署Redis数据库

  • 一、Redis数据库介绍
    • 1.Redis简介
    • 2.Redis特点
  • 二、检查本地系统版本
  • 三、下载Redis软件包
    • 1.下载软件
    • 2.查看redis安装包
  • 四、安装redis前环境准备工作
    • 1.解压redis压缩包
    • 2.安装gcc模块
  • 五、编译redis源码包
    • 1.进入软件目录
    • 2.编译redis前准备工作
    • 3.编译redis
  • 六、启动redis
    • 1.配置环境变量
    • 2.检查redis版本
    • 3.创建redis相关目录
    • 4.编辑redis配置文件
    • 5.启动redis数据库服务
  • 七、连接redis数据库
    • 1.检查redis状态
    • 2.连接redis

一、Redis数据库介绍

1.Redis简介

Redis 是完全开源的,遵守 BSD 协议,是一个高性能的 key-value 数据库。

2.Redis特点

  • Redis支持数据的持久化,可以将内存中的数据保存在磁盘中,重启的时候可以再次加载进行使用。
  • Redis不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,hash等数据结构的存储。
  • Redis支持数据的备份,即master-slave模式的数据备份。

二、检查本地系统版本

[root@node data]# 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"


三、下载Redis软件包

1.下载软件

[root@node redis]# wget https://download.redis.io/releases/redis-6.2.6.tar.gz
--2022-11-06 16:33:47--  https://download.redis.io/releases/redis-6.2.6.tar.gz
Resolving download.redis.io (download.redis.io)... 45.60.125.1
Connecting to download.redis.io (download.redis.io)|45.60.125.1|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2476542 (2.4M) [application/octet-stream]
Saving to: ‘redis-6.2.6.tar.gz’

100%[=========================================================================================================>] 2,476,542   4.90MB/s   in 0.5s   

2022-11-06 16:33:49 (4.90 MB/s) - ‘redis-6.2.6.tar.gz’ saved [2476542/2476542]

2.查看redis安装包

[root@node redis]# ls
redis-6.2.6.tar.gz

四、安装redis前环境准备工作

1.解压redis压缩包

[root@node redis]# tar -xzf redis-6.2.6.tar.gz 
[root@node redis]# ls
redis-6.2.6  redis-6.2.6.tar.gz

2.安装gcc模块

[root@node redis]# yum -y install gcc automake autoconf libtool make
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
 * base: mirrors.huaweicloud.com
 * extras: mirrors.huaweicloud.com
 * updates: mirrors.huaweicloud.com
base                                                                                                                        | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                            | 3.5 kB  00:00:00     
extras                                                                                                                      | 2.9 kB  00:00:00     
mongodb-org                                                                                                                 | 2.9 kB  00:00:00     
mysql-connectors-community                                                                                                  | 2.6 kB  00:00:00     
mysql-tools-community                                                                                                       | 2.6 kB  00:00:00     
mysql57-community                                                                                                           | 2.6 kB  00:00:00     
updates                                                                                                                     | 2.9 kB  00:00:00     
mongodb-org/7/primary_db                                                                                                    | 130 kB  00:00:01     
Resolving Dependencies
--> Running transaction check
---> Package autoconf.noarch 0:2.69-11.el7 will be installed
--> Processing Dependency: m4 >= 1.4.14 for package: autoconf-2.69-11.el7.noarch
---> Package automake.noarch 0:1.13.4-3.el7 will be installed
--> Processing Dependency: perl(Thread::Queue) for package: automake-1.13.4-3.el7.noarch
--> Processing Dependency: perl(TAP::Parser) for package: automake-1.13.4-3.el7.noarch
---> Package gcc.x86_64 0:4.8.5-44.el7 will be installed
--> Processing Dependency: libgomp = 4.8.5-44.el7 for package: gcc-4.8.5-44.el7.x86_64
--> Processing Dependency: cpp = 4.8.5-44.el7 for package: gcc-4.8.5-44.el7.x86_64
--> Processing Dependency: libgcc >= 4.8.5-44.el7 for package: gcc-4.8.5-44.el7.x86_64
--> Processing Dependency: glibc-devel >= 2.2.90-12 for package: gcc-4.8.5-44.el7.x86_64
---> Package libtool.x86_64 0:2.4.2-22.el7_3 will be installed
---> Package make.x86_64 1:3.82-23.el7 will be updated
---> Package make.x86_64 1:3.82-24.el7 will be an update
--> Running transaction check
---> Package cpp.x86_64 0:4.8.5-44.el7 will be installed
---> Package glibc-devel.x86_64 0:2.17-326.el7_9 will be installed
--> Processing Dependency: glibc-headers = 2.17-326.el7_9 for package: glibc-devel-2.17-326.el7_9.x86_64
--> Processing Dependency: glibc = 2.17-326.el7_9 for package: glibc-devel-2.17-326.el7_9.x86_64
--> Processing Dependency: glibc-headers for package: glibc-devel-2.17-326.el7_9.x86_64
---> Package libgcc.x86_64 0:4.8.5-36.el7 will be updated
---> Package libgcc.x86_64 0:4.8.5-44.el7 will be an update
---> Package libgomp.x86_64 0:4.8.5-36.el7 will be updated
---> Package libgomp.x86_64 0:4.8.5-44.el7 will be an update
---> Package m4.x86_64 0:1.4.16-10.el7 will be installed
---> Package perl-Test-Harness.noarch 0:3.28-3.el7 will be installed
---> Package perl-Thread-Queue.noarch 0:3.02-2.el7 will be installed
--> Running transaction check
---> Package glibc.x86_64 0:2.17-260.el7 will be updated
--> Processing Dependency: glibc = 2.17-260.el7 for package: glibc-common-2.17-260.el7.x86_64
---> Package glibc.x86_64 0:2.17-326.el7_9 will be an update
---> Package glibc-headers.x86_64 0:2.17-326.el7_9 will be installed
--> Processing Dependency: kernel-headers >= 2.2.1 for package: glibc-headers-2.17-326.el7_9.x86_64
--> Processing Dependency: kernel-headers for package: glibc-headers-2.17-326.el7_9.x86_64
--> Running transaction check
---> Package glibc-common.x86_64 0:2.17-260.el7 will be updated
---> Package glibc-common.x86_64 0:2.17-326.el7_9 will be an update
---> Package kernel-headers.x86_64 0:3.10.0-1160.76.1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================================================================================
 Package                                Arch                        Version                                     Repository                    Size
===================================================================================================================================================
Installing:
 autoconf                               noarch                      2.69-11.el7                                 base                         701 k
 automake                               noarch                      1.13.4-3.el7                                base                         679 k
 gcc                                    x86_64                      4.8.5-44.el7                                base                          16 M
 libtool                                x86_64                      2.4.2-22.el7_3                              base                         588 k
Updating:
 make                                   x86_64                      1:3.82-24.el7                               base                         421 k
Installing for dependencies:
 cpp                                    x86_64                      4.8.5-44.el7                                base                         5.9 M
 glibc-devel                            x86_64                      2.17-326.el7_9                              updates                      1.1 M
 glibc-headers                          x86_64                      2.17-326.el7_9                              updates                      691 k
 kernel-headers                         x86_64                      3.10.0-1160.76.1.el7                        updates                      9.1 M
 m4                                     x86_64                      1.4.16-10.el7                               base                         256 k
 perl-Test-Harness                      noarch                      3.28-3.el7                                  base                         302 k
 perl-Thread-Queue                      noarch                      3.02-2.el7                                  base                          17 k
Updating for dependencies:
 glibc                                  x86_64                      2.17-326.el7_9                              updates                      3.6 M
 glibc-common                           x86_64                      2.17-326.el7_9                              updates                       12 M
 libgcc                                 x86_64                      4.8.5-44.el7                                base                         103 k
 libgomp                                x86_64                      4.8.5-44.el7                                base                         159 k

Transaction Summary
===================================================================================================================================================
Install  4 Packages (+7 Dependent packages)
Upgrade  1 Package  (+4 Dependent packages)

Total size: 51 M
Total download size: 35 M
Downloading packages:
(1/11): automake-1.13.4-3.el7.noarch.rpm                                                                                    | 679 kB  00:00:00     
(2/11): autoconf-2.69-11.el7.noarch.rpm                                                                                     | 701 kB  00:00:00     
(3/11): glibc-devel-2.17-326.el7_9.x86_64.rpm                                                                               | 1.1 MB  00:00:00     
(4/11): libtool-2.4.2-22.el7_3.x86_64.rpm                                                                                   | 588 kB  00:00:00     
(5/11): m4-1.4.16-10.el7.x86_64.rpm                                                                                         | 256 kB  00:00:00     
(6/11): perl-Test-Harness-3.28-3.el7.noarch.rpm                                                                             | 302 kB  00:00:00     
(7/11): perl-Thread-Queue-3.02-2.el7.noarch.rpm                                                                             |  17 kB  00:00:00     
(8/11): kernel-headers-3.10.0-1160.76.1.el7.x86_64.rpm                                                                      | 9.1 MB  00:00:01     
(9/11): cpp-4.8.5-44.el7.x86_64.rpm                                                                                         | 5.9 MB  00:00:02     
(10/11): glibc-headers-2.17-326.el7_9.x86_64.rpm                                                                            | 691 kB  00:00:03     
(11/11): gcc-4.8.5-44.el7.x86_64.rpm                                                                                        |  16 MB  00:00:06     
---------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                              4.7 MB/s |  35 MB  00:00:07     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : libgcc-4.8.5-44.el7.x86_64                                                                                                     1/21 
  Updating   : glibc-common-2.17-326.el7_9.x86_64                                                                                             2/21 
  Updating   : glibc-2.17-326.el7_9.x86_64                                                                                                    3/21 
warning: /etc/nsswitch.conf created as /etc/nsswitch.conf.rpmnew
  Installing : cpp-4.8.5-44.el7.x86_64                                                                                                        4/21 
  Installing : m4-1.4.16-10.el7.x86_64                                                                                                        5/21 
  Installing : autoconf-2.69-11.el7.noarch                                                                                                    6/21 
  Updating   : libgomp-4.8.5-44.el7.x86_64                                                                                                    7/21 
  Installing : perl-Thread-Queue-3.02-2.el7.noarch                                                                                            8/21 
  Installing : perl-Test-Harness-3.28-3.el7.noarch                                                                                            9/21 
  Installing : automake-1.13.4-3.el7.noarch                                                                                                  10/21 
  Installing : kernel-headers-3.10.0-1160.76.1.el7.x86_64                                                                                    11/21 
  Installing : glibc-headers-2.17-326.el7_9.x86_64                                                                                           12/21 
  Installing : glibc-devel-2.17-326.el7_9.x86_64                                                                                             13/21 
  Installing : gcc-4.8.5-44.el7.x86_64                                                                                                       14/21 
  Installing : libtool-2.4.2-22.el7_3.x86_64                                                                                                 15/21 
  Updating   : 1:make-3.82-24.el7.x86_64                                                                                                     16/21 
  Cleanup    : libgomp-4.8.5-36.el7.x86_64                                                                                                   17/21 
  Cleanup    : 1:make-3.82-23.el7.x86_64                                                                                                     18/21 
  Cleanup    : glibc-common-2.17-260.el7.x86_64                                                                                              19/21 
  Cleanup    : glibc-2.17-260.el7.x86_64                                                                                                     20/21 
  Cleanup    : libgcc-4.8.5-36.el7.x86_64                                                                                                    21/21 
  Verifying  : kernel-headers-3.10.0-1160.76.1.el7.x86_64                                                                                     1/21 
  Verifying  : autoconf-2.69-11.el7.noarch                                                                                                    2/21 
  Verifying  : glibc-2.17-326.el7_9.x86_64                                                                                                    3/21 
  Verifying  : perl-Test-Harness-3.28-3.el7.noarch                                                                                            4/21 
  Verifying  : automake-1.13.4-3.el7.noarch                                                                                                   5/21 
  Verifying  : glibc-common-2.17-326.el7_9.x86_64                                                                                             6/21 
  Verifying  : perl-Thread-Queue-3.02-2.el7.noarch                                                                                            7/21 
  Verifying  : cpp-4.8.5-44.el7.x86_64                                                                                                        8/21 
  Verifying  : gcc-4.8.5-44.el7.x86_64                                                                                                        9/21 
  Verifying  : glibc-headers-2.17-326.el7_9.x86_64                                                                                           10/21 
  Verifying  : glibc-devel-2.17-326.el7_9.x86_64                                                                                             11/21 
  Verifying  : 1:make-3.82-24.el7.x86_64                                                                                                     12/21 
  Verifying  : m4-1.4.16-10.el7.x86_64                                                                                                       13/21 
  Verifying  : libgcc-4.8.5-44.el7.x86_64                                                                                                    14/21 
  Verifying  : libgomp-4.8.5-44.el7.x86_64                                                                                                   15/21 
  Verifying  : libtool-2.4.2-22.el7_3.x86_64                                                                                                 16/21 
  Verifying  : libgcc-4.8.5-36.el7.x86_64                                                                                                    17/21 
  Verifying  : glibc-common-2.17-260.el7.x86_64                                                                                              18/21 
  Verifying  : glibc-2.17-260.el7.x86_64                                                                                                     19/21 
  Verifying  : libgomp-4.8.5-36.el7.x86_64                                                                                                   20/21 
  Verifying  : 1:make-3.82-23.el7.x86_64                                                                                                     21/21 

Installed:
  autoconf.noarch 0:2.69-11.el7       automake.noarch 0:1.13.4-3.el7       gcc.x86_64 0:4.8.5-44.el7       libtool.x86_64 0:2.4.2-22.el7_3      

Dependency Installed:
  cpp.x86_64 0:4.8.5-44.el7                             glibc-devel.x86_64 0:2.17-326.el7_9          glibc-headers.x86_64 0:2.17-326.el7_9         
  kernel-headers.x86_64 0:3.10.0-1160.76.1.el7          m4.x86_64 0:1.4.16-10.el7                    perl-Test-Harness.noarch 0:3.28-3.el7         
  perl-Thread-Queue.noarch 0:3.02-2.el7                

Updated:
  make.x86_64 1:3.82-24.el7                                                                                                                        

Dependency Updated:
  glibc.x86_64 0:2.17-326.el7_9      glibc-common.x86_64 0:2.17-326.el7_9      libgcc.x86_64 0:4.8.5-44.el7      libgomp.x86_64 0:4.8.5-44.el7     

Complete!

五、编译redis源码包

1.进入软件目录

[root@node redis]# cd redis-6.2.6/
[root@node redis-6.2.6]# ls
00-RELEASENOTES  CONDUCT       COPYING  INSTALL   MANIFESTO  redis.conf  runtest-cluster    runtest-sentinel  src    TLS.md
BUGS             CONTRIBUTING  deps     Makefile  README.md  runtest     runtest-moduleapi  sentinel.conf     tests  utils
[root@node redis-6.2.6]# cd deps/
[root@node deps]# ls
hdr_histogram  hiredis  jemalloc  linenoise  lua  Makefile  README.md  update-jemalloc.sh

2.编译redis前准备工作

[root@node deps]# make lua hiredis linenoise hdr_histogram jemalloc

3.编译redis

[root@node src]# make PREFIX=/usr/local/redis MALLOC=libc install
   


六、启动redis

1.配置环境变量

[root@node src]# vim /etc/profile.d/redis.sh
[root@node src]# cat /etc/profile.d/redis.sh 
#!/bin/bash
##########################################################
#File Name:/etc/profile.d/redis.sh
#Version:V1.0
#Aurhor:jeven
#Emali:[email protected]
#Created Time:2022-11-06 16:53:28
#Description:
##########################################################
export PATH=$PATH:/usr/local/redis/bin
[root@node src]# source !$
source /etc/profile.d/redis.sh

2.检查redis版本

[root@node src]# redis-server --version
Redis server v=6.2.6 sha=00000000:0 malloc=libc bits=64 build=50e1147e6629be9b

3.创建redis相关目录

mkdir -p /usr/local/redis/{etc,logs,data}

4.编辑redis配置文件

[root@node src]# cat  /usr/local/redis/etc/redis.conf
daemonize yes
supervised systemd
pidfile /var/run/redis.pid
port 6379
logfile /usr/local/redis/logs/redis.log
dbfilename dump.rdb
dir /usr/local/redis/data

maxmemory 1G

bind 192.168.3.166 127.0.0.1

timeout 300
loglevel notice

databases 16
save 900 1
save 300 10
save 60 10000

rdbcompression yes

maxclients 10000
appendonly yes
appendfilename appendonly.aof
appendfsync everysec

5.启动redis数据库服务

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

七、连接redis数据库

1.检查redis状态

[root@node src]#  ps -ef |grep redis
root      62216      1  0 16:57 ?        00:00:00 redis-server 192.168.3.166:6379
root      62271  40947  0 16:58 pts/1    00:00:00 grep --color=auto redis

2.连接redis

[root@node src]# redis-cli  -h 192.168.3.166 -p 6379
192.168.3.166:6379> info
# Server
redis_version:6.2.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:50e1147e6629be9b
redis_mode:standalone
os:Linux 3.10.0-957.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:atomic-builtin
gcc_version:4.8.5
process_id:62216
process_supervised:no
run_id:2214123488103e78bca63970b6830e53341b9a66
tcp_port:6379
server_time_usec:1667725122023863
uptime_in_seconds:86
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:6780738
executable:/aa/redis/redis-6.2.6/src/redis-server
config_file:/usr/local/redis/etc/redis.conf
io_threads_active:0

# Clients
connected_clients:1
cluster_connections:0
maxclients:10000
client_recent_max_input_buffer:48
client_recent_max_output_buffer:0
blocked_clients:0
tracking_clients:0
clients_in_timeout_table:0

# Memory
used_memory:936080
used_memory_human:914.14K
used_memory_rss:2478080
used_memory_rss_human:2.36M
used_memory_peak:990912
used_memory_peak_human:967.69K
used_memory_peak_perc:94.47%
used_memory_overhead:901168
used_memory_startup:884112
used_memory_dataset:34912
used_memory_dataset_perc:67.18%
allocator_allocated:901664
allocator_active:2440192
allocator_resident:2440192
total_system_memory:8182054912
total_system_memory_human:7.62G
used_memory_lua:37888
used_memory_lua_human:37.00K
used_memory_scripts:0
used_memory_scripts_human:0B
number_of_cached_scripts:0
maxmemory:1000000000
maxmemory_human:953.67M
maxmemory_policy:noeviction
allocator_frag_ratio:2.71
allocator_frag_bytes:1538528
allocator_rss_ratio:1.00
allocator_rss_bytes:0
rss_overhead_ratio:1.02
rss_overhead_bytes:37888
mem_fragmentation_ratio:2.75
mem_fragmentation_bytes:1576416
mem_not_counted_for_evict:20
mem_replication_backlog:0
mem_clients_slaves:0
mem_clients_normal:17032
mem_aof_buffer:24
mem_allocator:libc
active_defrag_running:0
lazyfree_pending_objects:0
lazyfreed_objects:0

# Persistence
loading:0
current_cow_size:0
current_cow_size_age:0
current_fork_perc:0.00
current_save_keys_processed:0
current_save_keys_total:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1667725036
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
rdb_last_cow_size:0
aof_enabled:1
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
aof_last_cow_size:0
module_fork_in_progress:0
module_fork_last_cow_size:0
aof_current_size:0
aof_base_size:0
aof_pending_rewrite:0
aof_buffer_length:0
aof_rewrite_buffer_length:0
aof_pending_bio_fsync:0
aof_delayed_fsync:0

# Stats
total_connections_received:1
total_commands_processed:1
instantaneous_ops_per_sec:0
total_net_input_bytes:31
total_net_output_bytes:20324
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
expired_stale_perc:0.00
expired_time_cap_reached_count:0
expire_cycle_cpu_milliseconds:1
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
total_forks:0
migrate_cached_sockets:0
slave_expires_tracked_keys:0
active_defrag_hits:0
active_defrag_misses:0
active_defrag_key_hits:0
active_defrag_key_misses:0
tracking_total_keys:0
tracking_total_items:0
tracking_total_prefixes:0
unexpected_error_replies:0
total_error_replies:0
dump_payload_sanitizations:0
total_reads_processed:2
total_writes_processed:1
io_threaded_reads_processed:0
io_threaded_writes_processed:0

# Replication
role:master
connected_slaves:0
master_failover_state:no-failover
master_replid:1a8b2d03ea009393183110d55ca0c6b619127210
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:0
second_repl_offset:-1
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

# CPU
used_cpu_sys:0.132352
used_cpu_user:0.044117
used_cpu_sys_children:0.000000
used_cpu_user_children:0.000000
used_cpu_sys_main_thread:0.132334
used_cpu_user_main_thread:0.044111

# Modules

# Errorstats

# Cluster
cluster_enabled:0

# Keyspace

你可能感兴趣的:(Redis,数据库,redis,linux)