Redis 初探

运维的坑 2016-01-12 20:05 暂无评论

这是个坑,我也不吐槽了……

资料参考

Redis 官网:http://redis.io/
Redis WIKI:https://zh.wikipedia.org/zh-cn/Redis
Redis 设计与实现:http://redisbook.com/
Redis 命令参考:http://redisdoc.com/
Redis2.4 命令参考:https://redis.readthedocs.org/en/2.4/

安装

在官网下载 Redis3.0 并且解压编译安装到系统中,编译的时候如果提示错误注意检查有没有安装 gcc 如果没有的话安装一下 yum install gcc -y

[root@localhost ~]# wget -c http://download.redis.io/releases/redis-3.0.6.tar.gz && tar zxvf redis-3.0.6.tar.gz && cd redis-3.0.6 && make MALLOC=libc && make install

安装在 CentOS7 1511 最小化安装。编译 redis 的时候会出现一些问题,如果不懂多 Google 一下

Redis 软件包

redis-benchmark Redis 性能测试
redis-check-dump 检查本地数据库文件
redis-sentinel Redis 实例监控管理
redis-check-aof 修复 AOF 问题文件
redis-cli Redis 客户端
redis-server Redis 服务启动

Redis 运行

运行 Redis 的方法很简单,一般运行方式是 src/redis-server 就可以把 Redis 运行起来!

[root@localhost redis-3.0.6]# redis-server
2611:C 12 Jan 19:49:05.152 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
2611:M 12 Jan 19:49:05.152 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 3.0.6 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 2611
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           http://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

2611:M 12 Jan 19:49:05.154 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
2611:M 12 Jan 19:49:05.154 # Server started, Redis version 3.0.6
2611:M 12 Jan 19:49:05.154 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
2611:M 12 Jan 19:49:05.154 * The server is now ready to accept connections on port 6379

在启动 Redis 的时候如果不指定配置参数的话,是默认读取 Redis 根目录下的 redis.conf 配置文件来启动的。启动后默认监听 6379 端口,在运行的日志中有提示到警告内容,因为没有指定配置文件,所以按默认的配置来运行。不知道这么理解对不对[逃]

连接 Redis

使用 redis-cli 连接 Redis 服务

root@localhost ~]# redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379>

连接成功后可以执行 info 看看是否成功返回,如果错误那么连接失败或者 Redis 服务没有启动成功!

127.0.0.1:6379> info
# Server
redis_version:3.0.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:c71cf6fb92b44111
redis_mode:standalone
os:Linux 3.10.0-327.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.5
process_id:2611
run_id:b3506aec3005681a8225837af38bb1230e967219
tcp_port:6379
uptime_in_seconds:697
uptime_in_days:0
hz:10
lru_clock:9759466
config_file:

# Clients
connected_clients:1
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Memory
used_memory:882776
used_memory_human:862.09K
used_memory_rss:2265088
used_memory_peak:882776
used_memory_peak_human:862.09K
used_memory_lua:36864
mem_fragmentation_ratio:2.57
mem_allocator:libc

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1452599345
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:-1
rdb_current_bgsave_time_sec:-1
aof_enabled:0
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok

# Stats
total_connections_received:1
total_commands_processed:0
instantaneous_ops_per_sec:0
total_net_input_bytes:14
total_net_output_bytes:0
instantaneous_input_kbps:0.00
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:0
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:0
migrate_cached_sockets:0

# Replication
role:master
connected_slaves:0
master_repl_offset:0
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0

# CPU
used_cpu_sys:0.57
used_cpu_user:0.21
used_cpu_sys_children:0.00
used_cpu_user_children:0.00

# Cluster
cluster_enabled:0

# Keyspace
127.0.0.1:6379>

喏,下面再看看 Redis 的 conf 配置的方式,以及参数等等。

暂无评论