• Centos7 安装Redis


    系统环境和版本说明

    Linux依然使用的是Centos7,安装的redis是官网的最新的版本4.0.2

    安装步骤

    下载安装包:
    https://redis.io/download

    创建文件目录:

    # mkdir /usr/local/redis
    

    解压文件

    # tar xvfz redis-4.0.2.tar.gz
    

    进入解压文件

    # cd /usr/local/redis/redis-4.0.2/
    # ls
    总用量 280
    -rw-rw-r--.  1 root root 131381 9月  21 22:12 00-RELEASENOTES
    -rw-rw-r--.  1 root root     53 9月  21 22:12 BUGS
    -rw-rw-r--.  1 root root   1815 9月  21 22:12 CONTRIBUTING
    -rw-rw-r--.  1 root root   1487 9月  21 22:12 COPYING
    drwxrwxr-x.  6 root root   4096 9月  21 22:12 deps
    -rw-rw-r--.  1 root root     11 9月  21 22:12 INSTALL
    -rw-rw-r--.  1 root root    151 9月  21 22:12 Makefile
    -rw-rw-r--.  1 root root   4223 9月  21 22:12 MANIFESTO
    -rw-rw-r--.  1 root root  20530 9月  21 22:12 README.md
    -rw-rw-r--.  1 root root  57764 9月  21 22:12 redis.conf
    -rwxrwxr-x.  1 root root    271 9月  21 22:12 runtest
    -rwxrwxr-x.  1 root root    280 9月  21 22:12 runtest-cluster
    -rwxrwxr-x.  1 root root    281 9月  21 22:12 runtest-sentinel
    -rw-rw-r--.  1 root root   7606 9月  21 22:12 sentinel.conf
    drwxrwxr-x.  3 root root   4096 9月  21 22:12 src
    drwxrwxr-x. 10 root root   4096 9月  21 22:12 tests
    drwxrwxr-x.  8 root root   4096 9月  21 22:12 utils
    

    配置编译环境

    # yum install gcc-c++
    

    编译

    # make
    

    如果报错:jemalloc/jemalloc.h:没有那个文件或目录
    使用:

    make MALLOC=libc
    
    # make install
    cd src && make install
    make[1]: 进入目录“/usr/local/redis/redis-4.0.2/src”
        CC Makefile.dep
    make[1]: 离开目录“/usr/local/redis/redis-4.0.2/src”
    make[1]: 进入目录“/usr/local/redis/redis-4.0.2/src”
    
    Hint: It's a good idea to run 'make test' ;)
    
        INSTALL install
        INSTALL install
        INSTALL install
        INSTALL install
        INSTALL install
    make[1]: 离开目录“/usr/local/redis/redis-4.0.2/src”
    

    启动Redis-server

    # redis-server
    


    Ctrl+shift+t 重开一个终端tab
    查看Redis

    $ ps -ef | grep redis
    root       5188   3749  0 22:46 pts/0    00:00:00 redis-server *:6379
    xcx        5235   5200  0 22:46 pts/1    00:00:00 grep --color=auto redis
    
    

    启动Redis-client

    $ redis-cli
    127.0.0.1:6379> ping
    PONG
    127.0.0.1:6379> 
    
    

    基本安装完成

    此时重启系统,发现redis并没有启动,所以需要设置redis自启,
    这里我们进入utils文件夹

    # cd /usr/local/redis/redis-4.0.2/utils
    

    切换root用户,执行里面的install_server.sh该文件会帮助我们将redis服务添加到系统自启服务中

    # ./install_server.sh 
    Welcome to the redis service installer
    This script will help you easily set up a running redis server
    
    Please select the redis port for this instance: [6379] 
    Selecting default: 6379
    Please select the redis config file name [/etc/redis/6379.conf] 
    Selected default - /etc/redis/6379.conf
    Please select the redis log file name [/var/log/redis_6379.log] 
    Selected default - /var/log/redis_6379.log
    Please select the data directory for this instance [/var/lib/redis/6379] 
    Selected default - /var/lib/redis/6379
    Please select the redis executable path [/usr/local/bin/redis-server] 
    Selected config:
    Port           : 6379
    Config file    : /etc/redis/6379.conf
    Log file       : /var/log/redis_6379.log
    Data dir       : /var/lib/redis/6379
    Executable     : /usr/local/bin/redis-server
    Cli Executable : /usr/local/bin/redis-cli
    Is this ok? Then press ENTER to go on or Ctrl-C to abort.
    Copied /tmp/6379.conf => /etc/init.d/redis_6379
    Installing service...
    Successfully added to chkconfig!
    Successfully added to runlevels 345!
    Starting Redis server...
    Installation successful!
    
    

    这是再重启系统,就会发现redis跟随系统自动启动了

    如果需要外部访问,需要修改配置文件:

    # vim /etc/redis/6379.conf
    
    #bind 127.0.0.1
    bind 0.0.0.0
    #daemonize no
    daemonize yes
    

    防火墙开放6379端口

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

    重启redis服务后就可以外部访问了

  • 相关阅读:
    Opennebula4.2管理端和节点SSH模式的安装配置
    shell操作mysql之增删改查
    Linux常用服务部署与优化之NFS篇
    Linux常用服务部署与优化之Samba篇
    sql编程小结
    mysql5.7.11编译安装以及修改root密码小结
    基于centOS6.7搭建LAMP(httpd-2.4.18+mysql-5.5.47+php-5.6.16)环境
    php实现文件上传下载功能小结
    zabbix搭建
    mysql主从复制
  • 原文地址:https://www.cnblogs.com/yxdz/p/7633257.html
Copyright © 2020-2023  润新知