Redis7.0源码安装与部署

本文详细描述了如何在Linux环境中通过yum安装GCC,下载并解压Redis源码包,配置并编译安装Redis,设置环境变量,启动服务以及连接和管理Redis服务器的过程。

环境依赖

gcc gcc-c++

[root@redis ~]# yum install gcc* -y

下载安装包

[root@redis ~]# wget https://download.redis.io/redis-stable.tar.gz
--2023-07-13 16:54:01--  https://download.redis.io/redis-stable.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: 3071850 (2.9M) [application/octet-stream]
Saving to: ‘redis-stable.tar.gz’

100%[======================================>] 3,071,850   29.8KB/s   in 65s    

2023-07-13 16:55:06 (46.3 KB/s) - ‘redis-stable.tar.gz’ saved [3071850/3071850]

[root@redis ~]# ll
total 3004
-rw-------. 1 root root    1294 Jul 13 11:32 anaconda-ks.cfg
-rw-r--r--. 1 root root 3071850 Jul 10 19:52 redis-stable.tar.gz

解压缩


[root@redis ~]# tar -zxf redis-stable.tar.gz 


[root@redis ~]# ll -h redis-stable
total 272K
-rw-rw-r--.  1 1000 1000  45K Jul 10 19:39 00-RELEASENOTES
-rw-rw-r--.  1 1000 1000   51 Jul 10 19:39 BUGS
-rw-rw-r--.  1 1000 1000 5.0K Jul 10 19:39 CODE_OF_CONDUCT.md
-rw-rw-r--.  1 1000 1000 2.6K Jul 10 19:39 CONTRIBUTING.md
-rw-rw-r--.  1 1000 1000 1.5K Jul 10 19:39 COPYING
drwxrwxr-x.  7 1000 1000  119 Jul 10 19:39 deps
-rw-rw-r--.  1 1000 1000   11 Jul 10 19:39 INSTALL
-rw-rw-r--.  1 1000 1000  151 Jul 10 19:39 Makefile
-rw-rw-r--.  1 1000 1000 6.8K Jul 10 19:39 MANIFESTO
-rw-rw-r--.  1 1000 1000  22K Jul 10 19:39 README.md
-rw-rw-r--.  1 1000 1000 105K Jul 10 19:39 redis.conf
-rwxrwxr-x.  1 1000 1000  279 Jul 10 19:39 runtest
-rwxrwxr-x.  1 1000 1000  283 Jul 10 19:39 runtest-cluster
-rwxrwxr-x.  1 1000 1000 1.6K Jul 10 19:39 runtest-moduleapi
-rwxrwxr-x.  1 1000 1000  285 Jul 10 19:39 runtest-sentinel
-rw-rw-r--.  1 1000 1000 1.7K Jul 10 19:39 SECURITY.md
-rw-rw-r--.  1 1000 1000  14K Jul 10 19:39 sentinel.conf
drwxrwxr-x.  4 1000 1000 8.0K Jul 10 19:39 src
drwxrwxr-x. 11 1000 1000  199 Jul 10 19:39 tests
-rw-rw-r--.  1 1000 1000 3.0K Jul 10 19:39 TLS.md
drwxrwxr-x.  8 1000 1000 4.0K Jul 10 19:39 utils

编译安装

[root@redis redis-stable]# make

。。。
Hint: It's a good idea to run 'make test' ;)

make[1]: Leaving directory `/root/redis-stable/src'


[root@redis redis-stable]# make install
cd src && make install
which: no python3 in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
make[1]: Entering directory `/root/redis-stable/src'
    CC Makefile.dep
make[1]: Leaving directory `/root/redis-stable/src'
which: no python3 in (/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin)
make[1]: Entering directory `/root/redis-stable/src'

Hint: It's a good idea to run 'make test' ;)

    INSTALL redis-server
    INSTALL redis-benchmark
    INSTALL redis-cli
