前言
今天想试试最新版本的Redis,于是乎发现Redis6.x版本要求多了。这里记录下教程,需要的可以查看下。
Redis6.0.9安装需求
Redis6.0以上对gcc版本有要求(5.3)以上,而centos7.6默认安装4.8.5。所以需要升级gcc版本。
升级GCC
# yum -y install centos-release-scl
# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
# scl enable devtoolset-9 bash
# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/rh/devtoolset-9/root/usr/libexec/gcc/x86_64-redhat-linux/9/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,fortran,lto --prefix=/opt/rh/devtoolset-9/root/usr --mandir=/opt/rh/devtoolset-9/root/usr/share/man --infodir=/opt/rh/devtoolset-9/root/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-gcc-major-version-only --with-linker-hash-style=gnu --with-default-libstdcxx-abi=gcc4-compatible --enable-plugin --enable-initfini-array --with-isl=/builddir/build/BUILD/gcc-9.3.1-20200408/obj-x86_64-redhat-linux/isl-install --disable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
Thread model: posix
gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC)
其中上面scl命令启用只是临时的,退出shell或重新打开一个shell就会恢复原系统gcc版本,所以需要执行以下命令永久使用gcc 9。
# echo "source /opt/rh/devtoolset-9/enable" >> /etc/profile
# . ~/.bash_profile
# which gcc
/opt/rh/devtoolset-9/root/usr/bin/gcc
如果没有生效环境变量,则需要重新登录再看看gcc版本。
编译
[testerzhang@VM-8-7-centos redis-6.0.9]$ mkdir -p bm/redis-6.0.9
[testerzhang@VM-8-7-centos redis-6.0.9]$ cd bm/redis-6.0.9
[testerzhang@VM-8-7-centos redis-6.0.9]$ wget https://download.redis.io/releases/redis-6.0.9.tar.gz?_ga=2.232216794.43188584.1606029760-1221876175.1606029760 -O redis-6.0.9.tar.gz
[testerzhang@VM-8-7-centos redis-6.0.9]$ tar zxf redis-6.0.9.tar.gz
[testerzhang@VM-8-7-centos redis-6.0.9]$ cd redis-6.0.9
[testerzhang@VM-8-7-centos redis-6.0.9]$ mkdir -p ~/3rd/redis-6.0.9
[testerzhang@VM-8-7-centos redis-6.0.9]$ make
[testerzhang@VM-8-7-centos redis-6.0.9]$ make PREFIX=/home/testerzhang/3rd/redis-6.0.9 install
[testerzhang@VM-8-7-centos redis-6.0.9]$ cp redis.conf ~/3rd/redis-6.0.9/bin/
查看编译后的文件安装目录
[testerzhang@VM-8-7-centos bin]$ pwd
/home/testerzhang/3rd/redis-6.0.9/bin
[testerzhang@VM-8-7-centos bin]$ ls
redis-benchmark redis-check-aof redis-check-rdb redis-cli redis.conf redis-sentinel redis-server
启动Redis
- 编辑配置文件(这里列举一些重要的配置项)
[testerzhang@VM-8-7-centos bin]$ pwd
/home/testerzhang/3rd/redis-6.0.9/bin
[testerzhang@VM-8-7-centos bin]$ vi redis.conf
# bind 127.0.0.1 ::1
bind 127.0.0.1
#port 6379
port 16379
# requirepass foobared
requirepass testerzhang
- 启动命令
$ ./redis-server redis.conf
如果是后台运行,则可以加上nohup命令
$ nohup ./redis-server redis.conf &
验证 Redis服务
[testerzhang@VM-8-7-centos bin]$ pwd
/home/testerzhang/3rd/redis-6.0.9/bin
[testerzhang@VM-8-7-centos bin]$ ./redis-cli -p 16379
127.0.0.1:16379> auth testerzhang
OK
127.0.0.1:16379> set name 123
OK
127.0.0.1:16379> get name
"123"
至此,Redis6.0.9版本安装完毕。
网友评论