centos7安装Redis及连接成功示例
一、安装gcc
gcc编译c的,因为redis是c编写的,所以我们先安装下gcc
yum install gcc-c++
三、本人目录解释:
(tool是在根目录下自己创建的文件夹,作用:存放软件安装包)
(software是在根目录下自己创建的文件夹,作用:存放安装后的软件)
三、wget方式下载redis压缩包到指定目录,并解压,以及编译
wget -P 指定目录 下载地址
wget -P /tool http://download.redis.io/releases/redis-3.2.9.tar.gz
解压
tar -zxvf redis-3.2.9.tar.gz
这样/tool/目录下就有解压后的redis-3.2.9了
编译:
[[email protected] /]# cd /tool/redis-3.2.9/ #进入redis-3.2.9目录
[[email protected] redis-3.2.9]# make #编译
四、安装redis
[[email protected] /]# cd /tool/redis-3.2.9/ #进入redis-3.2.9目录
[[email protected] redis-3.2.9]# make PREFIX=/software/redis install #安装到/software/redis/目录下
已经有redis
[[email protected] /]# cd /software/redis/
[[email protected] redis]# ll
total 0
drwxr-xr-x. 2 root root 134 Apr 26 11:17 bin
redis里有个bin,bin里是一些工具
[[email protected] redis]# cd bin
[[email protected] bin]# ll
total 15060
-rwxr-xr-x. 1 root root 2432936 Apr 26 11:17 redis-benchmark
-rwxr-xr-x. 1 root root 25080 Apr 26 11:17 redis-check-aof
-rwxr-xr-x. 1 root root 5181832 Apr 26 11:17 redis-check-rdb
-rwxr-xr-x. 1 root root 2585880 Apr 26 11:17 redis-cli
lrwxrwxrwx. 1 root root 12 Apr 26 11:17 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 5181832 Apr 26 11:17 redis-server
cd回到/tool/redis-3.2.9/目录下的,我们需要把一个redis.conf配置文件 复制到/software/redis/下 后台启动用到
[[email protected] redis-3.2.9]# cp redis.conf /software/redis/
[[email protected] redis-3.2.9]# ll /software/redis/
总用量 48
drwxr-xr-x. 2 root root 134 7月 2 16:44 bin
-rw-r--r--. 1 root root 46695 7月 2 16:49 redis.conf
五、启动和关闭redis服务
启动redis就是执行 /software/redis/里的bin里的redis-server命令
进入redis目录 执行
[[email protected] /]# cd /software/redis/
[[email protected] redis]# bin/redis-server
出现这种图标,说明启动成功;
但是 ,这种启动是前端或者前台启动,假如退出 程序就终止或者退出了。
所以这种服务程序,必须后端运行;
我们通过修改配置文件redis.conf
操作,
我们ctrl+c 退出当前程序;
vi打开redis.conf
vi /software/redis/redis.conf
找到
把no改成yes
esc退出 wq!保存;
然后进入redis目录,然后加载配置文件运行;
[[email protected] ~]# cd /software/redis/
[[email protected] redis]# ./bin/redis-server ./redis.conf
[[email protected] redis]#
通过ps -ef | grep -i redis命令来搜索redis服务
[[email protected] redis]# ps -ef | grep -i redis
root 22941 1 0 11:55 ? 00:00:00 ./bin/redis-server 127.0.0.1:6379
root 22959 22819 0 11:57 pts/0 00:00:00 grep --color=auto -i redis
[[email protected] redis]#
通过shutdown命令来停止redis服务的运行
[[email protected] redis]# ./bin/redis-cli shutdown
[[email protected] redis]# ps -ef | grep -i redis
root 22993 22819 0 11:58 pts/0 00:00:00 grep --color=auto -i redis
[[email protected] redis]#
六、redis连接操作
进入/software/redis目录,启动并且查看进程,启动成功后,./bin/redis-cli进入了连接
[[email protected] /]# cd /software/redis/
[[email protected] redis]# ./bin/redis-server ./redis.conf
[[email protected] redis]# ps -ef | grep -i redis
root 23065 1 1 12:00 ? 00:00:00 ./bin/redis-server 127.0.0.1:6379
root 23075 22819 0 12:00 pts/0 00:00:00 grep --color=auto -i redis
[[email protected] redis]#
进入客户端
[[email protected] redis]# ./bin/redis-cli
127.0.0.1:6379>
127.0.0.1:6379> set key1 value1 #通过set设置,存储 key:value格式的数据
OK
127.0.0.1:6379> get key1 #通过get获取值
"value1"
127.0.0.1:6379>
以上说明redis连接成功。
以下为简单的语法操作:
127.0.0.1:6379> keys * #keys * 显示所有keys
1) "key1"
127.0.0.1:6379>
127.0.0.1:6379> del key1 #通过del删除key
(integer) 1
127.0.0.1:6379> keys *
(empty list or set)
127.0.0.1:6379>
七、退出redis连接及停止redis服务
按Ctrl+c 退出redis命令行
退出redis命令行后,输入./bin/redis-cli shutdown 停止redis服务