zoukankan      html  css  js  c++  java
  • 阿里云 linux centos7中安装redis

    1、下载redis

    wget http://download.redis.io/releases/redis-5.0.7.tar.gz

    2、解压到当前目录

    tar -zvxf redis-5.0.7.tar.gz

    3、复制redis-5.0.7到指定目录

    一般都会将redis目录放置到 /usr/local/redis目录,所以这里输入下面命令将目前在/root目录下的redis-5.0.7文件夹更改目录,同时更改文件夹名称为redis。

    mv /root/redis-5.0.7 /usr/local/redis

    4、编译

    cd /usr/local/redis
    make

    5、安装

    make PREFIX=/usr/local/redis install

    这里多了一个关键字 PREFIX= 这个关键字的作用是编译的时候用于指定程序存放的路径。比如我们现在就是指定了redis必须存放在/usr/local/redis目录。假设不添加该关键字Linux会将可执行文件存放在/usr/local/bin目录,

    库文件会存放在/usr/local/lib目录。配置文件会存放在/usr/local/etc目录。其他的资源文件会存放在usr/local/share目录。这里指定号目录也方便后续的卸载,后续直接rm -rf /usr/local/redis 即可删除redis。

    6、启动redis

    cd /usr/local/redis
    ./bin/redis-server ./redis.conf

    效果如下:

    13452:C 20 Nov 2021 17:11:58.752 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    13452:C 20 Nov 2021 17:11:58.752 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=13452, just started
    13452:C 20 Nov 2021 17:11:58.752 # Configuration loaded
                    _._                                                  
               _.-``__ ''-._                                             
          _.-``    `.  `_.  ''-._           Redis 5.0.7 (00000000/0) 64 bit
      .-`` .-```.  ```\/    _.,_ ''-._                                   
     (    '      ,       .-`  | `,    )     Running in standalone mode
     |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
     |    `-._   `._    /     _.-'    |     PID: 13452
      `-._    `-._  `-./  _.-'    _.-'                                   
     |`-._`-._    `-.__.-'    _.-'_.-'|                                  
     |    `-._`-._        _.-'_.-'    |           http://redis.io        
      `-._    `-._`-.__.-'_.-'    _.-'                                   
     |`-._`-._    `-.__.-'    _.-'_.-'|                                  
     |    `-._`-._        _.-'_.-'    |                                  
      `-._    `-._`-.__.-'_.-'    _.-'                                   
          `-._    `-.__.-'    _.-'                                       
              `-._        _.-'                                           
                  `-.__.-'                                               
    
    13452:M 20 Nov 2021 17:11:58.753 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
    13452:M 20 Nov 2021 17:11:58.753 # Server initialized
    13452:M 20 Nov 2021 17:11:58.753 # 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.
    13452:M 20 Nov 2021 17:11:58.753 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
    13452:M 20 Nov 2021 17:11:58.753 * Ready to accept connections

    redis-server 后面是配置文件,目的是根据该配置文件的配置启动redis服务。redis.conf配置文件允许自定义多个配置文件,通过启动时指定读取哪个即可。

    7、查看redis是否正在运行

    ps -aux | grep redis

    采取端口监听查看方式

    netstat -lanp | grep 6379

    关闭redis

    kill -9 pid

    8、开放端口

    firewall-cmd --zone=public --add-port=6379/tcp --permanent;

    --permanent的作用是使设置永久生效,不加的话机器重启之后失效

    重新载入一下防火墙设置,使设置生效

    firewall-cmd --reload

    可通过如下命令查看是否生效

    firewall-cmd --zone=public --query-port=6379/tcp

    如下命令可查看当前系统打开的所有端口

    firewall-cmd --zone=public --list-ports

    查看防火墙状态

    systemctl status firewalld

    打开防火墙

    systemctl start firewalld

    9、设置阿里云 安全组规则

    阿里云的防火墙中加入redis连接的规则。

    10、远程连接Redis可能无法连接,您只需要修改几个配置文件参数即可

    vim redis.conf

    1)、把protected-mode yes改为protected-mode no(在没有密码的情况下,关闭保护模式)

    2)、注释掉bind 127.0.0.1     (取消绑定本地地址)

    3)、把daemonize no改为daemonize yes   (是否为进程守护,关闭ssh窗口后即是否在后台继续运行)

    11、redis修改密码

    vim redis.conf

    使用/查找requirepass,将注释打开,然后修改redis密码为123456.

    重启redis

    此时可以在redis Desktop manager中进行连接。

  • 相关阅读:
    VSCode
    git CAPTCHA required
    css :active
    节流 防抖
    判断数据类型
    http协议的三次握手和四次挥手
    http协议
    发布网站相关信息
    获取任意两个数之间多个随机数的方法;
    数组中的12个方法;
  • 原文地址:https://www.cnblogs.com/zwh0910/p/15582196.html
Copyright © 2011-2022 走看看