搭建环境:linux是centos7.4(请注意centos7以下版本的防火墙跟centos7以上的会有所区别,使用redis客户端连接redis时会有区别,建议使用centos7以上版本)
一、下载linux版本的redis
二、安装
1、使用SecureCRT工具将redis压缩包上传到linux系统root用户的root工作目录下
注:SecureCRT是一款支持SSH的终端仿真程序,使用它可以连接windows、unix和vms,没有安装的可以参考我的另一篇博客
参考地址:writing...
连接上vm中的linux
按下alt+p,然后将下载的redis压缩包拖到CRT窗口
输入命令ll查看,此时root目录下已经有redis压缩包了
2、安装gcc编译环境:yum install gcc-c++
输入y
完成
3、解压:tar -zxvf redis-4.0.6.tar.gz
[root@localhost ~]# tar -zxvf redis-4.0.6.tar.gz
4、进入到redis目录,执行make进行编译
[root@localhost ~]# cd redis-4.0.6
[root@localhost redis-4.0.6]# make
5、安装到指定目录下:make install PREFIX=/usr/local/redis (该目录可以自定义)
三、配置
1、将redis.conf文件复制到redis的安装目录下面的bin目录
[root@localhost redis-4.0.6]# cp redis.conf /usr/local/redis/bin
2、修改配置文件
首先打开bin目录下的redis.conf配置文件
[root@localhost redis-4.0.6]# vi /usr/local/redis/bin/redis.conf
将redis的启动方式更改为后台启动:daemonize no 修改为yes (默认为前端启动)
保存退出
注:如果需要远程连接redis服务器或者使用客户端连接redis服务器,还需要修改其它配置,可以参考我的下一篇博文
四、启动redis并测试
1、进入到redis的bin目录
[root@localhost redis-4.0.6]# cd /usr/local/redis/bin
2、启动redis服务
[root@localhost bin]# ./redis-server redis.conf
3、查看redis进程是否启动
[root@localhost bin]# ps aux|grep redis
4、连接上redis进行测试
[root@localhost bin]# ./redis-cli
127.0.0.1:6379> set a 10
OK
127.0.0.1:6379> get a
"10"
5、退出连接(使用quit也可以)
127.0.0.1:6379> exit
[root@localhost bin]#
6、关闭redis服务
[root@localhost bin]# ./redis-cli -p 6379 shutdown