Centos7源码安装Redis6.0.20

Administrator 24 2024-07-30

Centos7源码安装Redis6.0.20

1、下载Redis6.0.20软件包

cd /opt
wget http://download.redis.io/releases/redis-6.0.20.tar.gz

2、解压

tar xzf redis-6.0.20.tar.gz && cd redis-6.0.20

3、编译

make

4、【可能出现】make编译报错

注释:原因是安装redis-6版本gcc版本需要大于5.3,centos7默认gcc版本为4.85所以无法make

执行make编译报错提示:
server.c:1050:47: error:‘struct redisServer’ has no member named ‘timezone’
         nolocks_localtime(&tm,tv.tv_sec,server.timezone,server.daylight_active);
                                               ^
server.c:1050:63: error:‘struct redisServer’ has no member named ‘daylight_active’
         nolocks_localtime(&tm,tv.tv_sec,server.timezone,server.daylight_active);
[root@server ~]# 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)

5、查找yum源支持的gcc版本

[root@server ~]# yum list dev\*gcc
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
devtoolset-8-gcc.x86_64                                                   8.3.1-3.1.el7                                                     @centos-sclo-rh
Available Packages
devtoolset-3-gcc.x86_64                                                   4.9.2-6.el7                                                       centos-sclo-rh 
devtoolset-4-gcc.x86_64                                                   5.3.1-6.1.el7                                                     centos-sclo-rh 
devtoolset-6-gcc.x86_64                                                   6.3.1-3.1.el7                                                     centos-sclo-rh 
devtoolset-7-gcc.x86_64                                                   7.3.1-5.15.el7                                                    centos-sclo-rh 

6、升级gcc版本

yum -y install centos-release-scl
yum -y install devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-8-binutils

# 临时生效
scl enable devtoolset-8 bash
# 永久生效
echo "source /opt/rh/devtoolset-8/enable" >>/etc/profile

# 此时查看gcc -v 版本
gcc version 8.3.1 (GCC)

7、继续编译和安装

# 切到解压后的Redis目录
cd redis-6.0.20

# 编译
make

# 安装(指定安装路径)
make PREFIX=/usr/local/redis-6.0.20 install

8、将源码目录中的配置文件 redis.confsentinel.conf 拷贝到Redis安装目录

# 拷贝配置文件(目录与上文路径一致)
cp /opt/redis-6.0.20/*.conf /usr/local/redis-6.0.20/

9、安装目录下配置redis.conf

注释:需要创建/usr/local/redis/目录

activerehashing yes
aof-load-truncated yes
aof-rewrite-incremental-fsync yes
appendfilename "appendonly.aof"
appendfsync everysec
appendonly no
auto-aof-rewrite-min-size 64mb
auto-aof-rewrite-percentage 100
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit pubsub 32mb 8mb 60
client-output-buffer-limit slave 256mb 64mb 60
daemonize yes
databases 16
dbfilename dump.rdb
dir /usr/local/redis/
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
hll-sparse-max-bytes 3000
hz 10
latency-monitor-threshold 0
list-compress-depth 0
list-max-ziplist-size -2
logfile ""
loglevel notice
lua-time-limit 5000
no-appendfsync-on-rewrite no
notify-keyspace-events ""
pidfile /var/run/redis_6379.pid
port 6379
protected-mode no
rdbchecksum yes
rdbcompression yes
repl-disable-tcp-nodelay no
repl-diskless-sync-delay 5
repl-diskless-sync no
save 300 10
save 60 10000
save 900 1
set-max-intset-entries 512
slave-priority 100
slave-read-only yes
slave-serve-stale-data yes
slowlog-log-slower-than 10000
slowlog-max-len 128
stop-writes-on-bgsave-error yes
supervised no
tcp-backlog 511
tcp-keepalive 300
timeout 0
zset-max-ziplist-entries 128
zset-max-ziplist-value 64

10、将Redis添加为系统服务,并设置开机自启动

vi /usr/lib/systemd/system/redis.service

# 将以下内容复制粘贴到redis.service
[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis-6.0.20/bin/redis-server /usr/local/redis-6.0.20/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target

# 修改redis.service文件权限
chmod 755 /usr/lib/systemd/system/redis.service

# 设置开机自启动
systemctl enable redis

11、启动Redis

# 启动
systemctl start redis

# 查看运行状态
systemctl status redis