zoukankan      html  css  js  c++  java
  • centos7安装redis5

    一、下载包

    [root@iZ2ze6bgt1xmvd4jc0v7nmZ src]# wget http://download.redis.io/releases/redis-5.0.3.tar.gz

    二、解压

    [root@iZ2ze6bgt1xmvd4jc0v7nmZ src]# tar -zxvf redis-5.0.3.tar.gz  

    三、进入源码目录,并编译

    make &&  make install PREFIX=/usr/local/redis

    四、运行

    [root@iZ2ze6bgt1xmvd4jc0v7nmZ bin]# cd /usr/local/redis/bin/
    [root@iZ2ze6bgt1xmvd4jc0v7nmZ bin]# ./redis-server 
    7138:C 06 Apr 2021 14:19:46.160 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    7138:C 06 Apr 2021 14:19:46.160 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=7138, just started
    7138:C 06 Apr 2021 14:19:46.160 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
                    _._                                                  
               _.-``__ ''-._                                             
          _.-``    `.  `_.  ''-._           Redis 5.0.3 (00000000/0) 64 bit
      .-`` .-```.  ```/    _.,_ ''-._                                   
     (    '      ,       .-`  | `,    )     Running in standalone mode
     |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
     |    `-._   `._    /     _.-'    |     PID: 7138
      `-._    `-._  `-./  _.-'    _.-'                                   
     |`-._`-._    `-.__.-'    _.-'_.-'|                                  
     |    `-._`-._        _.-'_.-'    |           http://redis.io        
      `-._    `-._`-.__.-'_.-'    _.-'                                   
     |`-._`-._    `-.__.-'    _.-'_.-'|                                  
     |    `-._`-._        _.-'_.-'    |                                  
      `-._    `-._`-.__.-'_.-'    _.-'                                   
          `-._    `-.__.-'    _.-'                                       
              `-._        _.-'                                           
                  `-.__.-'                                               
    
    7138:M 06 Apr 2021 14:19:46.161 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
    7138:M 06 Apr 2021 14:19:46.161 # Server initialized
    7138:M 06 Apr 2021 14:19:46.161 # 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.
    7138:M 06 Apr 2021 14:19:46.161 # 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.
    7138:M 06 Apr 2021 14:19:46.162 * DB loaded from disk: 0.000 seconds
    7138:M 06 Apr 2021 14:19:46.162 * Ready to accept connections

    成功后,退出

    五、建立/etc/redis目录,用于存放redis配置文件

    [root@iZ2ze6bgt1xmvd4jc0v7nmZ bin]# mkdir /etc/redis

    将源码目录下的redis.conf文件复制到/etc/redis目录下

    [root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# cp /usr/local/src/redis-5.0.3/redis.conf /etc/redis/

    六、修改配置文件,让服务后台启动

    [root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# vim /etc/redis/redis.conf 

    搜索daemonize,将值no改为yes

    daemonize yes

    保存退出

    七、指定配置文件启动redis

    [root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# /usr/local/redis/bin/redis-server /etc/redis/redis.conf 
    7394:C 06 Apr 2021 14:26:35.455 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
    7394:C 06 Apr 2021 14:26:35.455 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=7394, just started
    7394:C 06 Apr 2021 14:26:35.455 # Configuration loaded

    八、设置开机自启动

    新建 redis.service文件

    [root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# vim /etc/systemd/system/redis.service

    添加如下内容

    [Unit]
    Description=redis-server
    After=network.target
    [Service]
    Type=forking
    ExecStart=/usr/local/redis/bin/redis-server /etc/redis/redis.conf
    PrivateTmp=true
    [Install]
    WantedBy=multi-user.target

    保存退出

    依次执行如下命令:

    [root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# systemctl daemon-reload
    [root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# systemctl start redis 
    [root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# systemctl enable redis
    Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /etc/systemd/system/redis.service.

    查询

    [root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# systemctl enable redis
    Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /etc/systemd/system/redis.service.
    [root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# systemctl list-unit-files|grep redis
    redis.service                                 enabled 
    [root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# 

    九、客户端连接数据库

    首先设置软连接

    [root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# ln -s /usr/local/redis/bin/redis-cli /usr/bin/

    再连接数据库

    [root@iZ2ze6bgt1xmvd4jc0v7nmZ home]# redis-cli 
    127.0.0.1:6379>
  • 相关阅读:
    《新土改:土地制度改革焦点难点辨析》:土地涨价要归公并用于城市配套设施,城市化的主角是人,小产权房不应该合法化,四星
    《清明上河图密码》:北宋的福尔摩斯探案,五星
    《中国的人口与城市》:关于中国人口与中国城市的数据分析,4星推荐。
    《集体失忆的黑暗时代》:已故加拿大公共知识分子关于城市规划与人类文明的随笔,三星推荐
    《智慧社会:大数据与社会物理学》:研究人类的想法的流动扩散的规律,四星
    《中国东部三大都市圈城市体系演化机制研究》:博士论文,结论是北上广深城市化规模还是不够,三星推荐
    《中国十亿城民——人类历史上最大规模人口流动背后的故事》:中国城市化将继续,城市对外来务工者应该更友好更包容,三星
    [Javascript] JavaScript赋值时的传值与传址
    [Vue @Component] Pass Props Between Components with Vue Slot Scope & renderless component
    [Dart] Understand Variables and Constants in Dart
  • 原文地址:https://www.cnblogs.com/sky-cheng/p/14621836.html
Copyright © 2011-2022 走看看