当前位置: 首页 > news >正文

Centos8安装redis7

1.下载:

官网下载:Download | Redis

把安装包上传至服务器:

2.安装:

  1. 解压redis:

    [root@node202 ~]# cd /usr/local/soft/
    [root@node202 soft]# tar -zxvf redis-7.0.11.tar.gz 
    
  2. 安装:

    进入redis-7.0.11文件夹:

    [root@node202 soft]# cd redis-7.0.11/
    #安装必要类库
    [root@node202 redis-7.0.11]# yum -y install gcc automake autoconf libtool make
    [root@node202 redis-7.0.11]# make & make install
    
  3. 启动:

    [root@node202 redis-7.0.11]# cd src
    [root@node202 src]# ./redis-server /usr/local/soft/redis-7.0.11/redis.conf 
    
    打印启动日志:
    
    8789:C 11 May 2023 01:53:49.076 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    8789:C 11 May 2023 01:53:49.076 # Redis version=7.0.11, bits=64, commit=00000000, modified=0, 	pid=8789, just started
    8789:C 11 May 2023 01:53:49.076 # Configuration loaded
    8789:M 11 May 2023 01:53:49.077 * Increased maximum number of open files to 10032 (it was 	originally set to 1024).
    8789:M 11 May 2023 01:53:49.077 * monotonic clock: POSIX clock_gettime_._                                                  _.-``__ ''-._                                             _.-``    `.  `_.  ''-._           Redis 7.0.11 (00000000/0) 64 bit.-`` .-```.  ```\/    _.,_ ''-._                                  
    (    '      ,       .-`  | `,    )     Running in standalone mode|`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379|    `-._   `._    /     _.-'    |     PID: 8789`-._    `-._  `-./  _.-'    _.-'                                   |`-._`-._    `-.__.-'    _.-'_.-'|                                  |    `-._`-._        _.-'_.-'    |           https://redis.io       `-._    `-._`-.__.-'_.-'    _.-'                                   |`-._`-._    `-.__.-'    _.-'_.-'|                                  |    `-._`-._        _.-'_.-'    |                                  `-._    `-._`-.__.-'_.-'    _.-'                                   `-._    `-.__.-'    _.-'                                       `-._        _.-'                                           `-.__.-'                                               8789:M 11 May 2023 01:53:49.078 # WARNING: The TCP backlog setting of 511 cannot be 	enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
    8789:M 11 May 2023 01:53:49.078 # Server initialized
    8789:M 11 May 2023 01:53:49.078 # WARNING Memory overcommit must be enabled! Without it, a 	background save or replication may fail under low memory condition. Being disabled, it can can also 	cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. 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.
    8789:M 11 May 2023 01:53:49.078 * Ready to accept connections
    
  4. 使用:

    [root@node202 src]# ./redis-cli 
    127.0.0.1:6379> set foo bar
    OK
    127.0.0.1:6379> get foo
    "bar"
    127.0.0.1:6379> 
    

3.配置

  1. 创建一个用于存储 Redis 配置文件目录(/etc/redis)和数据目录(/var/redis):

    mkdir -p /etc/redis
    mkdir -p /var/redis
    
  2. 复制配置文件:

    cp /usr/local/soft/redis-7.0.11/redis.conf /etc/redis/
    
  3. 复制编辑启动脚本:

    cp /usr/local/soft/redis-7.0.11/utils/redis_init_script /etc/init.d/redis
    
    vim /etc/init.d/redis
    #!/bin/sh
    # 
    # Simple Redis init.d script conceived to work on Linux systems
    # as it does use of the /proc filesystem.### BEGIN INIT INFO
    # Provides:     redis_6379
    # Default-Start:        2 3 4 5
    # Default-Stop:         0 1 6
    # Short-Description:    Redis data structure server
    # Description:          Redis data structure server. See https://redis.io
    ### END INIT INFOREDISPORT=6379
    EXEC=/usr/local/bin/redis-server
    CLIEXEC=/usr/local/bin/redis-cliPIDFILE=/var/run/redis_${REDISPORT}.pid
    CONF="/etc/redis/redis.conf"case "$1" in
    start)if [ -f $PIDFILE ]thenecho "$PIDFILE exists, process is already running or crashed"elseecho "Starting Redis server..."$EXEC $CONFfi;;
    stop)if [ ! -f $PIDFILE ]thenecho "$PIDFILE does not exist, process is not running"elsePID=$(cat $PIDFILE)echo "Stopping ..."$CLIEXEC -p $REDISPORT shutdownwhile [ -x /proc/${PID} ]doecho "Waiting for Redis to shutdown ..."sleep 1doneecho "Redis stopped"fi;;
    restart)"$0" stopsleep 3"$0" start;;
    *)echo "Please use start or stop or restart as first argument";;
    esac
    
  4. 设置开机自启动:

    chmod +x /etc/init.d/redis  #给脚本设置权限chkconfig --add redis  #添加redis服务chkconfig redis on  #设置redis服务开机启动
    

完结。

解决服务器Redis无法连接问题

找到你的redis配置文件,进行以下步骤修改。(本人的在/etc/redis.conf,如果找不到,直接创建一个,然后度娘一个默认的redis配置文件粘贴上去即可,启动时使用命令redis-cli +文件路径,下文会讲)

修改bind,默认为bind 127.0.0.1,将其注释(前面加个#),如果没有找到bind 127.0.0.1或已经注释,跳过此步。

# By default Redis listens for connections from all the network interfaces
# available on the server. It is possible to listen to just one or multiple
# interfaces using the "bind" configuration directive, followed by one or
# more IP addresses.
#
# Examples:
# bind 127.0.0.1

关闭保护模式,默认为protected-mode yes,将yes修改为no,如果没有找到protected-mode yes,可以随意另起一行添加protected-mode no;或已经修改为protected-mode no,跳过此步。

# When protected mode is on and if:
#
# 1) The server is not binding explicitly to a set of addresses using the
#    "bind" directive.
# 2) No password is configured.
#
# The server only accepts connections from clients connecting from the
# IPv4 and IPv6 loopback addresses 127.0.0.1 and ::1, and from Unix domain
# sockets.
#
# By default protected mode is enabled. You should disable it only if
# you are sure you want clients from other hosts to connect to Redis
# even if no authentication is configured, nor a specific set of interfaces
# are explicitly listed using the "bind" directive.
protected-mode no

如果有需求,设置密码(没有需求则跳过),添加一行requirepass 123456,作用是设置连接密码为123456,如有需求可以修改密码

################################## SECURITY #################################### Require clients to issue AUTH <PASSWORD> before processing any other
# commands.  This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
# requirepass foobared
requirepass 123456

http://www.lryc.cn/news/66540.html

相关文章:

  • RabbitMQ详解(一):Linux安装
  • Mojo:比 Python 快 35000 倍的 AI 编程语言
  • 1703_LibreOffice常用功能使用体验
  • Postgres:Win/Linux环境安装及一键部署脚本
  • 每日一题144——数组大小减半
  • 运维必懂的13条高效工作秘诀
  • 【牛客刷题专栏】0x26:JZ25 合并两个排序的链表(C语言编程题)
  • 5/5~5/7总结
  • 重要通知|Sui测试网将于5月11日重置
  • 教你快速把heic格式转化jpg,4种方法操作简单
  • 交互式数据分析和处理新方法:pandas-ai =Pandas + ChatGPT
  • FIR滤波
  • Python小姿势 - Python中的类型检查
  • 人工智能前景
  • python并发编程学习笔记--生产者消费者模型 day02
  • 彩蛋丨利用R语言脚本实现批量合并Excel表格,再也不用手动点来点去了!
  • 深入学习MYSQL-数据操纵及视图
  • 深入讲解eMMC简介
  • ICV:中国车载超声波雷达市场规模预计2024年可达20亿美元
  • PointNet:利用深度学习对点云进行3D分类和语义分割
  • 第四十二章 Unity 下拉框 (Dropdown) UI
  • STL常用梳理——STACK、QUEUE
  • Unity物理系统基本概念
  • 防止表单重复提交的几种方式,演示一个自定义注解方式的实现
  • 《基于智能手机采集的PPG信号预测血管老化》阅读笔记
  • 【大数据-调度工具】dolphinscheduler安装和遇到的问题
  • 滑动轨迹生成的思路和代码分享-测试可过极验 90%机率
  • 【Linux】项目自动化构建工具make/makefile
  • 【系分范文】论软件需求获取技术以及应用
  • vue2.0中post请求