coderwang在Linux中的Redis安装与启动:)

7 篇文章 0 订阅
1 篇文章 0 订阅

注:所需镜像版本:CentOS-7-x86_64-DVD-1511
Redis版本为:redis-3.0.0
我是在hadoop用户下安装的,所以需要赋予root权限,如果在root用户下安装,直接输入命令即可
我的安装路径为:/home/hadoop/software/Redis

1 安装环境:
因为redis是用c语言开发的,安装redis需要先将官网下载的源码进行编译,编译依赖gcc环境。如果没有gcc环境,需要安装gcc:

sudo yum install gcc-c++

[hadoop@hadoop1 ~]$ sudo yum install gcc-c++
[sudo] password for hadoop: 
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.jdcloud.com
 * extras: mirror.jdcloud.com
 * updates: mirror.jdcloud.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 gcc-c++.x86_64.0.4.8.5-36.el7_6.1 将被 安装
--> 正在处理依赖关系 libstdc++-devel = 4.8.5-36.el7_6.1,它被软件包 gcc-c++-4.8.5-36.el7_6.1.x86_64 需要
--> 正在处理依赖关系 libstdc++ = 4.8.5-36.el7_6.1,它被软件包 gcc-c++-4.8.5-36.el7_6.1.x86_64 需要
--> 正在处理依赖关系 gcc = 4.8.5-36.el7_6.1,它被软件包 gcc-c++-4.8.5-36.el7_6.1.x86_64 需要
--> 正在处理依赖关系 libmpc.so.3()(64bit),它被软件包 gcc-c++-4.8.5-36.el7_6.1.x86_64 需要
--> 正在检查事务
---> 软件包 gcc.x86_64.0.4.8.5-36.el7_6.1 将被 安装
--> 正在处理依赖关系 libgomp = 4.8.5-36.el7_6.1,它被软件包 gcc-4.8.5-36.el7_6.1.x86_64 需要
--> 正在处理依赖关系 cpp = 4.8.5-36.el7_6.1,它被软件包 gcc-4.8.5-36.el7_6.1.x86_64 需要
--> 正在处理依赖关系 libgcc >= 4.8.5-36.el7_6.1,它被软件包 gcc-4.8.5-36.el7_6.1.x86_64 需要
--> 正在处理依赖关系 glibc-devel >= 2.2.90-12,它被软件包 gcc-4.8.5-36.el7_6.1.x86_64 需要
---> 软件包 libmpc.x86_64.0.1.0.1-3.el7 将被 安装
---> 软件包 libstdc++.x86_64.0.4.8.5-4.el7 将被 升级
---> 软件包 libstdc++.x86_64.0.4.8.5-36.el7_6.1 将被 更新
---> 软件包 libstdc++-devel.x86_64.0.4.8.5-36.el7_6.1 将被 安装
--> 正在检查事务
---> 软件包 cpp.x86_64.0.4.8.5-36.el7_6.1 将被 安装
---> 软件包 glibc-devel.x86_64.0.2.17-260.el7_6.4 将被 安装
--> 正在处理依赖关系 glibc-headers = 2.17-260.el7_6.4,它被软件包 glibc-devel-2.17-260.el7_6.4.x86_64 需要
--> 正在处理依赖关系 glibc = 2.17-260.el7_6.4,它被软件包 glibc-devel-2.17-260.el7_6.4.x86_64 需要
--> 正在处理依赖关系 glibc-headers,它被软件包 glibc-devel-2.17-260.el7_6.4.x86_64 需要
---> 软件包 libgcc.x86_64.0.4.8.5-4.el7 将被 升级
---> 软件包 libgcc.x86_64.0.4.8.5-36.el7_6.1 将被 更新
---> 软件包 libgomp.x86_64.0.4.8.5-4.el7 将被 升级
---> 软件包 libgomp.x86_64.0.4.8.5-36.el7_6.1 将被 更新
--> 正在检查事务
---> 软件包 glibc.x86_64.0.2.17-105.el7 将被 升级
--> 正在处理依赖关系 glibc = 2.17-105.el7,它被软件包 glibc-common-2.17-105.el7.x86_64 需要
---> 软件包 glibc.x86_64.0.2.17-260.el7_6.4 将被 更新
---> 软件包 glibc-headers.x86_64.0.2.17-260.el7_6.4 将被 安装
--> 正在处理依赖关系 kernel-headers >= 2.2.1,它被软件包 glibc-headers-2.17-260.el7_6.4.x86_64 需要
--> 正在处理依赖关系 kernel-headers,它被软件包 glibc-headers-2.17-260.el7_6.4.x86_64 需要
--> 正在检查事务
---> 软件包 glibc-common.x86_64.0.2.17-105.el7 将被 升级
---> 软件包 glibc-common.x86_64.0.2.17-260.el7_6.4 将被 更新
---> 软件包 kernel-headers.x86_64.0.3.10.0-957.10.1.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

