Redis数据库的编译安装方法

Redis数据库的编译安装方法

  • 一、Redis介绍
  • 二、检查本地系统版本
    • 1.检查系统版本
    • 2.检查系统内核版本
  • 三、下载Redis的源码包
    • 1.下载redis源码包
    • 2.解压源码包
  • 四、关闭防火墙和selinux
    • 1.关闭防火墙
    • 2.关闭selinux
  • 五、编译前环境准备工作
    • 1.安装gcc模块
    • 2.进入deps/目录下编译
  • 六、编译安装Redis
  • 七、启动Redis
    • 1.配置环境变量
    • 2.检查Redis版本
    • 3.创建Redis相关目录
    • 4.编辑redis的配置文件
    • 5.启动redis
  • 八、连接Redis
    • 1.检查redis端口
    • 2.连接redis

一、Redis介绍

Redis 是完全开源免费的,遵守BSD协议,是一个高性能(NOSQL)的key-value数据库,Redis是一个开源的使用ANSI C语言编写、支持网络、可基于内存亦可持久化的日志型、Key-Value数据库,并提供多种语言的API。

Redis是一个非关系型数据库,与传统数据库不同的是redis的数据是存在内存中的,所以读写速度非常快,因此 redis 被广泛应用于缓存方向。另外,redis 也经常用来做分布式锁。 redis 提供了多种数据类型来支持不同的业务场景。 除此之外,redis 支持事务 、持久化、LUA脚本、LRU驱动事件、多种集群方案。

二、检查本地系统版本

1.检查系统版本

[root@node01 ~]# 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.检查系统内核版本

[root@node01 ~]# uname -r
3.10.0-957.el7.x86_64

三、下载Redis的源码包

1.下载redis源码包


[root@node01 redis]# wget https://download.redis.io/releases/redis-6.2.6.tar.gz
--2022-11-24 18:36:42--  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.37MB/s   in 0.5s   

2022-11-24 18:36:43 (4.37 MB/s) - ‘redis-6.2.6.tar.gz’ saved [2476542/2476542]


2.解压源码包

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



四、关闭防火墙和selinux

1.关闭防火墙

systemctl stop firewalld.service
systemctl disable firewalld.service

2.关闭selinux

[root@node01 redis]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/' /etc/selinux/config
[root@node01 redis]# setenforce 0
setenforce: SELinux is disabled
[root@node01 redis]# 


五、编译前环境准备工作

1.安装gcc模块

yum -y install gcc automake autoconf libtool make

2.进入deps/目录下编译

[root@node01 redis]# ls
redis-6.2.6  redis-6.2.6.tar.gz
[root@node01 redis]# cd redis-6.2.6/
[root@node01 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@node01 redis-6.2.6]# cd deps/
[root@node01 deps]# ls
hdr_histogram  hiredis  jemalloc  linenoise  lua  Makefile  README.md  update-jemalloc.sh


make lua hiredis linenoise hdr_histogram jemalloc


六、编译安装Redis


[root@node01 redis-6.2.6]# make PREFIX=/usr/local/redis MALLOC=libc install
cd src && make install
make[1]: Entering directory `/data/redis/redis-6.2.6/src'
    CC Makefile.dep
make[1]: Leaving directory `/data/redis/redis-6.2.6/src'
make[1]: Entering directory `/data/redis/redis-6.2.6/src'


七、启动Redis

1.配置环境变量

[root@node01 redis-6.2.6]# cat /etc/profile.d/redis_init.sh 
export PATH=$PATH:/usr/local/redis/bin
[root@node01 redis-6.2.6]# source  /etc/profile.d/redis_init.sh

2.检查Redis版本

[root@node01 redis-6.2.6]# redis-server --version
Redis server v=6.2.6 sha=00000000:0 malloc=libc bits=64 build=a6a826a997b028c6

3.创建Redis相关目录

[root@node01 redis-6.2.6]# mkdir -p /usr/local/redis/{etc,logs,data}
[root@node01 redis-6.2.6]# 

4.编辑redis的配置文件

[root@node01 redis-6.2.6]# vim /usr/local/redis/etc/redis.conf
[root@node01 redis-6.2.6]# 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.172 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
[root@node01 redis-6.2.6]# 


5.启动redis

[root@node01 redis-6.2.6]# redis-server /usr/local/redis/etc/redis.conf
[root@node01 redis-6.2.6]# 


八、连接Redis

1.检查redis端口


[root@node01 redis-6.2.6]# ps -ef |grep redis
root      8540     1  0 18:59 ?        00:00:00 redis-server 192.168.3.172:6379
root      8546  3927  0 19:00 pts/0    00:00:00 grep --color=auto redis


2.连接redis

[root@node01 redis-6.2.6]#  redis-cli  -h 192.168.3.172 -p 6379
192.168.3.172:6379> info
# Server
redis_version:6.2.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:a6a826a997b028c6
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:8540
process_supervised:no
run_id:89e1dec4b9b1afd95a1ccc2531caf7fe9229db00
tcp_port:6379
server_time_usec:1669287649621670
uptime_in_seconds:97
uptime_in_days:0
hz:10
configured_hz:10
lru_clock:8343265
executable:/data/redis/redis-6.2.6/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:936096
used_memory_human:914.16K
used_memory_rss:2445312
used_memory_rss_human:2.33M
used_memory_peak:990896
used_memory_peak_human:967.67K
used_memory_peak_perc:94.47%
used_memory_overhead:901184
used_memory_startup:884128
used_memory_dataset:34912
used_memory_dataset_perc:67.18%
allocator_allocated:901680
allocator_active:2407424
allocator_resident:2407424
total_system_memory:8201056256
total_system_memory_human:7.64G
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.67
allocator_frag_bytes:1505744
allocator_rss_ratio:1.00
allocator_rss_bytes:0
rss_overhead_ratio:1.02
rss_overhead_bytes:37888
mem_fragmentation_ratio:2.71
mem_fragmentation_bytes:1543632
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:1669287552
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:8bf21705d6f7b0d1eafb79061d723c106c8b0625
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.036196
used_cpu_user:0.030852
used_cpu_sys_children:0.000000
used_cpu_user_children:0.000000
used_cpu_sys_main_thread:0.035946
used_cpu_user_main_thread:0.030988

# Modules

# Errorstats

# Cluster
cluster_enabled:0

# Keyspace
192.168.3.172:6379> 

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