zoukankan      html  css  js  c++  java
  • centos7下redis6的安装

    redis的安装

    安装环境

    • redis-6.0.6
    • centos 7

    下载与解压

    下载地址:https://redis.io/download

    下载至/usr/local目录下,并解压

    # cd /usr/local
    # wget wget http://download.redis.io/releases/redis-6.0.6.tar.gz
    # tar -zxvf redis-6.0.6.tar.gz
    
    • 1
    • 2
    • 3

    如果没有安装wget,先安装yum install -y wget

    安装

    make之前确保安装了gcc,未安装则需安装yum install -y gcc

    # cd redis-6.0.6
    # make
    # make install PREFIX=/usr/local/redis 
    
    • 1
    • 2
    • 3

    具体安装过程可以查询redis-6.0.6目录下的README.md文件。

    make命令时linux提供的一个编译命令(类似java中的javac命令),它会在当前目录下查找Makefile文件,根据里面的内容进行安装,与执行maven的mvn命令时,会去查找当前目录下的pom.xml类似。

    安装过程中可能会报一个如下的错误:

    server.c: In function ‘main’:
    server.c:5011:11: error: ‘struct redisServer’ has no member named ‘sentinel_mode’
         server.sentinel_mode = checkForSentinelMode(argc,argv);
               ^
    server.c:5028:15: error: ‘struct redisServer’ has no member named ‘sentinel_mode’
         if (server.sentinel_mode) {
                   ^
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    需要升级GCC版本

    #升级到 5.3及以上版本
    yum -y install centos-release-scl
    yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
    
    scl enable devtoolset-9 bash
    
    #注意:scl命令启用只是临时的,退出xshell或者重启就会恢复到原来的gcc版本。
    #如果要长期生效的话,执行如下:
    echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    先运行make distclean清理上次make失败的文件和目录,再次make。

    安装成系统服务

    配置redis环境变量:

    # vi /etc/profile
    增加如下内容
    export REDIS_HOME=/usr/local/redis
    export PATH=$PATH:$REDIS_HOME/bin
    # source /etc/profile
    
    • 1
    • 2
    • 3
    • 4
    • 5

    进入utils目录执行注册服务脚本install_server.sh

    # cd utils
    # ./install_server.sh 
    Welcome to the redis service installer
    This script will help you easily set up a running redis server
    
    ./install_server.sh: line 82: 3: command not found
    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/redis/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/redis/bin/redis-server
    Cli Executable : /usr/local/redis/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!
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    一个服务器上可以使用这个脚本安装多个redis实例(进程),每个实例都运行的是同一份脚本,但是都拥有不同的数据目录、配置文件、日志文件。

    运行脚本后默认会启动redis。

    以后就可以使用系统服务的命令来操作redis了:

    # systemctl stop redis_6379
    # systemctl status redis_6379
    # systemctl start redis_6379
    
    • 1
    • 2
    • 3

    运行脚本install_server.sh可能会报如下错误:

    This systems seems to use systemd.
    Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!
    
    • 1
    • 2

    打开install_server.sh,注释掉下面的内容:

    #_pid_1_exe="$(readlink -f /proc/1/exe)"
    #if [ "${_pid_1_exe##*/}" = systemd ]
    #then
    #	echo "This systems seems to use systemd."
    #	echo "Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!"
    #	exit 1
    #fi
    #unset _pid_1_exe
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    redis.conf配置

    下面来看一下/etc/redis/6379.conf中配置:

    开启守护进程模式

    daemonize yes
    
    • 1

    daemonize设置yes或者no区别:

    • yes:代表开启守护进程模式,redis会在后台运行,并将进程pid号写入至redis.conf选项pidfile设置的文件中。
    • no:启动将进入redis的命令行界面,exit或者关闭连接工具(putty,xshell等)都会导致redis进程退出。

    去除bind的ip,注释掉下面这一行,否则无法使用远程连接,只能本地连接redis。

    # bind 127.0.0.1
    
    • 1

    关闭保护模式,将protected-mode的yes改为no,也是开启远程连接。

    protected-mode no
    
    • 1

    运行客户端

    # redis-cli 
    127.0.0.1:6379> set hello world
    OK
    127.0.0.1:6379> get hello
    "world"
  • 相关阅读:
    Redis学习(一)认识并安装redis
    并发编程(七)线程如何优雅地终止
    并发编程(六)Object类中线程相关的方法详解
    并发编程(五)线程同步
    并发编程(四)Thread类详解
    并发编程(三)线程池
    并发编程(二)Java中的多线程
    Python学习————作业
    Python学习————作业(面向对象)
    Python学习————面向对象和面向过程
  • 原文地址:https://www.cnblogs.com/xiadongqing/p/13664758.html
Copyright © 2011-2022 走看看