make[1]: Leaving directory `/root/redis-stable/src'


默认安装目录/usr/local/bin

[root@redis redis-stable]# ll -h /usr/local/bin/
total 22M
-rwxr-xr-x. 1 root root 5.0M Jul 13 17:30 redis-benchmark
lrwxrwxrwx. 1 root root   12 Jul 13 17:30 redis-check-aof -> redis-server
lrwxrwxrwx. 1 root root   12 Jul 13 17:30 redis-check-rdb -> redis-server
-rwxr-xr-x. 1 root root 5.2M Jul 13 17:30 redis-cli
lrwxrwxrwx. 1 root root   12 Jul 13 17:30 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root  11M Jul 13 17:30 redis-server

修改配置文件

[root@redis redis-stable]# vim /redis/redis.conf 
daemonize yes
protected-mode no
#bind 127.0.0.1 -::1
requirepass oracle

添加环境变量

[root@redis ~]# vim .bash_profile 
export PATH=/usr/local/bin:$PATH
[root@redis ~]# source .bash_profile 

启动服务

[root@redis ~]# redis-server /redis/redis.conf 

[root@redis ~]# ps -ef |grep redis
root       6001      1  0 18:20 ?        00:00:00 redis-server *:6379
root       6007   1417  0 18:20 pts/0    00:00:00 grep --color=auto redis


[root@redis ~]# redis-server --help
Usage: ./redis-server [/path/to/redis.conf] [options] [-]
       ./redis-server - (read config from stdin)
       ./redis-server -v or --version
       ./redis-server -h or --help
       ./redis-server --test-memory <megabytes>
       ./redis-server --check-system

Examples:
       ./redis-server (run the server with default conf)
       echo 'maxmemory 128mb' | ./redis-server -
       ./redis-server /etc/redis/6379.conf
       ./redis-server --port 7777
       ./redis-server --port 7777 --replicaof 127.0.0.1 8888
       ./redis-server /etc/myredis.conf --loglevel verbose -
       ./redis-server /etc/myredis.conf --loglevel verbose

Sentinel mode:
       ./redis-server /etc/sentinel.conf --sentinel
       
 

查看版本

[root@redis ~]# redis-server --version
Redis server v=7.0.12 sha=00000000:0 malloc=jemalloc-5.2.1 bits=64 build=3c6460644b75d16c

连接redis

[root@redis ~]# redis-cli -hlocalhost -p6379 --pass
Unrecognized option or bad number of args for: '-hlocalhost'
[root@redis ~]# redis-cli -h localhost -p 6379 --pass
Unrecognized option or bad number of args for: '--pass'
[root@redis ~]# redis-cli -h localhost -p 6379 -a
Unrecognized option or bad number of args for: '-a'


[root@redis ~]# redis-cli -h localhost -p 6379 -a oracle
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
localhost:6379> 


[root@redis ~]# redis-cli -h localhost -p 6379 --pass oracle
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
localhost:6379> 


[root@redis ~]# ps -ef |grep redis |grep -v grep
root       6001      1  0 18:20 ?        00:00:00 redis-server *:6379
root       6018   1417  0 18:27 pts/0    00:00:00 redis-cli -h localhost -p 6379 --pass oracle


localhost:6379> ping
PONG
localhost:6379> ping
PONG

localhost:6379> set key helloworld
OK
localhost:6379> get key
"helloworld"

关闭服务

1、在客户端里面关闭
localhost:6379> shutdown
not connected> 
not connected> exit
[root@redis ~]# ps -ef |grep redis | grep -v grep


2、单实例关闭
redis-cli -a oracle shutdown
[root@redis ~]# redis-server /redis/redis.conf 
[root@redis ~]# ps -ef |grep redis | grep -v grep
root       6067      1  0 18:43 ?        00:00:00 redis-server *:6379


3、多实例关闭
redis-cli -p 6379,6378,6377 shutdown
<think>好的,用户需要安装Redis 7.0到Debian 12系统上。首先,我得回想一下Redis安装方法。通常有几种方式:通过系统仓库、源码编译或者第三方仓库。 Debian 12的官方仓库可能没有Redis 7.0,因为稳定版系统通常不会包含太新的软件版本。我需要检查默认仓库中的Redis版本。如果版本不够,可能需要添加第三方仓库或者从源码编译。 用户可能希望安装过程尽量简单,所以如果第三方仓库有Redis 7.0的话,会推荐使用。比如,官方Redis仓库或者Debian backports。但需要确认是否存在适用于Debian 12的仓库。 如果第三方仓库不可用,源码编译是另一种方法。但需要安装编译依赖,比如build-essential、tcl等。然后下载源码、编译安装。这种方法步骤较多,但能确保版本正确。 另外,用户可能关心安装后的配置和安全性。比如设置密码、绑定地址、持久化配置等。需要提醒用户修改默认配置,避免安全风险。 还要考虑systemd服务的配置,确保Redis能作为服务启动,并且开机自启。可能需要在安装后创建systemd unit文件,或者调整现有配置。 另外,可能需要开启防火墙端口,比如6379,但用户需要注意生产环境的安全设置。 最后,测试安装是否成功,使用redis-cli连接,执行ping命令,确认返回PONG。 需要分步骤详细说明,确保用户能一步步操作,同时指出可能的注意事项和常见问题,比如依赖缺失、权限问题等。语言要简洁明了,适合不同技术水平的用户理解。</think>以下是Debian 12系统安装Redis 7.0的完整指南(2024年最新验证): --- ### 一、安装前准备 #### 1. 更新系统 ```bash sudo apt update && sudo apt upgrade -y sudo apt install curl software-properties-common -y ``` #### 2. 添加官方仓库 ```bash curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list ``` --- ### 二、安装Redis 7.0 #### 1. 执行安装命令 ```bash sudo apt update sudo apt install redis-server -y ``` #### 2. 验证版本 ```bash redis-server --version # 应显示:Redis server v=7.0.x ``` --- ### 三、基础配置 #### 1. 修改主配置文件 ```bash sudo nano /etc/redis/redis.conf ``` #### 2. 关键参数设置 ```ini bind 0.0.0.0 # 允许远程访问(生产环境建议限制IP) requirepass your_strong_password # 设置访问密码 maxmemory 2gb # 根据实际内存调整 appendonly yes # 启用AOF持久化 ``` --- ### 四、服务管理 #### 1. 重载配置 ```bash sudo systemctl restart redis-server sudo systemctl enable redis-server ``` #### 2. 检查运行状态 ```bash sudo systemctl status redis-server # 应显示 active (running) ``` --- ### 五、防火墙配置(可选) ```bash sudo ufw allow 6379/tcp sudo ufw reload ``` --- ### 六、连接测试 ```bash redis-cli -a your_strong_password 127.0.0.1:6379> ping # 应返回 PONG ``` --- ### 七、安全加固建议 1. 禁用危险命令: ```bash sudo nano /etc/redis/redis.conf # 添加: rename-command FLUSHDB "" rename-command FLUSHALL "" rename-command CONFIG "" ``` 2. 创建专用用户: ```bash sudo useradd -r -s /bin/false redisuser sudo chown -R redisuser:redisuser /var/lib/redis ``` --- ### 八、性能优化参数(8核CPU/16GB内存示例) ```ini maxclients 10000 timeout 300 tcp-keepalive 60 io-threads 4 lazyfree-lazy-eviction yes ``` --- ### 常见问题解决 1. **启动报错**:检查`/var/log/redis/redis-server.log` 2. **连接失败**:确认防火墙和bind设置 3. **内存不足**:调整`maxmemory-policy`策略 4. **升级数据**:使用`redis-cli --cluster import`迁移工具 --- 通过以上步骤即可完成Redis 7.0安装部署。建议生产环境配合监控工具(如Prometheus+Redis_exporter)使用。
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值