Redis简介Redis 是一个开源(BSD许可)的,内存中的数据结构存储系统,它可以用作数据库、缓存和消息中间件。 它支持多种类型的数据结构,如 字符串(strings), 散列(hashes), 列表(lists), 集合(sets), 有序集合(sorted sets) 与范围查询, bitmaps, hyperloglogs 和 地理空间(geospatial) 索引半径查询。 Redis 内置了 复制(replication)LUA脚本(Lua scripting), LRU驱动事件(LRU eviction)事务(transactions) 和不同级别的 磁盘持久化(persistence), 并通过 Redis哨兵(Sentinel)和自动 分区(Cluster)提供高可用性(high availability)。

以上来自Redis中文官网:http://redis.cn/ ,  下载地址:https://redis.io/download/

1 .   解压、编译安装Redis(这里用的是redis-5.0.14版本)

[root@Redis1 ~]# mkdir redis
[root@Redis1 ~]# cd redis/
[root@Redis1 redis]# ls
redis-5.0.14.tar.gz
[root@Redis1 redis]# tar zxf redis-5.0.14.tar.gz 
[root@Redis1 redis]# cd redis-5.0.14/
[root@Redis1 redis-5.0.14]# ls
00-RELEASENOTES COPYING Makefile redis.conf runtest-moduleapi src
BUGS deps MANIFESTO runtest runtest-sentinel tests
CONTRIBUTING INSTALL README.md runtest-cluster sentinel.conf utils
[root@Redis1 redis-5.0.14]# make && make install
cd src && make all
make[1]: Entering directory '/root/redis/redis-5.0.14/src'
CC Makefile.dep
rm -rf redis-server redis-sentinel redis-cli redis-benchmark redis-check-rdb redis-check-aof *.o *.gcda *.gcno *.gcov redis.info lcov-html Makefile.dep dict-benchmark
(cd ../deps && make distclean)
......

2. 安装后启动

[root@Redis1 redis-5.0.14]# utils/install_server.sh 
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379]   ##端口
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]   ##配置文件
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log]   ##日志文件
Selected default - /var/log/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] ##数据目录
Selected default - /var/lib/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server] ##二进制命令
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /var/log/redis_6379.log
Data dir : /var/lib/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

3. 查看监听到的端口是本机,所以把它改成监听所有端口

[root@Redis1 redis-5.0.14]# netstat -antlp | grep :6379
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 7206/redis-server 1
[root@Redis1 redis-5.0.14]# vim /etc/redis/6379.conf69 # 
70 bind 0.0.0.0    ##配置文件第70行改成0.0.0.0监听所有端口
[root@Redis1 redis-5.0.14]# /etc/init.d/redis_6379 restart     ##重启服务
Stopping ...
Waiting for Redis to shutdown ...
Redis stopped
Starting Redis server...
[root@Redis1 redis-5.0.14]# netstat -antlp | grep :6379  ##再次查看监听端口,已经改成了监听所有
tcp 0 0 0.0.0.0:6379 0.0.0.0:* LISTEN 7618/redis-server 0 
tcp 0 0 127.0.0.1:6379 127.0.0.1:45634 TIME_WAIT -

4. 安装后进入测试

[root@Redis1 redis-5.0.14]# redis-cli 
127.0.0.1:6379> set name redis
OK
127.0.0.1:6379> get name
"redis"
127.0.0.1:6379> 

至此安装完毕!!!

5. redis常用指令

config get *     //查看配置
select 1         //选择数据库
flushdb      //清空当前数据库
flushall      //清空所有数据库
move key 1    //移动key
del key          //删除
rename oldkey newkey  //改名
expire key 10      //设置过期时间
persist key       //设置持久化
keys user*       //查询
exists key       //判断是否存在

云野 » Redis安装部署

发表回复