Linux 上安装 redis
redis 下载
1下载链接 http://download.redis.io/releases/ 2 3 4Redis中国用户组 http://www.redis.cn/ 5 6 7Redis中国用户组(China Redis User Group),简称CRUG,成立于2016年5月20日,是中国地区最大的Redis技术交流社区,CRUG在成立时就得到了Redis官方的认可,并且凝聚了包括新浪微博、唯品会、去哪儿、小米、饿了么、搜狐、百度、陌陌、滴滴、阿里云、360、腾讯、美团、京东、今日头条、优酷土豆等公司众多的一线工程师和技术专家,累计覆盖Redis用户数万人。CRUG旨在汇聚国内Redis爱好者,共同探讨和交流Redis的使用经验和成长心得,共享Redis成果。
redis 版本
1Redis 使用标准版本标记进行版本控制:major.minor.patchlevel。偶数的版本号表示稳定的版本。 2目前企业中生产环境的主流版本是 3.2
redis 安装步骤
下载、解压、编译Redis
wget tar
1# 下载、解压、编译 Redis 。需要先安装 gcc 编译工具 2$ wget http://download.redis.io/releases/redis-5.0.4.tar.gz 3$ tar xzf redis-5.0.4.tar.gz 4$ cd redis-5.0.4 5$ make # 编译 6$ make PREFIX=/usr/local/redis/redis-3.2.8 install # 在指定位置生成 bin 目录,便于执行指令。 7 8# 进入到解压后的 src 目录,通过如下命令启动Redis 9$ src/redis-server 10 11# 您可以使用内置的客户端与Redis进行交互 12$ src/redis-cli 13redis> set foo bar 14OK 15redis> get foo 16"bar"
redis 安装实战
1# 解压后,make 之前。 2[root@localhost redis-3.2.8]# pwd 3/usr/local/redis/redis-3.2.8 4[root@localhost redis-3.2.8]# ll 5total 196 6-rw-rw-r--. 1 root root 85775 Feb 12 2017 00-RELEASENOTES 7-rw-rw-r--. 1 root root 53 Feb 12 2017 BUGS 8-rw-rw-r--. 1 root root 1805 Feb 12 2017 CONTRIBUTING 9-rw-rw-r--. 1 root root 1487 Feb 12 2017 COPYING 10drwxrwxr-x. 7 root root 143 Feb 12 2017 deps 11-rw-rw-r--. 1 root root 11 Feb 12 2017 INSTALL 12-rw-rw-r--. 1 root root 151 Feb 12 2017 Makefile 13-rw-rw-r--. 1 root root 4223 Feb 12 2017 MANIFESTO 14-rw-rw-r--. 1 root root 6834 Feb 12 2017 README.md 15-rw-rw-r--. 1 root root 46695 Feb 12 2017 redis.conf 16-rwxrwxr-x. 1 root root 271 Feb 12 2017 runtest 17-rwxrwxr-x. 1 root root 280 Feb 12 2017 runtest-cluster 18-rwxrwxr-x. 1 root root 281 Feb 12 2017 runtest-sentinel 19-rw-rw-r--. 1 root root 7606 Feb 12 2017 sentinel.conf 20drwxrwxr-x. 2 root root 4096 Feb 12 2017 src 21drwxrwxr-x. 10 root root 167 Feb 12 2017 tests 22drwxrwxr-x. 7 root root 4096 Feb 12 2017 utils
编译
1# CentOS7 最小版 自带 make 。但是没有 gcc 工具。 2[root@localhost ~]# make 3make: *** No targets specified and no makefile found. Stop. 4 5 6# 使用 make 编译失败,因为没有安装 gcc。 gcc: Command not found cc: command not found 7[root@localhost redis-3.2.8]# make 8... 9cd hiredis && make static 10make[3]: Entering directory `/usr/local/redis/redis-3.2.8/deps/hiredis' 11gcc -std=c99 -pedantic -c -O3 -fPIC -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb net.c 12make[3]: gcc: Command not found 13make[3]: *** [net.o] Error 127 14make[3]: Leaving directory `/usr/local/redis/redis-3.2.8/deps/hiredis' 15make[2]: *** [hiredis] Error 2 16make[2]: Leaving directory `/usr/local/redis/redis-3.2.8/deps' 17make[1]: [persist-settings] Error 2 (ignored) 18 CC adlist.o 19/bin/sh: cc: command not found 20make[1]: *** [adlist.o] Error 127 21make[1]: Leaving directory `/usr/local/redis/redis-3.2.8/src' 22make: *** [all] Error 2 23 24 25# 已经安装 gcc ,但是还是报错。考虑到上次执行 make 失败可能有影响。删除后重新解压缩,编译成功。 26[root@localhost redis-3.2.8]# make 27cd src && make all 28make[1]: Entering directory `/usr/local/redis/redis-3.2.8/src' 29 CC adlist.o 30In file included from adlist.c:34:0: 31zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory 32 #include <jemalloc/jemalloc.h> 33 ^ 34compilation terminated. 35make[1]: *** [adlist.o] Error 1 36make[1]: Leaving directory `/usr/local/redis/redis-3.2.8/src' 37make: *** [all] Error 2 38# 方案:考虑到上次执行 make 失败可能有影响。删除这个 redis ,重新解压缩,编译成功。 39 40 41# make 成功 42[root@localhost redis-3.2.8]# make 43total 204 44-rw-rw-r--. 1 root root 85775 Feb 12 2017 00-RELEASENOTES 45-rw-rw-r--. 1 root root 53 Feb 12 2017 BUGS 46-rw-rw-r--. 1 root root 1805 Feb 12 2017 CONTRIBUTING 47-rw-rw-r--. 1 root root 1487 Feb 12 2017 COPYING 48drwxrwxr-x. 7 root root 211 Jul 20 22:21 deps 49-rw-rw-r--. 1 root root 11 Feb 12 2017 INSTALL 50-rw-rw-r--. 1 root root 151 Feb 12 2017 Makefile 51-rw-rw-r--. 1 root root 4223 Feb 12 2017 MANIFESTO 52-rw-rw-r--. 1 root root 6834 Feb 12 2017 README.md 53-rw-rw-r--. 1 root root 46695 Feb 12 2017 redis.conf 54-rwxrwxr-x. 1 root root 271 Feb 12 2017 runtest 55-rwxrwxr-x. 1 root root 280 Feb 12 2017 runtest-cluster 56-rwxrwxr-x. 1 root root 281 Feb 12 2017 runtest-sentinel 57-rw-rw-r--. 1 root root 7606 Feb 12 2017 sentinel.conf 58drwxrwxr-x. 2 root root 8192 Jul 20 22:22 src 59drwxrwxr-x. 10 root root 167 Feb 12 2017 tests 60drwxrwxr-x. 7 root root 4096 Feb 12 2017 utils 61 62# 启动 redis 服务端 63[root@localhost redis-3.2.8]# src/redis-server 644754:C 20 Jul 22:26:56.606 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf 65 66# 启动 redis 客户端 67[root@localhost redis-3.2.8]# src/redis-cli 68127.0.0.1:6379> keys * 69(empty list or set) 70127.0.0.1:6379> set foo 'chang' 71OK 72127.0.0.1:6379> get foo 73"chang" 74127.0.0.1:6379> set foo '长河' 75OK 76127.0.0.1:6379> get foo 77"\xe9\x95\xbf\xe6\xb2\xb3"
安装
1# make install 安装将产生一个 bin 文件夹。便于操作 redis 。 2[root@localhost redis-3.2.8]# make PREFIX=/usr/local/redis/redis-3.2.8 install 3cd src && make install 4make[1]: Entering directory `/usr/local/redis/redis-3.2.8/src' 5 6Hint: It's a good idea to run 'make test' ;) 7 8 INSTALL install 9 INSTALL install 10 INSTALL install 11 INSTALL install 12 INSTALL install 13make[1]: Leaving directory `/usr/local/redis/redis-3.2.8/src' 14[root@localhost redis-3.2.8]# ll 15total 204 16-rw-rw-r--. 1 root root 85775 Feb 12 2017 00-RELEASENOTES 17drwxr-xr-x. 2 root root 134 Jul 20 23:12 bin 18-rw-rw-r--. 1 root root 53 Feb 12 2017 BUGS 19-rw-rw-r--. 1 root root 1805 Feb 12 2017 CONTRIBUTING 20-rw-rw-r--. 1 root root 1487 Feb 12 2017 COPYING 21drwxrwxr-x. 7 root root 211 Jul 20 22:21 deps 22-rw-rw-r--. 1 root root 11 Feb 12 2017 INSTALL 23-rw-rw-r--. 1 root root 151 Feb 12 2017 Makefile 24-rw-rw-r--. 1 root root 4223 Feb 12 2017 MANIFESTO 25-rw-rw-r--. 1 root root 6834 Feb 12 2017 README.md 26-rw-rw-r--. 1 root root 46695 Feb 12 2017 redis.conf 27-rwxrwxr-x. 1 root root 271 Feb 12 2017 runtest 28-rwxrwxr-x. 1 root root 280 Feb 12 2017 runtest-cluster 29-rwxrwxr-x. 1 root root 281 Feb 12 2017 runtest-sentinel 30-rw-rw-r--. 1 root root 7606 Feb 12 2017 sentinel.conf 31drwxrwxr-x. 2 root root 8192 Jul 20 22:22 src 32drwxrwxr-x. 10 root root 167 Feb 12 2017 tests 33drwxrwxr-x. 7 root root 4096 Feb 12 2017 utils 34 35# make install 在指定位置生成了 bin 目录,其中存放了操作 redis 的指令。 36[root@localhost redis-3.2.8]# ll bin 37total 15060 38-rwxr-xr-x. 1 root root 2433000 Jul 20 23:12 redis-benchmark 39-rwxr-xr-x. 1 root root 25088 Jul 20 23:12 redis-check-aof 40-rwxr-xr-x. 1 root root 5181784 Jul 20 23:12 redis-check-rdb 41-rwxr-xr-x. 1 root root 2585792 Jul 20 23:12 redis-cli 42lrwxrwxrwx. 1 root root 12 Jul 20 23:12 redis-sentinel -> redis-server 43-rwxr-xr-x. 1 root root 5181784 Jul 20 23:12 redis-server
联网安装 gcc
1# yum 搜索 gcc-c++ 安装包 2[root@localhost ~]# yum search gcc 3Loaded plugins: fastestmirror 4Loading mirror speeds from cached hostfile 5 * base: mirrors.neusoft.edu.cn 6 * extras: mirror.bit.edu.cn 7 * updates: mirrors.neusoft.edu.cn 8====================================================== N/S matched: gcc ======================================================= 9gcc-c++.x86_64 : C++ support for GCC 10 11# yum 安装 gcc-c++ 12[root@localhost develop]# yum install gcc-c++ 13Loaded plugins: fastestmirror 14Loading mirror speeds from cached hostfile 15 * base: mirror.lzu.edu.cn 16 * extras: mirror.bit.edu.cn 17 * updates: mirror.lzu.edu.cn 18Package gcc-c++-4.8.5-36.el7_6.2.x86_64 already installed and latest version 19Nothing to do 20 21 22# 使用 gcc/g++/c++ -v 查看 gcc 是否安装。 23[root@localhost develop]# gcc -v 24Using built-in specs. 25COLLECT_GCC=gcc 26COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper 27gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC) 28 29[root@localhost develop]# g++ -v 30Using built-in specs. 31COLLECT_GCC=g++ 32COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper 33gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
无网络情况下 如何安装GCC
无网络情况下 如何安装GCC https://www.linuxidc.com/Linux/2014-09/107134.htm
思路 配置本地 yum 源。createrepo mount 挂载镜像