================================================================================
 Package              架构        版本                       源            大小
================================================================================
正在安装:
 gcc-c++              x86_64      4.8.5-36.el7_6.1           updates      7.2 M
为依赖而安装:
 cpp                  x86_64      4.8.5-36.el7_6.1           updates      5.9 M
 gcc                  x86_64      4.8.5-36.el7_6.1           updates       16 M
 glibc-devel          x86_64      2.17-260.el7_6.4           updates      1.1 M
 glibc-headers        x86_64      2.17-260.el7_6.4           updates      683 k
 kernel-headers       x86_64      3.10.0-957.10.1.el7        updates      8.0 M
 libmpc               x86_64      1.0.1-3.el7                base          51 k
 libstdc++-devel      x86_64      4.8.5-36.el7_6.1           updates      1.5 M
为依赖而更新:
 glibc                x86_64      2.17-260.el7_6.4           updates      3.7 M
 glibc-common         x86_64      2.17-260.el7_6.4           updates       12 M
 libgcc               x86_64      4.8.5-36.el7_6.1           updates      102 k
 libgomp              x86_64      4.8.5-36.el7_6.1           updates      157 k
 libstdc++            x86_64      4.8.5-36.el7_6.1           updates      305 k

事务概要
================================================================================
安装  1 软件包 (+7 依赖软件包)
升级           ( 5 依赖软件包)

总计:56 M
总下载量:41 M
Is this ok [y/d/N]: yes
Is this ok [y/d/N]: Y
Downloading packages:
(1/7): cpp-4.8.5-36.el7_6.1.x86_64.rpm                     | 5.9 MB   00:01     
(2/7): glibc-devel-2.17-260.el7_6.4.x86_64.rpm             | 1.1 MB   00:03     
(3/7): kernel-headers-3.10.0-957.10.1.el7.x86_64.rpm       | 8.0 MB   00:01     
(4/7): glibc-headers-2.17-260.el7_6.4.x86_64.rpm           | 683 kB   00:03     
(5/7): libstdc++-devel-4.8.5-36.el7_6.1.x86_64.rpm         | 1.5 MB   00:00     
(6/7): gcc-4.8.5-36.el7_6.1.x86_64.rpm                     |  16 MB   00:06     
(7/7): gcc-c++-4.8.5-36.el7_6.1.x86_64.rpm                 | 7.2 MB   00:37     
--------------------------------------------------------------------------------
总计                                               1.1 MB/s |  41 MB  00:37     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在更新    : libgcc-4.8.5-36.el7_6.1.x86_64                             1/18 
  正在更新    : glibc-common-2.17-260.el7_6.4.x86_64                       2/18 
  正在更新    : glibc-2.17-260.el7_6.4.x86_64                              3/18 
warning: /etc/nsswitch.conf created as /etc/nsswitch.conf.rpmnew
  正在安装    : libmpc-1.0.1-3.el7.x86_64                                  4/18 
  正在更新    : libstdc++-4.8.5-36.el7_6.1.x86_64                          5/18 
  正在安装    : libstdc++-devel-4.8.5-36.el7_6.1.x86_64                    6/18 
  正在安装    : cpp-4.8.5-36.el7_6.1.x86_64                                7/18 
  正在更新    : libgomp-4.8.5-36.el7_6.1.x86_64                            8/18 
  正在安装    : kernel-headers-3.10.0-957.10.1.el7.x86_64                  9/18 
  正在安装    : glibc-headers-2.17-260.el7_6.4.x86_64                     10/18 
  正在安装    : glibc-devel-2.17-260.el7_6.4.x86_64                       11/18 
  正在安装    : gcc-4.8.5-36.el7_6.1.x86_64                               12/18 
  正在安装    : gcc-c++-4.8.5-36.el7_6.1.x86_64                           13/18 
  清理        : libstdc++-4.8.5-4.el7.x86_64                              14/18 
  清理        : libgomp-4.8.5-4.el7.x86_64                                15/18 
  清理        : glibc-common-2.17-105.el7.x86_64                          16/18 
  清理        : glibc-2.17-105.el7.x86_64                                 17/18 
  清理        : libgcc-4.8.5-4.el7.x86_64                                 18/18 
  验证中      : glibc-2.17-260.el7_6.4.x86_64                              1/18 
  验证中      : gcc-4.8.5-36.el7_6.1.x86_64                                2/18 
  验证中      : libstdc++-4.8.5-36.el7_6.1.x86_64                          3/18 
  验证中      : glibc-devel-2.17-260.el7_6.4.x86_64                        4/18 
  验证中      : glibc-headers-2.17-260.el7_6.4.x86_64                      5/18 
  验证中      : glibc-common-2.17-260.el7_6.4.x86_64                       6/18 
  验证中      : kernel-headers-3.10.0-957.10.1.el7.x86_64                  7/18 
  验证中      : libgomp-4.8.5-36.el7_6.1.x86_64                            8/18 
  验证中      : gcc-c++-4.8.5-36.el7_6.1.x86_64                            9/18 
  验证中      : libmpc-1.0.1-3.el7.x86_64                                 10/18 
  验证中      : libstdc++-devel-4.8.5-36.el7_6.1.x86_64                   11/18 
  验证中      : libgcc-4.8.5-36.el7_6.1.x86_64                            12/18 
  验证中      : cpp-4.8.5-36.el7_6.1.x86_64                               13/18 
  验证中      : libstdc++-4.8.5-4.el7.x86_64                              14/18 
  验证中      : libgomp-4.8.5-4.el7.x86_64                                15/18 
  验证中      : libgcc-4.8.5-4.el7.x86_64                                 16/18 
  验证中      : glibc-2.17-105.el7.x86_64                                 17/18 
  验证中      : glibc-common-2.17-105.el7.x86_64                          18/18 

