首页 » Redis » Redis学习01之安装Redis6 on Linux 7

Redis学习01之安装Redis6 on Linux 7

Redis是一个速度非常快的非关系型内存数据库,最初由Salvatore Sanfilippo创建,可以存储Key与5种不同类型的Value之间映射,允许将内存键值持久化到硬盘,也可以使用复制特性扩展读性能,算是一个远程内存库,有强劲的性能,致力于帮助用户解决问题,并且开源,通过复制、持久化、分片特性可以扩展成一个包含数百GB数据,每秒处理上百万次请求的系统,所以在目前的高并发应用中普遍采用。

支持的5种结构有string字符串,list列表,set集合,hash散列,zset有序信合。

下面记录Redis的安装与字符串类型的操作(python)

下载网站

$ wget http://download.redis.io/releases/redis-6.0.5.tar.gz
$ tar xzf redis-6.0.5.tar.gz
$ cd redis-6.0.5
$ make

在CENTOS/OEL 7上安装会可能遇到下面的错误

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

The reason
From redis 6.0.0, building redis from source code needs C11 support.

The version of gcc in Centos7 is 4.8.5, but C11 was introduced in 4.9.

[root@MiWiFi-R2100-srv redis-6.0.5]# rpm -qa|grep gcc
libgcc-4.8.5-4.el7.x86_64
gcc-gfortran-4.8.5-4.el7.x86_64
gcc-c++-4.8.5-4.el7.x86_64
gcc-4.8.5-4.el7.x86_64

Solvution
Install Developer Toolset 7 to compile with gcc7.

# yum install centos-release-scl
# yum install devtoolset-7

This won’t update gcc 4.8.5 to 7 directly, it provides a virtual environment for gcc toolchain.

Use the following command enter the environment.

[root@MiWiFi-R2100-srv redis-6.0.5]# scl enable devtoolset-7 bash
[root@MiWiFi-R2100-srv redis-6.0.5]#  echo "source /opt/rh/devtoolset-7/enable" >>/etc/profile
[root@MiWiFi-R2100-srv redis-6.0.5]# make
$ mkdir -p /usr/soft/redis
$ make PREFIX=/usr/soft/redis install

[root@MiWiFi-R2100-srv bin]# pwd
/usr/soft/redis/bin
[root@MiWiFi-R2100-srv bin]# ll
total 35632
-rwxr-xr-x 1 root root 4717032 Jun 22 10:36 redis-benchmark   # 性能检测
-rwxr-xr-x 1 root root 8932872 Jun 22 10:36 redis-check-aof   # 检查aof日志
-rwxr-xr-x 1 root root 8932872 Jun 22 10:36 redis-check-rdb   # 检查rdb日志
-rwxr-xr-x 1 root root 4966208 Jun 22 10:36 redis-cli         # 客户端
lrwxrwxrwx 1 root root      12 Jun 22 10:36 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 8932872 Jun 22 10:36 redis-server      # 服务端

# vi ~/.bash_profile

export REDIS_HOME=/usr/soft/redis
export PATH=$PATH:$REDIS_HOME/bin
# source ~/.bash_profile

[root@MiWiFi-R2100-srv redis]# redis-server
8133:C 22 Jun 2020 10:54:31.795 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
8133:C 22 Jun 2020 10:54:31.795 # Redis version=6.0.5, bits=64, commit=00000000, modified=0, pid=8133, just started
8133:C 22 Jun 2020 10:54:31.795 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
8133:M 22 Jun 2020 10:54:31.796 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 6.0.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 8133
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'


-- 放到后台进程
[root@MiWiFi-R2100-srv redis]# pwd
/usr/soft/redis
[root@MiWiFi-R2100-srv redis]# vi redis.conf
[root@MiWiFi-R2100-srv redis]# cat redis.conf
daemonize yes

[root@MiWiFi-R2100-srv redis]# redis-server /usr/soft/redis/redis.conf
8177:C 22 Jun 2020 10:59:58.664 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
8177:C 22 Jun 2020 10:59:58.664 # Redis version=6.0.5, bits=64, commit=00000000, modified=0, pid=8177, just started
8177:C 22 Jun 2020 10:59:58.664 # Configuration loaded

[root@MiWiFi-R2100-srv bin]# ps -ef|grep redis|grep -v grep
root 8178 1 0 10:59 ? 00:00:01 redis-server *:6379
[root@MiWiFi-R2100-srv redis]# redis-
redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli        redis-sentinel   redis-server
[root@MiWiFi-R2100-srv redis]# redis-cli
127.0.0.1:6379> set key1 "hello world"
OK
127.0.0.1:6379> get key1
"hello world"
127.0.0.1:6379>
 

打赏

对不起,这篇文章暂时关闭评论。