基于Centos7.0安装Redis单机

一、环境检查

Redis应用程序基于C语言开发,后续的make编译需要C语言编译器gcc的支持,如果没有,需要先安装gcc。可以输入以下命令检查gcc是否安装: rpm -q gcc

1.1 检查是否安装gcc

[root@thinkingcao ~]# rpm -q gcc
package gcc is not installed

1.2 安装C语言环境

使用yum在线安装gcc和c++环境

[root@thinkingcao ~]# rpm -q gcc
package gcc is not installed
[root@thinkingcao ~]# yum install gcc-c++

1.3 检查wget是否安装

没有wget命令则使用yum安装wget

[root@thinkingcao ~]# rpm -q wget
wget-1.14-10.el7.x86_64
[root@thinkingcao ~]#

根据不同版本的Linux操作系统,显示的结果各不一样,如果结果显示没有安装wget,则使用以下命令执行wget的安装

yum install wget

二、下载安装Redis

2.1 使用wget在线下载Redis安装包

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

2.2 解压Redis

tar -zxvf redis-3.2.9.tar.gz

2.3 编译安装Redis

cd redis-3.2.9
    
make
    
cd src
    
make install PREFIX=/usr/local/redis

2.4 移动配置文件到安装目录下

cd ../

mkdir /usr/local/redis/etc

mv redis.conf /usr/local/redis/etc

三、修改Redis配置

3.1 修改Redis为后台启动

protected-mode no # 关闭保护模式,使用密码访问
vi /usr/local/redis/etc/redis.conf   //将daemonize no 改成daemonize yes,表示以后台运行方式启动

3.2 修改Redis密码

vi /usr/local/redis/etc/redis.conf    将密码修改为: requirepass 123456

3.3 绑定监听的网卡IP,注释掉或配置成0.0.0.0可使任意IP均可访问

将bind 127.0.0.1这一行注释为 #bind 127.0.0.1 表示关闭外网访问

四、启动连接Redis

4.1 启动Redis

/usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf 

4.2 连接Redis客户端

./redis-cli -h 127.0.0.1 -p 6379 -a "123456" 

输入ping  ,如果响应 PING 结果表示成功

4.3 关闭防火墙

a.查看防火墙状态

systemctl status firewalld

b.临时关闭防火墙

systemctl stop firewalld

c.永久关闭防火墙

systemctl disable firewalld

4.5 停止Redis服务

./redis-cli -h 127.0.0.1 -p 6379 -a "123456" shutdown

五、核心操作日志

[root@thinkingcao src]# make install PREFIX=/usr/local/redis

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

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
[root@thinkingcao src]# cd ../
[root@thinkingcao redis-3.2.9]# mkdir /usr/local/redis/etc
[root@thinkingcao redis-3.2.9]# mv redis.conf /usr/local/redis/etc
[root@thinkingcao redis-3.2.9]# vi /usr/local/redis/etc/redis.conf
[root@thinkingcao redis-3.2.9]# /usr/local/redis/bin/redis-server /usr/local/redis/etc/redis.conf
[root@thinkingcao redis-3.2.9]# ls
00-RELEASENOTES  BUGS  CONTRIBUTING  COPYING  deps  INSTALL  Makefile  MANIFESTO  README.md  runtest  runtest-cluster  runtest-sentinel  sentinel.conf  src  tests  utils
[root@thinkingcao redis-3.2.9]# cd ..
[root@thinkingcao ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  redis-3.2.9  redis-3.2.9.tar.gz
[root@thinkingcao ~]# cd ../
[root@thinkingcao /]# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  swap  sys  tmp  usr  var
[root@thinkingcao /]# cd usr
[root@thinkingcao usr]# ls
bin  etc  games  include  lib  lib64  libexec  local  sbin  share  src  tmp
[root@thinkingcao usr]# cd local/
[root@thinkingcao local]# ls
bin  etc  games  include  lib  lib64  libexec  redis  sbin  share  src
[root@thinkingcao local]# cd redis/
[root@thinkingcao redis]# ls
bin  etc
[root@thinkingcao redis]# cd bin/
[root@thinkingcao bin]# ls
redis-benchmark  redis-check-aof  redis-check-rdb  redis-cli  redis-sentinel  redis-server
[root@thinkingcao bin]# ./redis-cli -h 127.0.0.1 -p 6379 -a "123456"
127.0.0.1:6379> get name
(nil)
127.0.0.1:6379> set name
(error) ERR wrong number of arguments for 'set' command
127.0.0.1:6379> set name 111
OK
127.0.0.1:6379> get name
"111"
127.0.0.1:6379> get name
"111"
127.0.0.1:6379>

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Thinkingcao

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值