已安装:
  gcc-c++.x86_64 0:4.8.5-36.el7_6.1                                             

作为依赖被安装:
  cpp.x86_64 0:4.8.5-36.el7_6.1                                                 
  gcc.x86_64 0:4.8.5-36.el7_6.1                                                 
  glibc-devel.x86_64 0:2.17-260.el7_6.4                                         
  glibc-headers.x86_64 0:2.17-260.el7_6.4                                       
  kernel-headers.x86_64 0:3.10.0-957.10.1.el7                                   
  libmpc.x86_64 0:1.0.1-3.el7                                                   
  libstdc++-devel.x86_64 0:4.8.5-36.el7_6.1                                     

作为依赖被升级:
  glibc.x86_64 0:2.17-260.el7_6.4       glibc-common.x86_64 0:2.17-260.el7_6.4  
  libgcc.x86_64 0:4.8.5-36.el7_6.1      libgomp.x86_64 0:4.8.5-36.el7_6.1       
  libstdc++.x86_64 0:4.8.5-36.el7_6.1  

完毕!

2 下载Redis

可以到redis的官网找到各个Redis版本的下载地址,
官网地址(Linux内打开):http://www.redis.io
在这里插入图片描述
用命令下载:

sudo wget http://download.redis.io/releases/redis-3.0.0.tar.gz

[hadoop@hadoop1 ~]$ sudo wget http://download.redis.io/releases/redis-3.0.0.tar.gz
[sudo] password for hadoop: 
--2019-04-12 15:22:26--  http://download.redis.io/releases/redis-3.0.0.tar.gz
正在解析主机 download.redis.io (download.redis.io)... 109.74.203.151
正在连接 download.redis.io (download.redis.io)|109.74.203.151|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1358081 (1.3M) [application/x-gzip]
正在保存至: “redis-3.0.0.tar.gz”

100%[======================================>] 1,358,081   37.2KB/s 用时 33s    

2019-04-12 15:23:01 (40.4 KB/s) - 已保存 “redis-3.0.0.tar.gz” [1358081/1358081])

3 解压:
进入安装目录后进行解压:

 tar -zxvf redis-3.0.0.tar.gz

4 编译并安装Redis

进入Redis安装目录后查看文件:

[hadoop@hadoop1 Redis ]$ cd redis-3.0.0/-----进入目录
[hadoop@hadoop1 redis-3.0.0]$ ll----查看文件
总用量 140
-rw-rw-r--.  1 hadoop hadoop 25890 4月   1 2015 00-RELEASENOTES
-rw-rw-r--.  1 hadoop hadoop    53 4月   1 2015 BUGS
-rw-rw-r--.  1 hadoop hadoop  1439 4月   1 2015 CONTRIBUTING
-rw-rw-r--.  1 hadoop hadoop  1487 4月   1 2015 COPYING
drwxrwxr-x.  6 hadoop hadoop   101 4月   1 2015 deps
-rw-rw-r--.  1 hadoop hadoop    11 4月   1 2015 INSTALL
-rw-rw-r--.  1 hadoop hadoop   151 4月   1 2015 Makefile
-rw-rw-r--.  1 hadoop hadoop  4223 4月   1 2015 MANIFESTO
-rw-rw-r--.  1 hadoop hadoop  5201 4月   1 2015 README
-rw-rw-r--.  1 hadoop hadoop 41403 4月   1 2015 redis.conf
-rwxrwxr-x.  1 hadoop hadoop   271 4月   1 2015 runtest
-rwxrwxr-x.  1 hadoop hadoop   280 4月   1 2015 runtest-cluster
-rwxrwxr-x.  1 hadoop hadoop   281 4月   1 2015 runtest-sentinel
-rw-rw-r--.  1 hadoop hadoop  7109 4月   1 2015 sentinel.conf
drwxrwxr-x.  2 hadoop hadoop  4096 4月   1 2015 src
drwxrwxr-x. 10 hadoop hadoop  4096 4月   1 2015 tests
drwxrwxr-x.  5 hadoop hadoop  4096 4月   1 2015 utils

