redis 学习问题总结 | http://aperise.iteye.com/blog/2310639 |
ehcache memcached redis 缓存技术总结 | http://aperise.iteye.com/blog/2296219 |
redis-stat 离线安装 | http://aperise.iteye.com/blog/2310254 |
redis cluster 非ruby方式启动 | http://aperise.iteye.com/blog/2310254 |
redis-sentinel安装部署 | http://aperise.iteye.com/blog/2342693 |
spring-data-redis使用 | http://aperise.iteye.com/blog/2342615 |
redis客户端redisson实战 | http://blog.csdn.net/zilong_zilong/article/details/78252037 |
redisson-2.10.4源代码分析 | http://blog.csdn.net/zilong_zilong/article/details/78609423 |
tcmalloc jemalloc libc选择 | http://blog.csdn.net/u010994304/article/details/49906819 |
redis-sentinel安装部署
1.redis安装
1)必要的linux库安装
yum install gcc
yum install tcl
yum install tcl
2)下载、解压、编译和安装redis
#创建redis用户和组
groupadd redis
useradd -g redis redis
#修改用户密码
passwd redis
#使用root账户切换到redis目录
cd /home/redis
#下载redis源码redis-3.2.0.tar.gz
wget http://download.redis.io/releases/redis-3.2.0.tar.gz
#解压redis-3.2.0.tar.gz
tar -zxvf redis-3.2.0.tar.gz
#编译和安装
cd /home/redis/redis-3.2.0
make
make install
groupadd redis
useradd -g redis redis
#修改用户密码
passwd redis
#使用root账户切换到redis目录
cd /home/redis
#下载redis源码redis-3.2.0.tar.gz
wget http://download.redis.io/releases/redis-3.2.0.tar.gz
#解压redis-3.2.0.tar.gz
tar -zxvf redis-3.2.0.tar.gz
#编译和安装
cd /home/redis/redis-3.2.0
make
make install
3) 安装完成后会在系统目录/usr/local/bin下生成如下文件:
2.redis-sentinel部署
1)部署结构图如下
2)3台redis节点部署并启动
节点一192.168.173.23上做如下配置:
#1.切换到redis用户
su - redis
#2.创建部署需要的目录
#日志目录
mkdir -p /home/redis/sentinel-cluster/logs/
#数据目录
mkdir -p /home/redis/sentinel-cluster/data/
#进程目录
mkdir -p /home/redis/sentinel-cluster/pids/
#配置文件目录
mkdir -p /home/redis/sentinel-cluster/conf/
#3.复制并修改一份redis.conf文件并修改配置
cd /home/redis/sentinel-cluster/conf/
#从源代码目录下拷贝一份配置文件
cp /home/redis/redis-3.2.0/redis.conf /home/redis/sentinel-cluster/conf/redis.conf
#修改配置文件
vi /home/redis/sentinel-cluster/conf/redis.conf
#主要修改如下内容
bind 192.168.173.23
port 6382
#开启redis守护进程
daemonize yes
#指定进程文件存放目录
pidfile /home/redis/sentinel-cluster/pids/redis.pid
#指定日志文件存放目录
logfile "/home/redis/sentinel-cluster/logs/redis.log"
data /home/redis/sentinel-cluster/data/
dbfilename dump.rdb
appendonly yes
appendfilename "appendonly.aof"
#主库认证密码
masterauth abcd_123456
#客户端连接密码
requirepass abcd_123456
su - redis
#2.创建部署需要的目录
#日志目录
mkdir -p /home/redis/sentinel-cluster/logs/
#数据目录
mkdir -p /home/redis/sentinel-cluster/data/
#进程目录
mkdir -p /home/redis/sentinel-cluster/pids/
#配置文件目录
mkdir -p /home/redis/sentinel-cluster/conf/
#3.复制并修改一份redis.conf文件并修改配置
cd /home/redis/sentinel-cluster/conf/
#从源代码目录下拷贝一份配置文件
cp /home/redis/redis-3.2.0/redis.conf /home/redis/sentinel-cluster/conf/redis.conf
#修改配置文件
vi /home/redis/sentinel-cluster/conf/redis.conf
#主要修改如下内容
bind 192.168.173.23
port 6382
#开启redis守护进程
daemonize yes
#指定进程文件存放目录
pidfile /home/redis/sentinel-cluster/pids/redis.pid
#指定日志文件存放目录
logfile "/home/redis/sentinel-cluster/logs/redis.log"
data /home/redis/sentinel-cluster/data/
dbfilename dump.rdb
appendonly yes
appendfilename "appendonly.aof"
#主库认证密码
masterauth abcd_123456
#客户端连接密码
requirepass abcd_123456
节点一192.168.173.23上启动redis服务:
#默认会调用/usr/local/bin/redis-server启动服务
redis-server /home/redis/sentinel-cluster/conf/redis.conf
redis-server /home/redis/sentinel-cluster/conf/redis.conf
节点二192.168.173.24上做如下配置:
#1.切换到redis用户
su - redis
#2.创建部署需要的目录
#日志目录
mkdir -p /home/redis/sentinel-cluster/logs/
#数据目录
mkdir -p /home/redis/sentinel-cluster/data/
#进程目录
mkdir -p /home/redis/sentinel-cluster/pids/
#配置文件目录
mkdir -p /home/redis/sentinel-cluster/conf/
#3.复制并修改一份redis.conf文件并修改配置
cd /home/redis/sentinel-cluster/conf/
#从源代码目录下拷贝一份配置文件
cp /home/redis/redis-3.2.0/redis.conf /home/redis/sentinel-cluster/conf/redis.conf
#修改配置文件
vi /home/redis/sentinel-cluster/conf/redis.conf
#主要修改如下内容
bind 192.168.173.24
port 6382
#开启redis守护进程
daemonize yes
#指定进程文件存放目录
pidfile /home/redis/sentinel-cluster/pids/redis.pid
#指定日志文件存放目录
logfile "/home/redis/sentinel-cluster/logs/redis.log"
data /home/redis/sentinel-cluster/data/
dbfilename dump.rdb
appendonly yes
appendfilename "appendonly.aof"
#主库认证密码
masterauth abcd_123456
#客户端连接密码
requirepass abcd_123456
#指定本节点是节点一的从节点
slaveof 192.168.173.23 6382
su - redis
#2.创建部署需要的目录
#日志目录
mkdir -p /home/redis/sentinel-cluster/logs/
#数据目录
mkdir -p /home/redis/sentinel-cluster/data/
#进程目录
mkdir -p /home/redis/sentinel-cluster/pids/
#配置文件目录
mkdir -p /home/redis/sentinel-cluster/conf/
#3.复制并修改一份redis.conf文件并修改配置
cd /home/redis/sentinel-cluster/conf/
#从源代码目录下拷贝一份配置文件
cp /home/redis/redis-3.2.0/redis.conf /home/redis/sentinel-cluster/conf/redis.conf
#修改配置文件
vi /home/redis/sentinel-cluster/conf/redis.conf
#主要修改如下内容
bind 192.168.173.24
port 6382
#开启redis守护进程
daemonize yes
#指定进程文件存放目录
pidfile /home/redis/sentinel-cluster/pids/redis.pid
#指定日志文件存放目录
logfile "/home/redis/sentinel-cluster/logs/redis.log"
data /home/redis/sentinel-cluster/data/
dbfilename dump.rdb
appendonly yes
appendfilename "appendonly.aof"
#主库认证密码
masterauth abcd_123456
#客户端连接密码
requirepass abcd_123456
#指定本节点是节点一的从节点
slaveof 192.168.173.23 6382
节点二192.168.173.24上启动redis服务:
#默认会调用/usr/local/bin/redis-server启动服务
redis-server /home/redis/sentinel-cluster/conf/redis.conf
redis-server /home/redis/sentinel-cluster/conf/redis.conf
节点三192.168.173.25上做如下配置:
#1.切换到redis用户
su - redis
#2.创建部署需要的目录
#日志目录
mkdir -p /home/redis/sentinel-cluster/logs/
#数据目录
mkdir -p /home/redis/sentinel-cluster/data/
#进程目录
mkdir -p /home/redis/sentinel-cluster/pids/
#配置文件目录
mkdir -p /home/redis/sentinel-cluster/conf/
#3.复制并修改一份redis.conf文件并修改配置
cd /home/redis/sentinel-cluster/conf/
#从源代码目录下拷贝一份配置文件
cp /home/redis/redis-3.2.0/redis.conf /home/redis/sentinel-cluster/conf/redis.conf
#修改配置文件
vi /home/redis/sentinel-cluster/conf/redis.conf
#主要修改如下内容
bind 192.168.173.25
port 6382
#开启redis守护进程
daemonize yes
#指定进程文件存放目录
pidfile /home/redis/sentinel-cluster/pids/redis.pid
#指定日志文件存放目录
logfile "/home/redis/sentinel-cluster/logs/redis.log"
data /home/redis/sentinel-cluster/data/
dbfilename dump.rdb
appendonly yes
appendfilename "appendonly.aof"
#主库认证密码
masterauth abcd_123456
#客户端连接密码
requirepass abcd_123456
#指定本节点是节点一的从节点
slaveof 192.168.173.23 6382
su - redis
#2.创建部署需要的目录
#日志目录
mkdir -p /home/redis/sentinel-cluster/logs/
#数据目录
mkdir -p /home/redis/sentinel-cluster/data/
#进程目录
mkdir -p /home/redis/sentinel-cluster/pids/
#配置文件目录
mkdir -p /home/redis/sentinel-cluster/conf/
#3.复制并修改一份redis.conf文件并修改配置
cd /home/redis/sentinel-cluster/conf/
#从源代码目录下拷贝一份配置文件
cp /home/redis/redis-3.2.0/redis.conf /home/redis/sentinel-cluster/conf/redis.conf
#修改配置文件
vi /home/redis/sentinel-cluster/conf/redis.conf
#主要修改如下内容
bind 192.168.173.25
port 6382
#开启redis守护进程
daemonize yes
#指定进程文件存放目录
pidfile /home/redis/sentinel-cluster/pids/redis.pid
#指定日志文件存放目录
logfile "/home/redis/sentinel-cluster/logs/redis.log"
data /home/redis/sentinel-cluster/data/
dbfilename dump.rdb
appendonly yes
appendfilename "appendonly.aof"
#主库认证密码
masterauth abcd_123456
#客户端连接密码
requirepass abcd_123456
#指定本节点是节点一的从节点
slaveof 192.168.173.23 6382
节点三192.168.173.25上启动redis服务:
#默认会调用/usr/local/bin/redis-server启动服务
redis-server /home/redis/sentinel-cluster/conf/redis.conf
redis-server /home/redis/sentinel-cluster/conf/redis.conf
3)3台sentinel服务部署
节点一192.168.173.23上sentinel部署如下:
#创建sentinel配置文件sentinel.conf并修改配置
vi /home/redis/sentinel-cluster/conf/sentinel.conf
bind 192.168.173.23
#sentinel服务端口
port 26382
#开启sentinel守护进程
daemonize yes
#指定进程文件存放目录
pidfile /home/redis/sentinel-cluster/pids/sentinel.pid
#指定日志文件存放目录
logfile "/home/redis/sentinel-cluster/logs/sentinel.log"
#监听主节点192.168.173.23 6382,给监听sentinel集群名字取名为redis-sentinel,需要2个sentinel同意时候才做故障切换
sentinel monitor redis-sentinel 192.168.173.23 6382 2
sentinel down-after-milliseconds redis-sentinel 60000
sentinel failover-timeout redis-sentinel 180000
sentinel parallel-syncs redis-sentinel 1
#sentinel链接密码
sentinel auth-pass redis-sentinel abcd_123456
vi /home/redis/sentinel-cluster/conf/sentinel.conf
bind 192.168.173.23
#sentinel服务端口
port 26382
#开启sentinel守护进程
daemonize yes
#指定进程文件存放目录
pidfile /home/redis/sentinel-cluster/pids/sentinel.pid
#指定日志文件存放目录
logfile "/home/redis/sentinel-cluster/logs/sentinel.log"
#监听主节点192.168.173.23 6382,给监听sentinel集群名字取名为redis-sentinel,需要2个sentinel同意时候才做故障切换
sentinel monitor redis-sentinel 192.168.173.23 6382 2
sentinel down-after-milliseconds redis-sentinel 60000
sentinel failover-timeout redis-sentinel 180000
sentinel parallel-syncs redis-sentinel 1
#sentinel链接密码
sentinel auth-pass redis-sentinel abcd_123456
节点一192.168.173.23上启动sentinel服务
#默认会调用/usr/local/bin/redis-server启动服务
redis-server /home/redis/sentinel-cluster/conf/sentinel.conf --sentinel
redis-server /home/redis/sentinel-cluster/conf/sentinel.conf --sentinel
节点二192.168.173.24上sentinel部署如下:
#创建sentinel配置文件sentinel.conf并修改配置
vi /home/redis/sentinel-cluster/conf/sentinel.conf
bind 192.168.173.24
#sentinel服务端口
port 26382
#开启sentinel守护进程
daemonize yes
#指定进程文件存放目录
pidfile /home/redis/sentinel-cluster/pids/sentinel.pid
#指定日志文件存放目录
logfile "/home/redis/sentinel-cluster/logs/sentinel.log"
#监听主节点192.168.173.23 6382,给监听sentinel集群名字取名为redis-sentinel,需要2个sentinel同意时候才做故障切换
sentinel monitor redis-sentinel 192.168.173.23 6382 2
sentinel down-after-milliseconds redis-sentinel 60000
sentinel failover-timeout redis-sentinel 180000
sentinel parallel-syncs redis-sentinel 1
#sentinel链接密码
sentinel auth-pass redis-sentinel abcd_123456
vi /home/redis/sentinel-cluster/conf/sentinel.conf
bind 192.168.173.24
#sentinel服务端口
port 26382
#开启sentinel守护进程
daemonize yes
#指定进程文件存放目录
pidfile /home/redis/sentinel-cluster/pids/sentinel.pid
#指定日志文件存放目录
logfile "/home/redis/sentinel-cluster/logs/sentinel.log"
#监听主节点192.168.173.23 6382,给监听sentinel集群名字取名为redis-sentinel,需要2个sentinel同意时候才做故障切换
sentinel monitor redis-sentinel 192.168.173.23 6382 2
sentinel down-after-milliseconds redis-sentinel 60000
sentinel failover-timeout redis-sentinel 180000
sentinel parallel-syncs redis-sentinel 1
#sentinel链接密码
sentinel auth-pass redis-sentinel abcd_123456
节点二192.168.173.24上启动sentinel服务
#默认会调用/usr/local/bin/redis-server启动服务
redis-server /home/redis/sentinel-cluster/conf/sentinel.conf --sentinel
redis-server /home/redis/sentinel-cluster/conf/sentinel.conf --sentinel
节点三192.168.173.25上sentinel部署如下:
#创建sentinel配置文件sentinel.conf并修改配置
vi /home/redis/sentinel-cluster/conf/sentinel.conf
bind 192.168.173.25
#sentinel服务端口
port 26382
#开启sentinel守护进程
daemonize yes
#指定进程文件存放目录
pidfile /home/redis/sentinel-cluster/pids/sentinel.pid
#指定日志文件存放目录
logfile "/home/redis/sentinel-cluster/logs/sentinel.log"
#监听主节点192.168.173.23 6382,给监听sentinel集群名字取名为redis-sentinel,需要2个sentinel同意时候才做故障切换
sentinel monitor redis-sentinel 192.168.173.23 6382 2
sentinel down-after-milliseconds redis-sentinel 60000
sentinel failover-timeout redis-sentinel 180000
sentinel parallel-syncs redis-sentinel 1
#sentinel链接密码
sentinel auth-pass redis-sentinel abcd_123456
vi /home/redis/sentinel-cluster/conf/sentinel.conf
bind 192.168.173.25
#sentinel服务端口
port 26382
#开启sentinel守护进程
daemonize yes
#指定进程文件存放目录
pidfile /home/redis/sentinel-cluster/pids/sentinel.pid
#指定日志文件存放目录
logfile "/home/redis/sentinel-cluster/logs/sentinel.log"
#监听主节点192.168.173.23 6382,给监听sentinel集群名字取名为redis-sentinel,需要2个sentinel同意时候才做故障切换
sentinel monitor redis-sentinel 192.168.173.23 6382 2
sentinel down-after-milliseconds redis-sentinel 60000
sentinel failover-timeout redis-sentinel 180000
sentinel parallel-syncs redis-sentinel 1
#sentinel链接密码
sentinel auth-pass redis-sentinel abcd_123456
节点三192.168.173.25上启动sentinel服务
#默认会调用/usr/local/bin/redis-server启动服务
redis-server /home/redis/sentinel-cluster/conf/sentinel.conf --sentinel
redis-server /home/redis/sentinel-cluster/conf/sentinel.conf --sentinel
4)节点一redis服务和sentinel服务查看
红色边框标记部分是sentinel服务通过监测的主节点服务192.168.173.6382自己发现的redis从服务器,不需要自己指定,sentinel发现后自己会更新sentinel.conf配置文件
5)节点二redis服务和sentinel服务查看
红色边框标记部分是sentinel服务通过监测的主节点服务192.168.173.6382自己发现的redis从服务器,不需要自己指定,sentinel发现后自己会更新sentinel.conf配置文件
6)节点三redis服务和sentinel服务查看
红色边框标记部分是sentinel服务通过监测的主节点服务192.168.173.6382自己发现的redis从服务器,不需要自己指定,sentinel发现后自己会更新sentinel.conf配置文件
3.redis-sentinel部署方式下redis-stat启动
3.1 redis-stat命令介绍
安装参见博客 redis-stat安装
cd /home/redis/redis-stat-0.4.13/bin
./redis-stat --help
usage: redis-stat [HOST[:PORT] ...] [INTERVAL [COUNT]]
-a, --auth=PASSWORD Password
-v, --verbose Show more info
--style=STYLE Output style: unicode|ascii
--no-color Suppress ANSI color codes
--csv[=CSV_FILE] Print or save the result in CSV
--es=ELASTICSEARCH_URL Send results to ElasticSearch: [http://]HOST[:PORT][/INDEX]
--server[=PORT] Launch redis-stat web server (default port: 63790)
--daemon Daemonize redis-stat. Must be used with --server option.
--version Show version
--help Show this message
./redis-stat --help
usage: redis-stat [HOST[:PORT] ...] [INTERVAL [COUNT]]
-a, --auth=PASSWORD Password
-v, --verbose Show more info
--style=STYLE Output style: unicode|ascii
--no-color Suppress ANSI color codes
--csv[=CSV_FILE] Print or save the result in CSV
--es=ELASTICSEARCH_URL Send results to ElasticSearch: [http://]HOST[:PORT][/INDEX]
--server[=PORT] Launch redis-stat web server (default port: 63790)
--daemon Daemonize redis-stat. Must be used with --server option.
--version Show version
--help Show this message
3.2 redis-stat启动
linux上启动
cd /home/redis/redis-stat-0.4.13/bin
./redis-stat 192.168.173.23:6382 192.168.173.24:6382 192.168.173.25:6382 --server --daemon -a abcd_123456
./redis-stat 192.168.173.23:6382 192.168.173.24:6382 192.168.173.25:6382 --server --daemon -a abcd_123456
启动后截图如下: