编译安装redis
下载redis
在官网访问redis官网,下载你需要的版本 redis下载
这里我使用6.2.1版本
下载
wget https://download.redis.io/releases/redis-6.2.1.tar.gz
解压
tar xzf redis-6.2.1.tar.gz
进入目录
cd redis-6.2.1
编译
make
make可能遇到的错误,是因为gcc 版本低于 5.3 ,需要升级
查看当前gcc版本
[root@izuf6c1rysne6s9az redis-6.0.9]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../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
Thread model: posix
gcc version 4.8.5 20150623 (Red Hat 4.8.5-44) (GCC)
升级gcc到9+
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
// 临时有效,退出 shell 或重启会恢复原 gcc 版本
scl enable devtoolset-9 bash
// 长期有效
echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
查看gcc版本
[root@izuf6c1rcb6s9az redis-6.0.9]# 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)
编译redis
编译
make
编译测试
make test
安装
make install
安装redis
redis 编译之后,文件存放在redis家目录的src文件夹中
创建目录
mkdir -p /opt/redis/{bin,conf,logs,data}
将src目录下的执行文件拷入bin目录中
cd src/
cp redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-sentinel redis-server /opt/redis/bin/
将redis配置文件拷入conf文件夹
cp redis.conf /opt/redis/conf/
设置开机启动
创建启动脚本
编辑redis启动文件
vim redis-start.sh
#!/bin/bash
/opt/module/redis-7000/src/redis-server /opt/module/redis-7000/redis.conf
赋予可执行权限
chmod +x redis-start.sh
创建关闭脚本
创建关闭脚本
vim redis-stop.sh
ps -aux|grep redis|awk '{print $2}'|xargs kill -15
赋予可执行权限
chmod +x redis-cluster-stop.sh
vim /usr/lib/systemd/system/redis-cluster.service
[Unit]
Description=Redis 6.0.9 Cluster Service
After=network.target
[Service]
Type=forking
ExecStart=/opt/redis/bin/redis-start.sh
ExecStop=/opt/redis/bin/redis-stop.sh
PrivateTmp=true
[Install]
WantedBy=default.target