LINUX安装Redis
1.安装gcc
gcc预编译c,因为redis是c编写开发的,需要安装gcc依赖。
yum -y install gcc-c++
#已安装:
# gcc-c++.x86_64 0:4.4.7-18.el6
#作为依赖被安装:
# libstdc++-devel.x86_64 0:4.4.7-18.el6
#作为依赖被升级:
# libstdc++.x86_64 0:4.4.7-18.el6
#完毕!
2.wget方式安装,下载redis压缩包,并解压,以及编译
#先安装wget
yum -y install wget
#下载
[root@zhyc ~] wget http://download.redis.io/releases/redis-3.2.10.tar.gz
#已保存 “redis-3.2.10.tar.gz” [1550261/1550261])
#解压
tar -zxvf redis-3.2.10.tar.gz
#ll命令可以查看文件信息,可以看到redis了
[root@zhyc ~] ll
#-rw-r--r--. 1 root root 1550261 7月 29 00:00 redis-3.2.10
#编译,先进入redis-3.2.10目录,然后make命令编译
[root@zhyc ~] cd redis-3.2.10
[root@zhyc redis-3.2.10] make
3.安装
[root@zhyc redis-3.2.10] make PREFIX=/usr/local/redis install
[root@zhyc redis-3.2.10] cd /usr/local
[root@zhyc local] ll
#已经有了redis
#总用量 4
#drwxr-xr-x. 3 root root 4096 8月 31 15:05 redis
#打开redis下的bin目录,我们需要把root目录下的redis.conf配置文件复制要该bin目录,redis后台启动用到
[root@zhyc local] cd redis/bin
[root@zhyc local] cd /../root
[root@zhyc ~] cd redis-3.2.10
[root@zhyc redis-3.2.10] ll
#-rw-rw-r--. 1 root root 46695 7月 28 23:59 redis.conf
[root@zhyc redis-3.2.10] cp redis.conf /usr/local/redis
4.启动和关闭Redis
#启动redis就是执行redis下的bin里的redis-server命令
[root@zhyc /] cd /usr/local/redis/bin
[root@zhyc bin] ./redis-server
#4923:C 31 Aug 15:22:08.865 # Warning: no config file specified, using the default config. In #order to specify a config file use ./redis-server /path/to/redis.conf
#4923:M 31 Aug 15:22:08.866 * Increased maximum number of open files to 10032 (it was originally #set to 1024).
# _._
# _.-``__ ''-._
# _.-`` `. `_. ''-._ Redis 3.2.10 (00000000/0) 64 bit
# .-`` .-```. ```\/ _.,_ ''-._
#( ' , .-` | `, ) Running in standalone mode
# |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
# | `-._ `._ / _.-' | PID: 4923
# `-._ `-._ `-./ _.-' _.-'
# |`-._`-._ `-.__.-' _.-'_.-'|
# | `-._`-._ _.-'_.-' | http://redis.io
# `-._ `-._`-.__.-'_.-' _.-'
# |`-._`-._ `-.__.-' _.-'_.-'|
# | `-._`-._ _.-'_.-' |
# `-._ `-._`-.__.-'_.-' _.-'
# `-._ `-.__.-' _.-'
# `-._ _.-'
# `-.__.-'
#出现这种图标,说明启动成功;
#但是 ,这种启动是前端或者前台启动,假如退出 程序就终止或者退出了。
#所以这种服务程序,必须后端运行,我们通过修改配置文件redis.conf
#将redis.conf里面的daemonize no 改成daeminize yes
[root@zhyc /] vi /usr/local/reids/redis.conf
#然后进入redis目录,然后加载配置文件运行;
[root@zhyc ~]# cd /usr/local/redis/
[root@zhyc redis]# ./bin/redis-server ./redis.conf
#我们通过ps -ef | grep -i redis命令来搜索redis服务
[root@zhyc redis]# ps -ef | grep -i redis
root 8692 1 0 16:52 ? 00:00:19 bin/redis-server *:6379
root 8954 8930 0 20:30 pts/0 00:00:00 grep --color=auto -i redi
#我们通过shutdown命令来停止redis服务的运行
[root@zhyc redis]# ./bin/redis-cli shutdown
[root@zhyc redis]# ps -ef | grep -i redis
root 8959 8930 0 20:35 pts/0 00:00:00 grep --color=auto -i redi
5.redis基本使用
#进入客户端
[root@zhyc redis]# ./bin/redis-cli
#设置name(key-value格式)
127.0.0.1:6379> set name zhyc
OK
#获取name
127.0.0.1:6379> get name
"zhyc"
#查询所有keys
127.0.0.1:6379> keys *
1) "name"
#删除name
127.0.0.1:6379> del name
(integer) 1
127.0.0.1:6379> keys *
(empty list or set)