Linux系统下安装Redis-7.0.0

一、准备工作
1、下载安装新版的gcc编译器
redis的安装需要gcc环境的支持,所以首先要检查下服务器上时候已经安装了gcc环境。
离线安装gcc包
执行安装命令:

rpm  -ivh  *.rpm --nodeps --force

1.1 下载Redis客户端
Redis官方网站:Download | Redis Redis中文官方网站:CRUG网站 (redis.cn)
可以直接通过上图的Redis官网平台下载安装包,下载后的安装包要通过FTP工具上传到linux环境下,这里我使用Linux自带的命令行工具下载省去了FTP上传的操作,如下:

# 通过命令行下载
wget http://download.redis.io/releases/redis-7.0.0.tar.gz
--2022-05-27 09:05:26--  http://download.redis.io/releases/redis-7.0.0.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|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2943054 (2.8M) [application/octet-stream]
Saving to: ‘redis-7.0.0.tar.gz’
100%[============================================================================================================================================================>] 2,943,054   4.02MB/s   in 0.7s   
2022-05-08 11:05:27 (4.02 MB/s) - ‘redis-7.0.0.tar.gz’ saved [2943054/2943054]
# 检查下载文件是否成功
[root@ys software]# ll -l
total 2876
-rw-r--r--. 1 root root 2943054 Apr 27 21:46 redis-7.0.0.tar.gz
[root@ys software]# 
# 解压到本地
[root@ys software]# tar -zxvf redis-7.0.0.tar.gz
# 拷贝解压后的安装文件到目录下
[root@ys local]# cp -r /home/software/redis-7.0.0 /usr/local/
[root@ys local]# cd redis-7.0.0/
[root@ys redis-7.0.0]# ls
00-RELEASENOTES  CONDUCT       COPYING  INSTALL   MANIFESTO  redis.conf  runtest-cluster    runtest-sentinel  sentinel.conf  tests   utils
BUGS             CONTRIBUTING  deps     Makefile  README.md  runtest     runtest-moduleapi  SECURITY.md       src            TLS.md
[root@ys redis-7.0.0]# 

二、安装Redis
2.1 编译安装

# 安装redis
[root@ys redis-7.0.0]# make && make install

2.2 检查安装

[root@ys redis-7.0.0]# cd src/
[root@ys src]# ./redis-server 
9491:C 08 May 2022 10:08:11.830 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
9491:C 08 May 2022 10:08:11.830  # Redis version=7.0.0, bits=64, commit=00000000, modified=0, pid=9691, just started
9491:C 08 May 2022 10:08:11.830  # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
9491:M 08 May 2022 10:08:11.830  * Increased maximum number of open files to 10032 (it was originally set to 1024).
9491:M 08 May 2022 10:08:11.830  * monotonic clock: POSIX clock_gettime
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 7.0.0 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                  
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 9491
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           https://redis.io       
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               
 
9491:M 08 May 2022 10:08:11.830  # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
9491:M 08 May 2022 10:08:11.830  # Server initialized
9491:M 08 May 2022 10:08:11.830  # WARNING overcommit_memory is set to 0! Background save 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.
9491:M 08 May 2022 10:08:11.830  * The AOF directory appendonlydir doesn't exist
9491:M 08 May 2022 10:08:11.830  * Ready to accept connections

到这里我们的redsi已经安装成功,运行版本是7.0.0,默认端口号为6379。

2.3 配置环境
在redis-7.0.0目录下面创建配置conf文件夹和data文件夹,先复制一份redis.conf到conf文件夹下面

[root@ys redis-7.0.0]# mkdir conf
[root@ys redis-7.0.0]# mkdir data
[root@ys redis-7.0.0]# ls
00-RELEASENOTES  CONDUCT  CONTRIBUTING  data  INSTALL   MANIFESTO  redis.conf  runtest-cluster    runtest-sentinel  sentinel.conf  tests   utils
BUGS             conf     COPYING       deps  Makefile  README.md  runtest     runtest-moduleapi  SECURITY.md       src            TLS.md
[root@ys redis-7.0.0]# cp redis.conf conf/
[root@ys redis-7.0.0]# cd conf/
[root@ys conf]# ls
redis.conf

修改配置文件,并设置启动模式为后台模式,绑定ip修改为0.0.0.0,支持远程登录。

# 默认绑定
bind 0.0.0.0 -::1
# 监听端口号
port 6379
# 是否守护进程,改成yes以后会以后台运行模式启动
daemonize no
# 日志文件名称
logfile "redis-6379.log"
# 指定data存放路径
dir /usr/local/redis-7.0.0/data

配置文件以后查看redis的运行状态,OK,运行成功了。

[root@huxing redis-7.0.0]# redis-server conf/redis-6379.conf 
[root@huxing redis-7.0.0]# ps -ef|grep redis
root       9629      1  0 10:11 ?        00:00:00 redis-server 0.0.0.0:6379
root       9635   4890  0 10:11 pts/0    00:00:00 grep --color=auto redis
[root@ys redis-7.0.0]# redis-cli -p 6379
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> 

2.4 设置开机启动
编辑开机启动脚本

[root@ys redis-7.0.0]# cd /etc/init.d/
[root@ys init.d]# vim /etc/init.d/redis_init_script

复制下面的脚本内容到脚本文件中

#!/bin/sh
# description: Start and Stop redis,Redis is a persistent key-value database   
# chkconfig: 2345 90 10
 
# redis端口号
REDISPORT=6379
# 指定运行的客户端
EXEC=/usr/local/bin/redis-server
# 客户端
CLIEXEC=/usr/local/bin/redis-cli
# 进程号
PIDFILE=/var/run/redis_${REDISPORT}.pid
# 核心配置文件
CONF="/usr/local/redis-7.0.0/conf/redis-6379.conf"
 
case "$1" in
    start)
        if [ -f $PIDFILE ]
        then
                echo "$PIDFILE exists, process is already running or crashed"
        else
                echo "Starting Redis server..."
                $EXEC $CONF &
        fi
        ;;
    stop)
        if [ ! -f $PIDFILE ]
        then
                echo "$PIDFILE does not exist, process is not running"
        else
                PID=$(cat $PIDFILE)
                echo "Stopping ..."
                $CLIEXEC -p $REDISPORT shutdown
                while [ -x /proc/${PID} ]
                do
                    echo "Waiting for Redis to shutdown ..."
                    sleep 1
                done
                echo "Redis stopped"
        fi
        ;;
    restart)
        "$0" stop
        sleep 3
        "$0" start
        ;;
    *)
        echo "Please use start or stop or restart as first argument"
        ;;
esac

脚本执行检查

# 脚本执行权限修改
[root@ys init.d]# chmod 777 redis_init_script
# 执行命令
[root@ys init.d]# ./redis_init_script start
Starting Redis server...
[root@ys init.d]# ps -ef|grep redis
root       9937      1  0 12:03 ?        00:00:00 /usr/local/bin/redis-server 0.0.0.0:6379
root       9943   4890  0 12:03 pts/0    00:00:00 grep --color=auto redis

开机启动管理

# 添加到开机启动
chkconfig --add redis_init_script
# 开启开机启动
chkconfig redis_init_script on
# 关闭开机启动
chkconfig redis_init_script off
# 从开机启动中删除
chkconfig --del redis_init_script 
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值