步骤:
首先要安装gcc:yum install gcc-c++
yum安装gcc
下载安装包
wget http://download.redis.io/releases/redis-4.0.9.tar.gz
- 解压
tar -xvf 文件名.tar.gz
- 编译(这个要进入redis目录里)
make - 安装
make install [destdir=/目录]
如果一开始没有安装gcc
会爆错:
/bin/sh: cc: command not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory /root/redis-4.0.9/src' make: *** [install] Error 2 [root@iZbp111cqx7ixgwxewvhy2Z redis-4.0.9]# make install cd src && make install make[1]: Entering directory
/root/redis-4.0.9/src’
CC Makefile.dep
make[1]: Leaving directory /root/redis-4.0.9/src' make[1]: Entering directory
/root/redis-4.0.9/src’
CC adlist.o
/bin/sh: cc: command not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory `/root/redis-4.0.9/src’
make: *** [install] Error 2
解决方法:
yum install gcc-c++
yum安装gcc
make distclean
清空上次编译失败残留文件
make && make install
执行编译及安装
如果是安装的redis6以上版本
记得升级gcc版本,否则报错:
解决方法:
- 查看gcc版本
gcc -v
[root@hadoop01 redis-6.0.5]# gcc -v
使用内建 specs。
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
目标:x86_64-redhat-linux
配置为:../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --disable-libgcj --with-isl=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.5-20150702/obj-x86_64-redhat-linux/cloog-install --enable-gnu-indirect-function --with-tune=generic --with-arch_32=x86-64 --build=x86_64-redhat-linux
线程模型:posix
gcc 版本 4.8.5 20150623 (Red Hat 4.8.5-39) (GCC)
升级gcc版本:
[root@hadoop01 redis-6.0.5]# gcc -v # 查看gcc版本
[root@hadoop01 redis-6.0.5]# yum -y install centos-release-scl # 升级到9.1版本
[root@hadoop01 redis-6.0.5]# yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
[root@hadoop01 redis-6.0.5]# scl enable devtoolset-9 bash
以上为临时启用,如果要长期使用gcc 9.1的话:
[root@hadoop01 redis-6.0.5]# echo "source /opt/rh/devtoolset-9/enable"
查看升级后gcc版本
[root@hadoop01 redis-6.0.5]# 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)
再使用
make distclean
清空上次编译失败残留文件
make && make install
执行编译及安装
(make install PREFIX=/usr/local/redis
:安装到指定目录)
xshell连接过程
- 连接redis:redis-cli -p 6380 -a 密码
- redis的位置:/usr/local/redis/etc/redis.conf
- 启动位置:/usr/local/redis/bin
- 启动命令:redis-server /usr/local/redis/etc/redis-6379.conf
然后是修改配置:
启动
首先要修改redis.conf:
注意这几个:
# bind 127.0.0.1 注释掉否则无法访问
protected-mode yes
daemonize yes
requirepass 自己的密码
启动命令:redis-server /usr/local/redis/etc/redis.conf
然后用ps -ef | grep redis
查看,连接是6379
停止命令:直接ps -ef|grep redis ,然后kill -9 掉即可。
参考链接:https://www.cnblogs.com/heqiuyong/p/10463334.html