Redis安装与部署(CentOS7环境,Redis6.0.9)

目录

 

一、Redis官网

二、安装Redis

1、解压

2、编译源码

3、安装

三、部署Redis

1、创建bin和etc文件夹

2、移动文件

四、启动Redis


一、Redis官网

https://redis.io/download

本文使用的是当下最新的稳定版本V6.0.9

二、安装Redis

1、解压

tar -zxf redis-6.0.9.tar.gz

2、编译源码

make

注:make过程可能会报错,错误信息如下

In file included from server.c:30:0:
server.h:1072:5: error: expected specifier-qualifier-list before ‘_Atomic’
     _Atomic unsigned int lruclock; /* Clock for LRU eviction */
     ^
server.c: In function ‘serverLogRaw’:
server.c:1031:31: error: ‘struct redisServer’ has no member named ‘logfile’
     int log_to_stdout = server.logfile[0] == '\0';
                               ^
server.c:1034:23: error: ‘struct redisServer’ has no member named ‘verbosity’
     if (level < server.verbosity) return;
                       ^
server.c:1036:47: error: ‘struct redisServer’ has no member named ‘logfile’
     fp = log_to_stdout ? stdout : fopen(server.logfile,"a");
                                               ^
server.c:1049:47: error: ‘struct redisServer’ has no member named ‘timezone’
         nolocks_localtime(&tm,tv.tv_sec,server.timezone,server.daylight_active);
                                               ^
........

错误原因:GCC版本低了,新版的Redis用到了c11,系统默认自带版本是4.8.5

[root@10 redis-6.0.9]# gcc --version
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39)
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

解决方法:需要更新gcc到5.4版本以上,安装命令如下

yum groupinstall "Development Tools"

strings /usr/lib64/libstdc++.so.6 | grep GLIBC

cd /usr/local/src/

wget http://ftp.gnu.org/gnu/gcc/gcc-10.2.0/gcc-10.2.0.tar.gz   //速度较慢,使用镜像站:wget http://mirror.hust.edu.cn/gnu/gcc/gcc-10.2.0/gcc-10.2.0.tar.gz

tar -zxf gcc-10.2.0.tar.gz

cd gcc-10.2.0

./contrib/download_prerequisites

./configure -enable-checking=release -enable-languages=c,c++ -disable-multilib

make -j4

ls /usr/local/bin | grep gcc

make install

由于安装过程很慢,另一种升级方式:

yum -y install centos-release-scl
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

3、安装

make install

[root@10 redis-6.0.9]# cd src/
[root@10 src]# make install

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install

三、部署Redis

1、创建bin和etc文件夹

[root@10 redis-6.0.9]# mkdir etc
[root@10 redis-6.0.9]# mkdir bin


2、移动文件

[root@10 src]# mv mkreleasehdr.sh redis-benchmark redis-check-aof redis-check-rdb redis-cli redis-server ../bin/
[root@10 src]# cd ../bin/
[root@10 bin]# ls
mkreleasehdr.sh  redis-check-aof  redis-cli
redis-benchmark  redis-check-rdb  redis-server
[root@10 bin]# cd ..
[root@10 redis-6.0.9]# mv redis.conf etc/
[root@10 redis-6.0.9]# cd etc
[root@10 etc]# ls
redis.conf

四、启动Redis

[root@10 bin]# ./redis-server
13660:C 05 Dec 2020 11:57:20.929 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
13660:C 05 Dec 2020 11:57:20.929 # Redis version=6.0.9, bits=64, commit=00000000                                                      , modified=0, pid=13660, just started
13660:C 05 Dec 2020 11:57:20.929 # Warning: no config file specified, using the                                                       default config. In order to specify a config file use ./redis-server /path/to/re                                                      dis.conf
13660:M 05 Dec 2020 11:57:20.931 * Increased maximum number of open files to 100                                                      32 (it was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 6.0.9 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 13660
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

13660:M 05 Dec 2020 11:57:20.934 # WARNING: The TCP backlog setting of 511 canno                                                      t be enforced because /proc/sys/net/core/somaxconn is set to the lower value of                                                       128.
13660:M 05 Dec 2020 11:57:20.934 # Server initialized
13660:M 05 Dec 2020 11:57:20.936 # WARNING overcommit_memory is set to 0! Backgr                                                      ound save may fail under low memory condition. To fix this issue add 'vm.overcom                                                      mit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl v                                                      m.overcommit_memory=1' for this to take effect.
13660:M 05 Dec 2020 11:57:20.937 # WARNING you have Transparent Huge Pages (THP)                                                       support enabled in your kernel. This will create latency and memory usage issue                                                      s with Redis. To fix this issue run the command 'echo madvise > /sys/kernel/mm/t                                                      ransparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order                                                       to retain the setting after a reboot. Redis must be restarted after THP is disab                                                      led (set to 'madvise' or 'never').
13660:M 05 Dec 2020 11:57:20.937 * Ready to accept connections

猜你喜欢

转载自blog.csdn.net/xlyrh/article/details/110729261