ICode9

精准搜索请尝试: 精确搜索
首页 > 数据库> 文章详细

Linux centos安装Redis,启动Redis,使用Redis,停止Redis

2020-03-10 16:09:24  阅读:552  来源: 互联网

标签:5.0 centos Redis redis local usr Linux root localhost


redis的安装包:以原码形式形式提供的
.c文件
将.c编译为.o文件 需要:gcc
将编译后的文件去安装到Linux的系统上

一、安装环境

redis是C语言开发,安装redis需要先将官网下载原码进行编译,编译依赖gcc环境。如果没有gcc环境,需要安装gcc:
Linux在链接网络的情况下

[root@localhost ~]# yum install gcc-c++

在这里插入图片描述
如果提示是否下载,输入y
在这里插入图片描述
如果提示是否安装,输入y
在这里插入图片描述
安装完成

二、安装Redis

步骤1、下载redis到Windows

Redis官方网站:https://redis.io/download
在这里插入图片描述

步骤2、将Windows下载的压缩文件上传到Linux,通过WinSCP进行上传,步骤如下

上传到/root/就可以
WinSCP官方下载:https://winscp.net/eng/download.php
在这里插入图片描述

步骤3、解压

在Linux里面解压 redis-5.0.7.tar.gz
定位到根目录下

[root@localhost ~]#  cd /root/
[root@localhost ~]# tar -zxvf redis-5.0.7.tar.gz 

在这里插入图片描述
在这里插入图片描述
解压成功后的文件
在这里插入图片描述

步骤4、编译 将原码翻译为.o文件

进入解压文件夹。

[root@localhost ~]# cd redis-5.0.7

进入redis-5.0.7到执行

[root@localhost redis-5.0.7]# make

编译成功(编译前一定要安装好gcc,否则会编译失败)
在这里插入图片描述

步骤5、将redis安装到/usr/local/redis

a)redis启动需要一个配置文件,可以修改端口号等信息
创建文件夹

[root@localhost ~]# mkdir /usr/local/redis

b)切换到redis-5.0.7目录

[root@localhost ~]# cd /root/redis-5.0.7

c)将安装到/usr/local/redis/

[root@localhost redis-5.0.7]# make PREFIX=/usr/local/redis/ install

d)安装成功
在这里插入图片描述
e) 安装完成之后,在/usr/local/redis/bin 下有几个可执行文件
在这里插入图片描述

步骤6、复制文件

redis启动需要一个配置文件,可以修改端口号等信息

[root@localhost redis-5.0.7]# cp /root/redis-5.0.7/redis.conf /usr/local/redis/

在这里插入图片描述

三、Redis的启动

1、前端模式启动

直接运行 /bin/redis-server将以前端模式启动,前端模式启动的缺点是启动完成后,不能进行其他的操作,如果要操作必须使用ctrl+c,同时redis-server程序结束运行,不推荐使用此方法

[root@localhost ~]# /usr/local/redis/bin/redis-server

运行成功
在这里插入图片描述
ctrl+c结束运行
在这里插入图片描述

2、后端模式启动

a) 修改redis.conf配置文件,daemonize yes以后端模式启动

[root@localhost ~]# vim /usr/local/redis/redis.conf

在这里插入图片描述
将光标切换到指定的位置按i进入到插入模式将no改为yes
在这里插入图片描述
按Esc进入到末行模式wq保存退出
在这里插入图片描述
b) 启动时,指定配置文件
先切换目录

[root@localhost ~]# cd /usr/local/redis/

启动redis-server并指定启动到redis.conf

[root@localhost redis]# ./bin/redis-server ./redis.conf

开放6379端口

[root@localhost redis]# /sbin/iptables -I INPUT -p tcp --dport 6379 -j ACCEPT

保存规则

[root@localhost redis]# /etc/rc.d/init.d/iptables save

端口号已开启并且对应的规则已经保存
在这里插入图片描述
查看对应的服务

[root@localhost redis]# ps -ef|grep -i redis

在这里插入图片描述
证明服务正在运行
c) 通过客户端连接redis

[root@localhost redis]# ./bin/redis-cli

在这里插入图片描述
测试一下Redis的命令
在这里插入图片描述
d) 退出客户端

127.0.0.1:6379> quit

四、Redis的停止

1、如果是用apt-get或者yum install安装的redis,可以直接通过下面的命令停止/启动/重启redis

[root@localhost redis]# /etc/init.d/redis-server stop
[root@localhost redis]# /etc/init.d/redis-server start
[root@localhost redis]# /etc/init.d/redis-server restart

2、通过源码安装的redis,则可以通过redis的客户端程序redis-cli的shutdown命令来重启redis

[root@localhost redis]# redis-cli -h 127.0.0.1 -p 6379 shutdown

3、如果上述方式都没有成功停止redis,则可以使用

[root@localhost redis]# kill -9 

标签:5.0,centos,Redis,redis,local,usr,Linux,root,localhost
来源: https://blog.csdn.net/qq_44757034/article/details/104768879

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有