CentOS7 安装 Redis6过程

下载redis

cd /opt
yum intall -y wget
wget https://download.redis.io/releases/redis-6.0.9.tar.gz

环境准备

yum install gcc
gcc -v
yum -y install centos-release-scl  # 升级到9.1版本
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash

执行安装

tar -zxvf redis-6.0.9.tar.gz
cd redis-6.0.9
make    #这里如果make出错,可以执行make distclean命令,然后重新 make
make install PREFIX=/opt/soft/redis6  #将redis服务安装到该目录下

配置环境变量

vi /etc/profile
export REDIS_HOME=/opt/soft/redis6
export PATH=$PATH:$REDIS_HOME/bin
source /etc/profile

安装系统服务

这里Redis6版本有一个坑,需要先将install_server.sh文件中的部分内容注释掉,否则会导致无法安装。

cd utils
vi ./install_server.sh

注释掉如下内容

#bail if this system is managed by systemd
#_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 ins
tall them. Sorry!"
#exit 1 
#fi

执行安装

./install_server.sh

如果要在本机上安装多个redis实例,只需要多次执行该脚本,设置不同的端口号即可

安装完成后,在/etc/redis目录下,会有对应端口号的配置文件,比如6379.conf。 后续redis的启动就是依赖该配置文件。

安装完成后的一些其他配置

vi /etc/redis/6379.conf #注意: 这个端口号是在安装的时候所设置的端口号
bind 127.0.0.1 192.168.xxx.xxx(自己机器对应的ip)   #绑定ip地址,使得该redis实例可以与其他实例通信
daemonize yes #后台启动  
protected‐mode no #关闭保护模式,开启的话,只有本机才可以访问redis

然后按ESC,输入 :wq 退出编辑。

启动方式

service redis_端口号 start

这里的端口号就是在执行./install_server.sh时 设置的端口号

service redis_6379 start    #启动redis_6379服务
service redis_6379 status   #查看状态
service redis_6379 restart  #重启服务
service redis_6379 stop     #停止服务   

使用方式

edis-cli #直接连本机redis, 127.0.0.1:6379
redis-cli -h 192.168.xxx.xxx -p 6379  #连接指定ip和端口的redis服务, 前提是该redis服务允许被外部访问

你可能感兴趣的:(CentOS7 安装 Redis6过程)