一、 Redis安装包下载
-
官网地址:https://redis.io/
-
下载版本:6.0.9
[root@MyDB1 ~]# mkdir -p /usr/local/software
[root@MyDB1 ~]# cd /usr/local/software/
[root@MyDB1 software]# wget https://download.redis.io/releases/redis-6.0.9.tar.gz
- 查看redis版本
[root@MyDB1 ~]# /usr/local/software/redis-6.0.9/src/redis-server -v
Redis server v=6.0.9 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=2296a8b68801b779
二、升级gcc版本
-
redis6.x.x开始支持多线程,gcc的版本需要大于4.9,而redhat7的gcc版本默认为4.8.5
-
若不升级,安装过程中会报如下的错误:
-
升级版本
① 配置redhat7的yum源(新建该配置文件:/etc/yum.repos.d/my.repo,内容如下:)
# CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-7 - Base #mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=os&infra=$infra baseurl=https://mirrors.ustc.edu.cn/centos/7/os/$basearch/ enabled=1 gpgcheck=0 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-7 #released updates [updates] name=CentOS-7 - Updates #mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=updates&infra=$infra baseurl=https://mirrors.ustc.edu.cn/centos/7/updates/$basearch/ enabled=1 gpgcheck=0 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-7 #additional packages that may be useful [extras] name=CentOS-7 - Extras #mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=extras&infra=$infra baseurl=https://mirrors.ustc.edu.cn/centos/7/extras/$basearch/ enabled=1 gpgcheck=0 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-7 #additional packages that extend functionality of existing packages [centosplus] name=CentOS-7 - Plus #mirrorlist=http://mirrorlist.centos.org/?release=7&arch=$basearch&repo=centosplus&infra=$infra baseurl=https://mirrors.ustc.edu.cn/centos/7/centosplus/$basearch/ enabled=1 gpgcheck=0 #gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-7
② 安装依赖
[root@MyDB1 ~]# yum -y install centos-release-scl [root@MyDB1 ~]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils [root@MyDB1 ~]# scl enable devtoolset-9 bash [root@MyDB1 ~]# echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile [root@MyDB1 ~]# source /etc/profile [root@MyDB1 ~]# gcc -v
三、gcc编译安装
- 安装
[root@MyDB1 ~]# mkdir -p /usr/local/software/
[root@MyDB1 ~]# cd /usr/local/software/
[root@MyDB1 software]# tar -zxvf redis-6.0.9.tar.gz
[root@MyDB1 software]# cd redis-6.0.9/src/
[root@MyDB1 src]# make install
安装成功!
四、修改配置文件
[root@MyDB1 redis-6.0.9]# pwd
/usr/local/software/redis-6.0.9
[root@MyDB1 redis-6.0.9]# vi redis.conf
修改内容如下:
daemonize yes #后台运行
#bind 127.0.0.1 #注释掉该配置,表示允许任何ip地址远程访问
requirepass yourpassword #设置密码(提高安全性,可选)
protected-mode no #关闭保护模式(否则远程无法连接)
五、服务-启动停止
- 启动服务
[root@MyDB1 redis-6.0.9]# ./src/redis-server ./redis.conf
- 验证服务
[root@MyDB1 redis-6.0.9]# ps -ef|grep redis
[root@MyDB1 redis-6.0.9]# netstat -anp|grep 637
- 停止服务
[root@MyDB1 redis-6.0.9]# ./src/redis-cli shutdown
- 客户端连接
[root@MyDB1 redis-6.0.9]# ./src/redis-cli
六、增强-配置别名
[root@MyDB1 ~]# vi .bashrc
[root@MyDB1 ~]# source .bashrc
新增内容如下:
alias redis='/usr/local/software/redis-6.0.9/src/redis-server /usr/local/software/redis-6.0.9/redis.conf'
alias rcli='/usr/local/software/redis-6.0.9/src/redis-cli'
下次使用时即可直接使用别名操作(在任何路径下)
[root@MyDB1 ~]# rcli
127.0.0.1:6379>