Ubuntu22.04安装最新版Redis-7.0.10

1. 修改Ubuntu的下载源

        将Ubuntu的镜像源配置为阿里云或清华云,不然下载会很慢。

1.1 查看系统版本

        按照不同版本选择不同的镜像源。

root@sd:/# 
root@sd:/# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.1 LTS
Release:        22.04
Codename:       jammy
root@sd:/# 

1.2 修改配置文件

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
sudo nano /etc/apt/sources.list


## 将下面的内容替换原来的内容

# aliyun
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse

# 更新系统资源
sudo apt-get update

2.上传压缩包到Ubuntu并解压

Ubuntu22.04安装最新版Redis-7.0.10_第1张图片

## 利用finalshell连接Ubuntu,执行下面两步后,会弹出一个窗口,选择压缩包上传即可
# apt install lrzsz
# rz -be

# 解压缩的目录不宜过深

# tar -zxvf redis-7.0.10.tar.gz

3.安装相关工具

sudo apt-get install -y gcc
sudo apt-get install -y g++
sudo apt-get install -y gcc automake autoconf libtool make

4.编译Redis源码

# 进入Redis目录
root@sd:/Java/Redis# cd redis-7.0.10
# 编译
root@sd:/Java/Redis/redis-7.0.10# make MALLOC=libc

# 新建SERVER文件夹,通过以下命令进行测试,将生成的可执行文件(bin目录)拷贝到/Java/SERVER/redis-7.0.10下
root@sd:/Java/Redis/redis-7.0.10# make test && make install PREFIX=/Java/SERVER/redis-7.0.10

# 出现以下结果表示操作成功

  0 seconds - defrag
  1 seconds - violations

\o/ All tests passed without errors!

Cleanup: may take some time... OK
make[1]: 离开目录“/Java/Redis/redis-7.0.10/src”
cd src && make install
make[1]: 进入目录“/Java/Redis/redis-7.0.10/src”
/bin/sh: 1: pkg-config: not found

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

    INSTALL redis-server
    INSTALL redis-benchmark
    INSTALL redis-cli
make[1]: 离开目录“/Java/Redis/redis-7.0.10/src”
root@sd:/Java/Redis/redis-7.0.10# 

# 进入Java/SERVER目录进行查看
root@sd:/Java/SERVER/redis-7.0.10/bin# ls -al
总计 9520
drwxr-xr-x 2 root root    4096  3月 25 08:41 .
drwxr-xr-x 3 root root    4096  3月 25 08:41 ..
-rwxr-xr-x 1 root root 1247576  3月 25 08:41 redis-benchmark
lrwxrwxrwx 1 root root      12  3月 25 08:41 redis-check-aof -> redis-server
lrwxrwxrwx 1 root root      12  3月 25 08:41 redis-check-rdb -> redis-server
-rwxr-xr-x 1 root root 1130280  3月 25 08:41 redis-cli
lrwxrwxrwx 1 root root      12  3月 25 08:41 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 7356704  3月 25 08:41 redis-server
root@sd:/Java/SERVER/redis-7.0.10/bin# 

5.修改Redis配置文件

# 进入SERVER文件夹,创建log和data文件夹,把原来目录的redis.conf配置文件复制到当前目录
cd /Java/SERVER/redis-7.0.10 
mkdir -p /Java/SERVER/redis-7.0.10/log  
mkdir -p //Java/SERVER/redis-7.0.10/data   
cp ../../Redis/redis-7.0.10/redis.conf ./  


# 进入【配置文件】,做以下修改
vim  redis.conf  

# 87行
# 87 bind 127.0.0.1 -::1
# bind localhost

# 如果要绑定虚拟机的ip,进行下面一步操作
# 111 protected-mode yes
# protected-mode no


# 309行
# 309 daemonize no
# daemonize yes

# 354行
# 354 logfile ""
# logfile  "/Java/SERVER/redis-7.0.10/log/redis.log" 

# 504行  
# 504 dir ./
# dir /Java/SERVER/redis-7.0.10/data 

# 修改完成保存退出

6.启动Redis

Ubuntu22.04安装最新版Redis-7.0.10_第2张图片

# cd /Java/SERVER/redis-7.0.10/bin/
# ./redis-server ../redis.conf  

# 查看启动日志
root@sd:/Java/SERVER/redis-7.0.10/log# tail -30f redis.log 
123790:C 25 Mar 2023 09:33:31.376 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
123790:C 25 Mar 2023 09:33:31.377 # Redis version=7.0.10, bits=64, commit=00000000, modified=0, pid=123790, just started
123790:C 25 Mar 2023 09:33:31.377 # Configuration loaded
123790:M 25 Mar 2023 09:33:31.378 * Increased maximum number of open files to 10032 (it was originally set to 1024).
123790:M 25 Mar 2023 09:33:31.378 * monotonic clock: POSIX clock_gettime
123790:M 25 Mar 2023 09:33:31.380 * Running mode=standalone, port=6379.
123790:M 25 Mar 2023 09:33:31.380 # Server initialized
123790:M 25 Mar 2023 09:33:31.380 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
123790:M 25 Mar 2023 09:33:31.380 * Ready to accept connections


# 查看redis是否启动成功--netstat -antp | grep 6379
root@sd:/Java/SERVER/redis-7.0.10/log# netstat -antp | grep 6379
tcp        0      0 192.158.343.568:6379     0.0.0.0:*               LISTEN      123790/bin/redis-se 
root@sd:/Java/SERVER/redis-7.0.10/log#

7.关闭Redis

./redis-cli  -h localhost shutdown  

8.客户端连接

cd /Java/SERVER/redis-7.0.10/bin/ 
./redis-cli -h localhost -p 6379

你可能感兴趣的:(Java的Redis,ubuntu,linux,运维,redis)