Linux 上安装 Redis

Linux 上安装 redis

redis 下载

下载链接 http://download.redis.io/releases/
Redis中国用户组 http://www.redis.cn/
Redis中国用户组(China Redis User Group),简称CRUG,成立于2016年5月20日,是中国地区最大的Redis技术交流社区,CRUG在成立时就得到了Redis官方的认可,并且凝聚了包括新浪微博、唯品会、去哪儿、小米、饿了么、搜狐、百度、陌陌、滴滴、阿里云、360、腾讯、美团、京东、今日头条、优酷土豆等公司众多的一线工程师和技术专家,累计覆盖Redis用户数万人。CRUG旨在汇聚国内Redis爱好者,共同探讨和交流Redis的使用经验和成长心得,共享Redis成果。

redis 版本

Redis 使用标准版本标记进行版本控制:major.minor.patchlevel。偶数的版本号表示稳定的版本。
目前企业中生产环境的主流版本是 3.2

redis 安装步骤

下载、解压、编译Redis

wget tar

# 下载、解压、编译 Redis 。需要先安装 gcc 编译工具
$ wget http://download.redis.io/releases/redis-5.0.4.tar.gz
$ tar xzf redis-5.0.4.tar.gz
$ cd redis-5.0.4
$ make # 编译
$ make PREFIX=/usr/local/redis/redis-3.2.8 install # 在指定位置生成 bin 目录,便于执行指令。

# 进入到解压后的 src 目录,通过如下命令启动Redis
$ src/redis-server

# 您可以使用内置的客户端与Redis进行交互
$ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"

redis 安装实战

# 解压后,make 之前。
[root@localhost redis-3.2.8]# pwd
/usr/local/redis/redis-3.2.8
[root@localhost redis-3.2.8]# ll
total 196
-rw-rw-r--.  1 root root 85775 Feb 12  2017 00-RELEASENOTES
-rw-rw-r--.  1 root root    53 Feb 12  2017 BUGS
-rw-rw-r--.  1 root root  1805 Feb 12  2017 CONTRIBUTING
-rw-rw-r--.  1 root root  1487 Feb 12  2017 COPYING
drwxrwxr-x.  7 root root   143 Feb 12  2017 deps
-rw-rw-r--.  1 root root    11 Feb 12  2017 INSTALL
-rw-rw-r--.  1 root root   151 Feb 12  2017 Makefile
-rw-rw-r--.  1 root root  4223 Feb 12  2017 MANIFESTO
-rw-rw-r--.  1 root root  6834 Feb 12  2017 README.md
-rw-rw-r--.  1 root root 46695 Feb 12  2017 redis.conf
-rwxrwxr-x.  1 root root   271 Feb 12  2017 runtest
-rwxrwxr-x.  1 root root   280 Feb 12  2017 runtest-cluster
-rwxrwxr-x.  1 root root   281 Feb 12  2017 runtest-sentinel
-rw-rw-r--.  1 root root  7606 Feb 12  2017 sentinel.conf
drwxrwxr-x.  2 root root  4096 Feb 12  2017 src
drwxrwxr-x. 10 root root   167 Feb 12  2017 tests
drwxrwxr-x.  7 root root  4096 Feb 12  2017 utils

编译

# CentOS7 最小版 自带 make 。但是没有 gcc 工具。
[root@localhost ~]# make
make: *** No targets specified and no makefile found.  Stop.
# 使用 make 编译失败,因为没有安装 gcc。 gcc: Command not found cc: command not found
[root@localhost redis-3.2.8]# make
...
cd hiredis && make static
make[3]: Entering directory `/usr/local/redis/redis-3.2.8/deps/hiredis'
gcc -std=c99 -pedantic -c -O3 -fPIC  -Wall -W -Wstrict-prototypes -Wwrite-strings -g -ggdb  net.c
make[3]: gcc: Command not found
make[3]: *** [net.o] Error 127
make[3]: Leaving directory `/usr/local/redis/redis-3.2.8/deps/hiredis'
make[2]: *** [hiredis] Error 2
make[2]: Leaving directory `/usr/local/redis/redis-3.2.8/deps'
make[1]: [persist-settings] Error 2 (ignored)
    CC adlist.o
/bin/sh: cc: command not found
make[1]: *** [adlist.o] Error 127
make[1]: Leaving directory `/usr/local/redis/redis-3.2.8/src'
make: *** [all] Error 2
# 已经安装 gcc ,但是还是报错。考虑到上次执行 make 失败可能有影响。删除后重新解压缩,编译成功。
[root@localhost redis-3.2.8]# make 
cd src && make all
make[1]: Entering directory `/usr/local/redis/redis-3.2.8/src'
    CC adlist.o
In file included from adlist.c:34:0:
zmalloc.h:50:31: fatal error: jemalloc/jemalloc.h: No such file or directory
 #include <jemalloc/jemalloc.h>
                               ^
compilation terminated.
make[1]: *** [adlist.o] Error 1
make[1]: Leaving directory `/usr/local/redis/redis-3.2.8/src'
make: *** [all] Error 2
# 方案:考虑到上次执行 make 失败可能有影响。删除这个 redis ,重新解压缩,编译成功。
# make 成功
[root@localhost redis-3.2.8]# make
total 204
-rw-rw-r--.  1 root root 85775 Feb 12  2017 00-RELEASENOTES
-rw-rw-r--.  1 root root    53 Feb 12  2017 BUGS
-rw-rw-r--.  1 root root  1805 Feb 12  2017 CONTRIBUTING
-rw-rw-r--.  1 root root  1487 Feb 12  2017 COPYING
drwxrwxr-x.  7 root root   211 Jul 20 22:21 deps
-rw-rw-r--.  1 root root    11 Feb 12  2017 INSTALL
-rw-rw-r--.  1 root root   151 Feb 12  2017 Makefile
-rw-rw-r--.  1 root root  4223 Feb 12  2017 MANIFESTO
-rw-rw-r--.  1 root root  6834 Feb 12  2017 README.md
-rw-rw-r--.  1 root root 46695 Feb 12  2017 redis.conf
-rwxrwxr-x.  1 root root   271 Feb 12  2017 runtest
-rwxrwxr-x.  1 root root   280 Feb 12  2017 runtest-cluster
-rwxrwxr-x.  1 root root   281 Feb 12  2017 runtest-sentinel
-rw-rw-r--.  1 root root  7606 Feb 12  2017 sentinel.conf
drwxrwxr-x.  2 root root  8192 Jul 20 22:22 src
drwxrwxr-x. 10 root root   167 Feb 12  2017 tests
drwxrwxr-x.  7 root root  4096 Feb 12  2017 utils

