Centos7安装Redis6.0.8指南

Redis的安装

安装环境

  • redis-6.0.8
  • centos 7

下载与解压

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

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

# cd /usr/local
# wget wget http://download.redis.io/releases/redis-6.0.8.tar.gz
# tar -zxvf redis-6.0.8.tar.gz

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

安装

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

# cd redis-6.0.8
# make
# make install PREFIX=/usr/local/redis 

具体安装过程可以查询redis-6.0.8目录下的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) {
               ^

需要升级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

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

安装成系统服务

配置redis环境变量:

# vi /etc/profile
增加如下内容
export REDIS_HOME=/usr/local/redis
export PATH=$PATH:$REDIS_HOME/bin
# source /etc/profile

进入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!

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

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

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

# systemctl stop redis_6379
# systemctl status redis_6379
# systemctl start redis_6379

运行脚本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!

打开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

redis.conf配置

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

开启守护进程模式

daemonize yes

daemonize设置yes或者no区别:

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

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

# bind 127.0.0.1

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

protected-mode no

运行客户端

# redis-cli 
127.0.0.1:6379> set hello world
OK
127.0.0.1:6379> get hello
"world"
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值