-
Notifications
You must be signed in to change notification settings - Fork 506
QuickStart
- 方式一:启动dockerhub上的镜像
/bin/bash -c "$(curl -sSL https://raw.githubusercontent.com/ctripcorp/x-pipe/master/redis/dockerPackage/start-xpipe-container.sh)"
启动后的容器分布
执行命令:docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1e77491414a9 ctripcorpxpipe/xpipe-console:1.0 "docker-entrypoint.sh" 3 days ago Up 3 days 0.0.0.0:8079->8080/tcp, :::8079->8080/tcp consolejq
6694f9eff0ad ctripcorpxpipe/xpipe-console:1.0 "docker-entrypoint.sh" 3 days ago Up 3 days 0.0.0.0:8081->8080/tcp, :::8081->8080/tcp consoleoy
aa0d109c7aae ctripcorpxpipe/xpipe-meta:1.0 "docker-entrypoint.sh" 3 days ago Up 3 days 0.0.0.0:9747->8080/tcp, :::9747->8080/tcp metajq
0c6cb6dfe51f ctripcorpxpipe/xpipe-meta:1.0 "docker-entrypoint.sh" 3 days ago Up 3 days 0.0.0.0:9748->8080/tcp, :::9748->8080/tcp metaoy
0e0f78ae096d ctripcorpxpipe/xpipe-keeper:1.0 "docker-entrypoint.sh" 3 days ago Up 3 days 0.0.0.0:7080->8080/tcp, :::7080->8080/tcp keeperjq1
16c5fdd14a5e ctripcorpxpipe/xpipe-keeper:1.0 "docker-entrypoint.sh" 3 days ago Up 3 days 0.0.0.0:7081->8080/tcp, :::7081->8080/tcp keeperjq2
1915292f3a7f ctripcorpxpipe/xpipe-keeper:1.0 "docker-entrypoint.sh" 3 days ago Up 3 days 0.0.0.0:7180->8080/tcp, :::7180->8080/tcp keeperoy1
0c885945d8f3 ctripcorpxpipe/xpipe-keeper:1.0 "docker-entrypoint.sh" 3 days ago Up 3 days 0.0.0.0:7181->8080/tcp, :::7181->8080/tcp keeperoy2
15062ab45feb ctripcorpxpipe/xpipe-proxy:1.0 "docker-entrypoint.sh" 3 days ago Up 3 days 0.0.0.0:19079->80/tcp, :::19079->80/tcp, 0.0.0.0:19442->443/tcp, :::19442->443/tcp, 0.0.0.0:8092->8080/tcp, :::8092->8080/tcp proxyjq
ed38daf8e71e ctripcorpxpipe/xpipe-proxy:1.0 "docker-entrypoint.sh" 3 days ago Up 3 days 0.0.0.0:19081->80/tcp, :::19081->80/tcp, 0.0.0.0:19444->443/tcp, :::19444->443/tcp, 0.0.0.0:8091->8080/tcp, :::8091->8080/tcp proxyoy
d0e811ea5d3d zookeeper "/docker-entrypoint.…" 3 days ago Up 3 days 2888/tcp, 3888/tcp, 0.0.0.0:2181->2181/tcp, :::2181->2181/tcp, 8080/tcp zoo1
41381b5bd3a9 zookeeper "/docker-entrypoint.…" 3 days ago Up 3 days 2888/tcp, 3888/tcp, 8080/tcp, 0.0.0.0:2182->2181/tcp, :::2182->2181/tcp zoo2
d5f85ee0360e ctripcorpxpipe/xpipe-mysql:2.0 "docker-entrypoint.s…" 3 days ago Up 3 days 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp mysql
ba2b64f10700 redis:4.0 "docker-entrypoint.s…" 3 days ago Up 3 days 0.0.0.0:6379->6379/tcp, :::6379->6379/tcp redis-6379
4687df7ac486 redis:4.0 "docker-entrypoint.s…" 3 days ago Up 3 days 0.0.0.0:6479->6379/tcp, :::6479->6379/tcp redis-6479
58cfdf41284a redis:4.0 "docker-entrypoint.s…" 3 days ago Up 3 days 0.0.0.0:6579->6379/tcp, :::6579->6379/tcp redis-6579
d180471bb010 redis:4.0 "docker-entrypoint.s…" 3 days ago Up 3 days 0.0.0.0:6679->6379/tcp, :::6679->6379/tcp redis-6679
4539be899dd3 redis:4.0 "docker-entrypoint.s…" 3 days ago Up 3 days 0.0.0.0:7379->6379/tcp, :::7379->6379/tcp redis-7379
dcf1b8079c1e redis:4.0 "docker-entrypoint.s…" 3 days ago Up 3 days 0.0.0.0:7479->6379/tcp, :::7479->6379/tcp redis-7479
180a2255d038 redis:4.0 "docker-entrypoint.s…" 3 days ago Up 3 days 0.0.0.0:7579->6379/tcp, :::7579->6379/tcp redis-7579
a877a83287b4 redis:4.0 "docker-entrypoint.s…" 3 days ago Up 3 days 0.0.0.0:7679->6379/tcp, :::7679->6379/tcp redis-7679
- 方式二:根据最新代码编译本地镜像再启动
如果需要启动自定义版本,参考docker镜像使用
- 数据复制
测试master中数据是否能同步到备机房redis
-
如果本地未安装reids, 则随机进入一台redis容器
docker exec -ti redis-6379 bash
-
连接主机房master redis 并添加数据后退出
`redis-cli -h 172.19.0.10
set test1 12345`
-
连接备机房slave redis 获取数据成功后退出
`redis-cli -h 172.19.0.13
get test1`
-
例子
song@ubuntu:~/yusong/code/test$ docker exec -ti redis-6379 bash
root@c568933bae57:/data# redis-cli -h 172.19.0.10
172.19.0.10:6379> set test1 12345
OK
172.19.0.10:6379> exit
root@c568933bae57:/data# redis-cli -h 172.19.0.13
172.19.0.13:6379> get test1
"12345"
172.19.0.13:6379> exit
- 延迟监测
启动浏览器,进入localhost:8079/#/cluster_dc_shards/cluster1
查看各个redis的状态指示均为绿色
- 迁移功能
- 在cluster_list页面找到该cluster,点击迁移
- 选择待迁移cluster和目标机房
- 执行迁移
- 查看迁移是否成功
docker-compose down
- core 所有工程相关的底层依赖
- redis
- redis-core redis 相关核心依赖
- redis-console 管理控制台
console主要负责整个系统元信息的管理,比如cluster、shard、redis、keeper。并且提供系统监控、报警等功能。 - redis-keeper Keeper 相关
keeper主要实现redis数据复制协议,向redis master请求数据,并且将数据传播至slave,用于缓存redis复制日志以及rdb数据。
Keeper container是keeper的容器,一个Keeper Container内部可以放多个逻辑的keeper。 - redis-meta MetaServer 相关
meta server主要有两部分功能,一部分是和console交互,当console配置信息变化时,meta server调用keeper container以及keeper相关的接口,执行这部分变化。
第二部分是管理单机房内的所有 keeper、Redis的 状态,并对异常状态进行纠正。 - redis-integration-test 集成测试相关用例
- package 负责项目打包
- services 此目录主要放置各个公司依赖的服务实现,其它公司的用户可以实现相关接口,将服务替换为公司内部服务
- ctrip-service 携程相关的服务实现,比如配置、SSO 等
- local-service 默认实现,支持本地文件配置、数据源配置
- 清空本地 maven 仓库的 com 和 org 目录
- XPipe 所有携程相关的 maven 依赖放置在项目 mvn_repo 分支下
git checkout mvn_repo - 在 xpipe 目录下, 运行
sh install.sh
, 自动将非公共 maven 仓库的依赖装载在本地 maven 系统中
-
在导入项目后,可能会发生某些类无法找到的现象
import com.ctrip.xpipe.redis.core.entity.ClusterMeta;
import com.ctrip.xpipe.redis.core.entity.KeeperMeta;
import com.ctrip.xpipe.redis.core.entity.RedisMeta;
-
问题原因
这些类是mvn编译时自动生成的,需要先执行命令:mvn install -DskipTests
生成类所在目录:
redis/redis-core/target/generated-sources/dal-model
redis/redis-console/target/generated-sources/dal-jdbc
XPipe 依赖 CAT 作为其监控系统,如果没有部署 CAT,请在启动时加入参数:
-Dcat.client.enabled=false
执行命令:mvn install -DskipTests
[INFO] xpipe-parent ....................................... SUCCESS [3.394 s]
[INFO] core ............................................... SUCCESS [5.566 s]
[INFO] redis-parent ....................................... SUCCESS [0.316 s]
[INFO] redis-core ......................................... SUCCESS [4.630 s]
[INFO] redis-keeper ....................................... SUCCESS [2.585 s]
[INFO] redis-meta ......................................... SUCCESS [1.204 s]
[INFO] redis-console ...................................... SUCCESS [19.111 s]
[INFO] redis-integration-test ............................. SUCCESS [1.554 s]
XPipe 支持单机调试模式,可以在本地启动所有服务,模拟双机房,进行调试,不妨将两个机房命名为 jq
,oy
启动文件:com.ctrip.xpipe.redis.console.AppTest
对应测试 Case:startConsole8080
Console 配置了一个集群:cluster1,主机房在 jq
,包含两个分片:shard1, shard2
在分片 shard1 中:
- 在金桥机房有两个 Redis: 127.0.0.1:6379, 127.0.0.1:6479
- 在金桥机房有两个 Redis: 127.0.0.1:6579, 127.0.0.1:6679
- 在本地
jq
机房启动两个 Redis,分别监听在端口: 6379 6479,其中 6479 的 Redis 是 6379 的 Redis 的 slave,模拟主机房 - 在本地
oy
机房启动两个 Redis,分别监听在端口: 6579 6679,模拟备机房
启动文件:com.ctrip.xpipe.redis.meta.server.AppTest
对应测试 Case:
启动文件:com.ctrip.xpipe.redis.keeper.AppTest
对应测试 Case:
Redis 6379 会有两个 slave,端口在 6000 的代表 Keeper
127.0.0.1:6379> info replication
# Replication
role:master
connected_slaves:2
slave0:ip=127.0.0.1,port=6479,state=online,offset=9275,lag=0
slave1:ip=127.0.0.1,port=6000,state=online,offset=9214,lag=1
master_repl_offset:9275
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:9274
Keeper 6000 有两个 slave,6001 是在当前 jq
机房的 ackup Keeper,6100 是在 oy
机房的 Keeper
127.0.0.1:6000> info replication
# Replication
role:slave
keeperrole:keeper
state:ACTIVE
master_host:127.0.0.1
master_port:6379
master_link_status:up
slave_repl_offset:13103
slave_priority:0
connected_slaves:2
slave0:ip=127.0.0.1,port=6100,state=online,offset=13042,lag=0,remotePort=52591
slave1:ip=127.0.0.1,port=6001,state=online,offset=13103,lag=0,remotePort=52653
master_replid:28181f6e3b2a66d637fa480bd003c546ca0c3a50
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:13103
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_first_byte_offset:10613
master_repl_offset:13103
repl_backlog_size:2491
repl_backlog_histlen:2491
Keeper 6100 有三个 slave,6101 是在当前 oy
机房的 Backup keeper,6579 和 6679 对应备机房 Redis
127.0.0.1:6100> info replication
# Replication
role:slave
keeperrole:keeper
state:ACTIVE
master_host:127.0.0.1
master_port:6000
master_link_status:up
slave_repl_offset:16612
slave_priority:0
connected_slaves:3
slave0:ip=127.0.0.1,port=6679,state=online,offset=16612,lag=0,remotePort=52618
slave1:ip=127.0.0.1,port=6101,state=online,offset=16612,lag=0,remotePort=52613
slave2:ip=127.0.0.1,port=6579,state=online,offset=16612,lag=0,remotePort=52617
master_replid:28181f6e3b2a66d637fa480bd003c546ca0c3a50
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:16612
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_first_byte_offset:13803
master_repl_offset:16612
repl_backlog_size:2810
repl_backlog_histlen:2810
XPipe