1.获取资源路径
redis官网:https://redis.io/download
获得资源路径:http://download.redis.io/releases/redis-6.0.6.tar.gz
2.服务器安装wget
yum install wget
3.解压
#我选择下载到/usr/local目录下
cd /usr/local
#下载
wget http://download.redis.io/releases/redis-6.0.6.tar.gz
#解压
tar -zxvf redis-6.0.6.tar.gz
4.编译
cd redis-6.0.6
make
make这步大概率会报错
1)如果报错 cc:command not found,是因为缺少gcc
请执行以下操作:
安装gcc
yum install gcc
清理一下
make distclean
再次编译
make
2)如果报错:make[1]: *** [server.o] Error 1 …,是因为gcc默认安装的gcc是4.8.5,版本过低,需要升级
请执行以下操作:
#6以上要求gcc版本号在5以上
#Centos7 gcc版本默认4.8.3,Red Hat 为了软件的稳定和版本支持,yum 上版本也是4.8.3,所以无法使用yum进行软件更新,所以使用scl。
scl软件集(Software Collections),是为了给 RHEL/CentOS 用户提供一种以方便、安全地安装和使用应用程序和运行时环境的多个(而且可能是更新的)版本的方式,同时避免把系统搞乱
yum -y install centos-release-scl scl-utils-build
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash
echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile
#查看版本号
gcc -v
清理一下
cd /usr/local/redis-6.0.6
make distclean
再次编译
make
5.配置环境变量
从源码中把可执行文件迁出
make install PREFIX=/usr/local/redis6
vi /etc/profile
增加以下内容:
export REDIS_HOME=/user/local/redis6
export PATH=$PATH:$REDIS_HOME/bin
#使配置生效
source /etc/profile
#验证
echo $PATH
6.创建redis实例
cd /opt/redis-6.0.6/utils/
./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 t hem. Sorry!
解决方案:
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 install them. Sorry!"
# exit 1
#fi
然后重新运行 ./install_server.sh
即可。
#查看该实例的运行状态
service redis_6379 status
#停止
service redis_6379 stop
#启动
service redis_6379 start