编译源码:make

[hadoop@hadoop1 redis-3.0.0]$ make

安装Redis:make install PREFIX=/home/hadoop/software/Redis

[hadoop@hadoop1 redis-3.0.0]$ make install PREFIX=/home/hadoop/software/Redis

注:make install PREFIX=”是固定的,后面加上Redis的安装目录

查看是否安装成功:
进入Redis安装目录,如果有一个名为bin的文件夹,即安装成功

[hadoop@hadoop1 ~]$ cd software/
[hadoop@hadoop1 software]$ cd Redis\ /
[hadoop@hadoop1 Redis ]$ ll
总用量 8
drwxrwxr-x. 2 hadoop hadoop 4096 4月  12 16:09 bin
drwxrwxr-x. 6 hadoop hadoop 4096 4月   1 2015 redis-3.0.0

5 启动Redis

两种启动方式:前端启动
后端启动

首先了解Bin目录里面的客户端和服务端:

  [hadoop@hadoop1 bin]$ ll
    总用量 8500
    -rwxr-xr-x. 1 hadoop hadoop 2077013 4月  12 16:09 redis-benchmark
    -rwxr-xr-x. 1 hadoop hadoop   25189 4月  12 16:09 redis-check-aof
    -rwxr-xr-x. 1 hadoop hadoop   56028 4月  12 16:09 redis-check-dump
    -rwxr-xr-x. 1 hadoop hadoop 2201199 4月  12 16:09 redis-cli------------客户端
    lrwxrwxrwx. 1 hadoop hadoop      12 4月  12 16:09 redis-sentinel -> redis-server
    -rwxr-xr-x. 1 hadoop hadoop 4332892 4月  12 16:09 redis-serve----------服务端

前端启动:
进入bin目录:./redis-server
在这里插入图片描述
注:前端启动Redis后,终端将进入Redis控制台,不能输入其他的Linux命令,即这个终端窗口只能输入Redis自己的命令。

前端关闭:
1.强制关闭:Ctrl+C----在Redis控制台直接执行(redis可能会丢失部分数据)
2.另开一个终端窗口,输入./redis-cli shutdown(redis不会丢失数据)

在这里插入图片描述
在终端二输入前端关闭命令,终端一直接关闭。

后端启动与停止
先要进行后端启动的相关配置:
进入bin目录,将redis源码目录下的redis.conf文件复制到redis安装目录的bin目录下。
可以手动进入虚拟机内复制粘贴,也可以用命令:
进入bin目录后:
cp /hime/hadoop/software/Redis/redis-3.0.0/redis.conf ./

修改redis.conf文件,如图所示:将daemonize的值改为yes后保存。
在这里插入图片描述
后端启动:

[hadoop@hadoop1 bin]# ./redis-server redis.conf---redis 根据redis.conf的配置来运行

在这里插入图片描述
观察后端是否启动:

[hadoop@lhadoop1 bin]# ps -aux | grep redis

在这里插入图片描述
看到id为:14270 端口号为:6379

后端关闭:
1 强制关闭:kill -9 +进程id 比如我关闭我的进程 即为:kill -9 14270
2 正常关闭:./redis-cli shutdown

6 Redis客户端介绍和基本使用
使用途径:
1 正常关闭redis服务。
2 让终端进入redis控制台(后台运行redis时使用)。

启动命令:[hadoop@hadoop1 bin]# ./redis-cli -h 127.0.0.1 -p 6379
注:
-h 后面指定访问的redis服务器的ip地址
-p 后面指定访问的redis服务器的port端口
若IP和port接口都是默认的 也可以用:./redis-cli

关闭客户端命令:
1 Ctrl+C
2 输入quit
注:两种方法均不影响数据的存储

7 修改redis数据库数量
将redis.conf配置文件中databases的值改变即可
在这里插入图片描述
8 选择Redis数据库
redis默认使用下标为0的数据库,如若需要切换数据库,在redis控制台中,直接使用”select + 下标号”选择数据库。
例如:select 14

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值