# 启动 redis 服务端
[root@localhost redis-3.2.8]# src/redis-server 
4754: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

# 启动 redis 客户端
[root@localhost redis-3.2.8]# src/redis-cli
127.0.0.1:6379> keys * 
(empty list or set)
127.0.0.1:6379> set foo 'chang'
OK
127.0.0.1:6379> get foo
"chang"
127.0.0.1:6379> set foo '长河'
OK
127.0.0.1:6379> get foo
"\xe9\x95\xbf\xe6\xb2\xb3"

安装

# make install 安装将产生一个 bin 文件夹。便于操作 redis 。
[root@localhost redis-3.2.8]# make PREFIX=/usr/local/redis/redis-3.2.8 install
cd src && make install
make[1]: Entering directory `/usr/local/redis/redis-3.2.8/src'

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

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: Leaving directory `/usr/local/redis/redis-3.2.8/src'
[root@localhost redis-3.2.8]# ll
total 204
-rw-rw-r--.  1 root root 85775 Feb 12  2017 00-RELEASENOTES
drwxr-xr-x.  2 root root   134 Jul 20 23:12 bin
-rw-rw-r--.  1 root root    53 Feb 12  2017 BUGS
-rw-rw-r--.  1 root root  1805 Feb 12  2017 CONTRIBUTING
-rw-rw-r--.  1 root root  1487 Feb 12  2017 COPYING
drwxrwxr-x.  7 root root   211 Jul 20 22:21 deps
-rw-rw-r--.  1 root root    11 Feb 12  2017 INSTALL
-rw-rw-r--.  1 root root   151 Feb 12  2017 Makefile
-rw-rw-r--.  1 root root  4223 Feb 12  2017 MANIFESTO
-rw-rw-r--.  1 root root  6834 Feb 12  2017 README.md
-rw-rw-r--.  1 root root 46695 Feb 12  2017 redis.conf
-rwxrwxr-x.  1 root root   271 Feb 12  2017 runtest
-rwxrwxr-x.  1 root root   280 Feb 12  2017 runtest-cluster
-rwxrwxr-x.  1 root root   281 Feb 12  2017 runtest-sentinel
-rw-rw-r--.  1 root root  7606 Feb 12  2017 sentinel.conf
drwxrwxr-x.  2 root root  8192 Jul 20 22:22 src
drwxrwxr-x. 10 root root   167 Feb 12  2017 tests
drwxrwxr-x.  7 root root  4096 Feb 12  2017 utils

# make install 在指定位置生成了 bin 目录,其中存放了操作 redis 的指令。
[root@localhost redis-3.2.8]# ll bin
total 15060
-rwxr-xr-x. 1 root root 2433000 Jul 20 23:12 redis-benchmark
-rwxr-xr-x. 1 root root   25088 Jul 20 23:12 redis-check-aof
-rwxr-xr-x. 1 root root 5181784 Jul 20 23:12 redis-check-rdb
-rwxr-xr-x. 1 root root 2585792 Jul 20 23:12 redis-cli
lrwxrwxrwx. 1 root root      12 Jul 20 23:12 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 5181784 Jul 20 23:12 redis-server

联网安装 gcc

# yum 搜索 gcc-c++ 安装包
[root@localhost ~]# yum search gcc
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.neusoft.edu.cn
 * extras: mirror.bit.edu.cn
 * updates: mirrors.neusoft.edu.cn
====================================================== N/S matched: gcc =======================================================
gcc-c++.x86_64 : C++ support for GCC

# yum 安装 gcc-c++
[root@localhost develop]# yum install gcc-c++
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.lzu.edu.cn
 * extras: mirror.bit.edu.cn
 * updates: mirror.lzu.edu.cn
Package gcc-c++-4.8.5-36.el7_6.2.x86_64 already installed and latest version
Nothing to do
# 使用 gcc/g++/c++ -v 查看 gcc 是否安装。
[root@localhost develop]# gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
gcc version 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)

[root@localhost develop]# g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.5/lto-wrapper
gcc 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 挂载镜像

posted @ 2019-08-02 13:55  没有理由不会呀  阅读(379)  评论(0编辑  收藏  举报