博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
redis集群配置
阅读量:5275 次
发布时间:2019-06-14

本文共 19973 字,大约阅读时间需要 66 分钟。

客户端分片 程序端实现

代理proxy,访问proxy,proxy指定redis保存位置。 Twemproxy

Redis cluster ,会造成一部分数据丢失,无中心化

1.将数据自动切分(split)到多个节点的能力
2.当集群中的一部分节点失效或者无法进行通信时,仍然可以继续处理命令请求的能力。

codis redis集群解决方案。豌豆荚开源

 

redis cluster 集群配置

cd /data/

mkdir `seq 7001 7008`

redis.conf 添加,端口需要变化

'''
port 7000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes

'''

安装ruby
yum -y install ruby rubygems

安装ruby的redis管理工具

gem install redis

1 gem installed

Installing ri documentation for redis-3.3.0...
Installing RDoc documentation for redis-3.3.0...

创建集群

redis-trib.rb create --replicas 1 172.16.230.167:7001 172.16.230.167:7002 172.16.230.167:7003 172.16.230.167:7004 172.16.230.167:7005
172.16.230.167:7006

客户端连接:

redis-cli -c -h 172.16.230.167 -p 7001

set name 111
set name1 222
会写入到不通哈希槽

cluster nodes

cluster info

添加集群节点:命令中的 add-node 表示我们要让 redis-trib 将一个节点添加到集群里面, add-node 之后跟着的是新节点的 IP 地址和端口号, 再

之后跟着的是集群中任意一个已存在节点的 IP 地址和端口号

[root@slave1 data]# redis-trib.rb add-node 172.16.230.167:7007 172.16.230.167:7001

>>> Adding node 172.16.230.167:7007 to cluster 172.16.230.167:7001
>>> Performing Cluster Check (using node 172.16.230.167:7001)
M: f2a684e0900e7b7eb91bdb77e3b559f47d0f7237 172.16.230.167:7001
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: 37b6f6478ca6425022521d6a5ecf0aeedf12c601 172.16.230.167:7005
slots: (0 slots) slave
replicates 84995c68e3625c91f4c646d71566dffd709e6d01
S: d6d307c91e6ba6fbba7d898f20fd4772a3e42b9c 172.16.230.167:7004
slots: (0 slots) slave
replicates f2a684e0900e7b7eb91bdb77e3b559f47d0f7237
S: 458a01eeace9fd93544645433ad5b12587d94d3b 172.16.230.167:7006
slots: (0 slots) slave
replicates ffe722398240b59f0c993074d35dbe79386c1ec3
M: ffe722398240b59f0c993074d35dbe79386c1ec3 172.16.230.167:7003
slots:10923-16383 (5461 slots) master
1 additional replica(s)
M: 84995c68e3625c91f4c646d71566dffd709e6d01 172.16.230.167:7002
slots:5461-10922 (5462 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 172.16.230.167:7007 to make it join the cluster.
[OK] New node added correctly.

查询新节点

172.16.230.167:7001> cluster nodes

37b6f6478ca6425022521d6a5ecf0aeedf12c601 172.16.230.167:7005 slave 84995c68e3625c91f4c646d71566dffd709e6d01 0 1467381076060 5

connected
d6d307c91e6ba6fbba7d898f20fd4772a3e42b9c 172.16.230.167:7004 slave f2a684e0900e7b7eb91bdb77e3b559f47d0f7237 0 1467381077061 4
connected
458a01eeace9fd93544645433ad5b12587d94d3b 172.16.230.167:7006 slave ffe722398240b59f0c993074d35dbe79386c1ec3 0 1467381073056 6
connected
ffe722398240b59f0c993074d35dbe79386c1ec3 172.16.230.167:7003 master - 0 1467381074057 3 connected 10923-16383

83e5dd37a0825a4adb77d6da4738bf0c88cd6c39 172.16.230.167:7007 master - 0 1467381075059 0 connected

84995c68e3625c91f4c646d71566dffd709e6d01 172.16.230.167:7002 master - 0 1467381073556 2 connected 5461-10922

f2a684e0900e7b7eb91bdb77e3b559f47d0f7237 172.16.230.167:7001 myself,master - 0 0 1 connected 0-5460

将一个新节点转变为从节点的方法,把7008加入到集群中
[root@slave1 data]# redis-trib.rb add-node 172.16.230.167:7008 172.16.230.167:7001

进入到新加入集群的终端中

[root@slave1 data]# redis-cli -c -h 172.16.230.167 -p 7008

172.16.230.167:7008> CLUSTER nodes

84995c68e3625c91f4c646d71566dffd709e6d01 172.16.230.167:7002 master - 0 1467381351640 2 connected 5461-10922
37b6f6478ca6425022521d6a5ecf0aeedf12c601 172.16.230.167:7005 slave 84995c68e3625c91f4c646d71566dffd709e6d01 0 1467381350638 2
connected
f2a684e0900e7b7eb91bdb77e3b559f47d0f7237 172.16.230.167:7001 master - 0 1467381352142 1 connected 0-5460
83e5dd37a0825a4adb77d6da4738bf0c88cd6c39 172.16.230.167:7007 master - 0 1467381352641 0 connected
458a01eeace9fd93544645433ad5b12587d94d3b 172.16.230.167:7006 slave ffe722398240b59f0c993074d35dbe79386c1ec3 0 1467381349636 3
connected
ffe722398240b59f0c993074d35dbe79386c1ec3 172.16.230.167:7003 master - 0 1467381348635 3 connected 10923-16383
d6d307c91e6ba6fbba7d898f20fd4772a3e42b9c 172.16.230.167:7004 slave f2a684e0900e7b7eb91bdb77e3b559f47d0f7237 0 1467381348135 1
connected
6b52de99a37444a2f7cb04a65ed4239446dee048 172.16.230.167:7008 myself,master - 0 0 7 connected

172.16.230.167:7008> CLUSTER REPLICATE 83e5dd37a0825a4adb77d6da4738bf0c88cd6c39

其中命令提供的 83e5dd37a0825a4adb77d6da4738bf0c88cd6c39 就是主节点 172.16.230.167:7007 的节点 ID

172.16.230.167:7008> CLUSTER nodes

84995c68e3625c91f4c646d71566dffd709e6d01 172.16.230.167:7002 master - 0 1467381552990 2 connected 5461-10922
37b6f6478ca6425022521d6a5ecf0aeedf12c601 172.16.230.167:7005 slave 84995c68e3625c91f4c646d71566dffd709e6d01 0 1467381554995 2
connected
f2a684e0900e7b7eb91bdb77e3b559f47d0f7237 172.16.230.167:7001 master - 0 1467381553992 1 connected 0-5460
83e5dd37a0825a4adb77d6da4738bf0c88cd6c39 172.16.230.167:7007 master - 0 1467381555997 0 connected
458a01eeace9fd93544645433ad5b12587d94d3b 172.16.230.167:7006 slave ffe722398240b59f0c993074d35dbe79386c1ec3 0 1467381550487 3
connected
ffe722398240b59f0c993074d35dbe79386c1ec3 172.16.230.167:7003 master - 0 1467381550988 3 connected 10923-16383
d6d307c91e6ba6fbba7d898f20fd4772a3e42b9c 172.16.230.167:7004 slave f2a684e0900e7b7eb91bdb77e3b559f47d0f7237 0 1467381549986 1
connected
6b52de99a37444a2f7cb04a65ed4239446dee048 172.16.230.167:7008 myself,slave 83e5dd37a0825a4adb77d6da4738bf0c88cd6c39 0 0 7 connected

对集群进行重新分片:主要对172.16.230.167:7007 集群节点做重新分片

[root@slave1 ~]# redis-trib.rb reshard 172.16.230.167:7007

>>> Performing Cluster Check (using node 172.16.230.167:7007)

M: 83e5dd37a0825a4adb77d6da4738bf0c88cd6c39 172.16.230.167:7007
slots: (0 slots) master
1 additional replica(s)
S: d6d307c91e6ba6fbba7d898f20fd4772a3e42b9c 172.16.230.167:7004
slots: (0 slots) slave
replicates f2a684e0900e7b7eb91bdb77e3b559f47d0f7237
S: 6b52de99a37444a2f7cb04a65ed4239446dee048 172.16.230.167:7008
slots: (0 slots) slave
replicates 83e5dd37a0825a4adb77d6da4738bf0c88cd6c39
M: 84995c68e3625c91f4c646d71566dffd709e6d01 172.16.230.167:7002
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: 37b6f6478ca6425022521d6a5ecf0aeedf12c601 172.16.230.167:7005
slots: (0 slots) slave
replicates 84995c68e3625c91f4c646d71566dffd709e6d01
M: f2a684e0900e7b7eb91bdb77e3b559f47d0f7237 172.16.230.167:7001
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: 458a01eeace9fd93544645433ad5b12587d94d3b 172.16.230.167:7006
slots: (0 slots) slave
replicates ffe722398240b59f0c993074d35dbe79386c1ec3
M: ffe722398240b59f0c993074d35dbe79386c1ec3 172.16.230.167:7003
slots:10923-16383 (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
How many slots do you want to move (from 1 to 16384)? 1000 #######分片大小
What is the receiving node ID? 83e5dd37a0825a4adb77d6da4738bf0c88cd6c39 #分配到那个集群节点的master上172.16.230.167:7007
Please enter all the source node IDs.
Type 'all' to use all the nodes as source nodes for the hash slots.
Type 'done' once you entered all the source nodes IDs.
Source node #1:all #所有

Do you want to proceed with the proposed reshard plan (yes/no)?yes

 

使用 consistency-test.rb检测数据一致性

下载
git clone https://github.com/antirez/redis-rb-cluster.git

[root@slave1 redis-rb-cluster]# ruby consistency-test.rb 172.16.230.167 7001

316 R (0 err) | 316 W (0 err) |
1453 R (0 err) | 1453 W (0 err) |
2708 R (0 err) | 2708 W (0 err) |
4010 R (0 err) | 4010 W (0 err) |
5309 R (0 err) | 5309 W (0 err) |
6613 R (0 err) | 6613 W (0 err) |
7915 R (0 err) | 7915 W (0 err) |
9214 R (0 err) | 9214 W (0 err) |
10517 R (0 err) | 10517 W (0 err) |
11817 R (0 err) | 11817 W (0 err) |
13121 R (0 err) | 13121 W (0 err) |
14422 R (0 err) | 14422 W (0 err) |
15724 R (0 err) | 15724 W (0 err) |
17012 R (0 err) | 17012 W (0 err) |
18312 R (0 err) | 18312 W (0 err) |
19628 R (0 err) | 19628 W (0 err) |
20949 R (0 err) | 20949 W (0 err) |
22255 R (0 err) | 22255 W (0 err) |
23294 R (0 err) | 23294 W (0 err) |
24542 R (0 err) | 24542 W (0 err) |
25852 R (0 err) | 25852 W (0 err) |

故障转移测试

查看主节点:

[root@slave1 ~]# redis-cli -c -h 172.16.230.167 -p 7001 cluster nodes | grep master
ffe722398240b59f0c993074d35dbe79386c1ec3 172.16.230.167:7003 master - 0 1467383421007 3 connected 11256-16383
83e5dd37a0825a4adb77d6da4738bf0c88cd6c39 172.16.230.167:7007 master - 0 1467383423010 8 connected 0-332 5461-5794 10923-11255
84995c68e3625c91f4c646d71566dffd709e6d01 172.16.230.167:7002 master - 0 1467383426014 2 connected 5795-10922
f2a684e0900e7b7eb91bdb77e3b559f47d0f7237 172.16.230.167:7001 myself,master - 0 0 1 connected 333-5460

使用debug segfault 让主节点崩溃

redis-cli -c -h 172.16.230.167 -p 7001 debug segfault

 

[root@slave1 ~]# redis-cli -c -h 172.16.230.167 -p 7002 cluster nodes | grep master

84995c68e3625c91f4c646d71566dffd709e6d01 172.16.230.167:7002 myself,master - 0 0 2 connected 5795-10922
d6d307c91e6ba6fbba7d898f20fd4772a3e42b9c 172.16.230.167:7004 master - 0 1467383553156 9 connected 333-5460
83e5dd37a0825a4adb77d6da4738bf0c88cd6c39 172.16.230.167:7007 master - 0 1467383556161 8 connected 0-332 5461-5794 10923-11255
ffe722398240b59f0c993074d35dbe79386c1ec3 172.16.230.167:7003 master - 0 1467383553657 3 connected 11256-16383
f2a684e0900e7b7eb91bdb77e3b559f47d0f7237 172.16.230.167:7001 master,fail - 1467383513361 1467383506054 1 disconnected

 

集群管理

yum -y install httpd php php-redis

git clone https://github.com/erikdubbelboer/phpRedisAdmin.git

cd phpRedisAdmin
git clone https://github.com/nrk/predis.git vendor

 

 

 

###################################

Codis 集群

Codis 由四部分组成:

Codis Proxy (codis-proxy)

Codis Dashboard (codis-config)
Codis Redis (codis-server)
ZooKeeper/Etcd

 

安装go
wget http://dinp.qiniudn.com/go1.7.0.linux-amd64.tar.gz
tar -zxvf go1.4.1.linux-amd64.tar.gz
mv go /usr/local/
vim /etc/profile
source /etc/profile
go version
mkdir -p $GOPATH/src/github.com/tools
go get -u github.com/tools/godep

go get github.com/golang/tools
cd /data/gopath/github.com/golang/
cp -ar tools /usr/local/go/src/golang.org/x/

go install ./

which godep
vim /etc/profile
source /etc/profile
go get -u -d github.com/CodisLabs/codis
cd CodisLabs/codis/
make
make gotest

环境变量:

export GOROOT=/usr/local/go
export GOPATH=/data/gopath
export ZOOKEEPER_HOME=/data/zookeeper
export PATH=$GOROOT/bin:$PATH
export PATH=$GOROOT/bin:$GOPATH/bin:$PATH

执行全部指令后,会在 bin 文件夹内生成 codis-config、codis-proxy、codis-server三个可执行文件。另外, bin/assets 文件夹是 codis-config

的 dashboard http 服务需要的前端资源, 需要和 codis-config 放置在同一文件夹下)
[root@slave1 bin]# ls
assets codis-config codis-proxy codis-server

编辑codis config.ini配置文件

coordinator=zookeeper

zk=172.16.230.167:2181
product=cinyi
dashboard_addr=172.16.230.167:18087
password=
backend_ping_period=5
session_max_timeout=1800
session_max_bufsize=131072
session_max_pipeline=1024
zk_session_timeout=30000
proxy_id=cinyicodis-poryx_1

配置和启动各组件

1.启动 dashboard(两台机,只需启动一台机上的dashboard)
cd /apps/svr/src/github.com/CodisLabs/codis
执行./bin/codis-config dashboard &, 该命令会启动 dashboard
以下是启动信息:
[1] 6243
[root@slave1 codis]# 2016/07/04 22:05:43 dashboard.go:160: [INFO] dashboard listening on addr: :18087
2016/07/04 22:05:43 dashboard.go:143: [INFO] dashboard node created: /zk/codis/db_cinyi/dashboard, {"addr": "172.16.230.167:18087",
"pid": 6243}
2016/07/04 22:05:43 dashboard.go:144: [WARN] ********** Attention **********
2016/07/04 22:05:43 dashboard.go:145: [WARN] You should use `kill {pid}` rather than `kill -9 {pid}` to stop me,
2016/07/04 22:05:43 dashboard.go:146: [WARN] or the node resisted on zk will not be cleaned when I'm quiting and you must remove it
manually
2016/07/04 22:05:43 dashboard.go:147: [WARN] *******************************

从上面信息可看到:

a.关闭dashboard的操作要用kil pid,不要用kill -9 pid
b.若关闭异常,下次启动时,会报错提示zk已有建立,此时需要删除 :/zk/codis/db_gls/dashboard,参考最后问题处理。
访问管理页面:http://172.16.230.167:18087,可以进行server group的增删操作、slot操作等。

初始化 slots

cd /data/gopath/src/github.com/CodisLabs/codis/bin
执行 ./codis-config -c ../config.ini slot init,该命令会在zookeeper上创建slot相关信息

配置和启动 Codis 的Redis(除配置文件scp外,其它两台机上都要操作)

cp /data/gopath/src/github.com/CodisLabs/codis/extern/redis-2.8.21 /data/redis2.8 -ar

cd /data/redis2.8/

make install

mkdir /data/{9001,9002,9003,9004}

###################################

[root@slave1 9004]# cat 9004.conf | grep -v "#" | sed '/^$/d'
daemonize yes
pidfile /var/run/redis_9004.pid
port 9004
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile "/var/log/redis_9004.log"
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename 9004_dump.rdb
dir /data/9004/
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
appendonly no
appendfilename "9004_appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes

 

###########################################

启动

/data/redis2.8/src/redis-server /data/9001/9001.conf
/data/redis2.8/src/redis-server /data/9002/9002.conf
/data/redis2.8/src/redis-server /data/9003/9003.conf
/data/redis2.8/src/redis-server /data/9004/9004.conf

添加 Redis Server Group(只在一台上操作,也可以在面板图形界面操作)
cd $CODIS_HOME/bin
./codis-config -c ../config.ini server add 1 172.16.230.167:9001 master
./codis-config -c ../config.ini server add 1 172.16.230.167:9003 slave
./codis-config -c ../config.ini server add 2 172.16.230.167:9003 master
./codis-config -c ../config.ini server add 2 172.16.230.167:9004 slave

查看

[root@slave1 bin]# ./codis-config -c ../config.ini server list

[
{
"id": 1,
"product_name": "cinyi",
"servers": [
{
"addr": "172.16.230.167:9001",
"group_id": 1,
"type": "master"
},
{
"addr": "172.16.230.167:9002",
"group_id": 1,
"type": "slave"
}
]
},
{
"id": 2,
"product_name": "cinyi",
"servers": [
{
"addr": "172.16.230.167:9003",
"group_id": 2,
"type": "master"
},
{
"addr": "172.16.230.167:9004",
"group_id": 2,
"type": "slave"
}
]
}
]

设置 server group 服务的 slot 范围(只在一台执行)

Codis 采用 Pre-sharding 的技术来实现数据的分片, 默认分成 1024 个 slots (0-1023), 对于每个key来说, 通过以下公式确定所属的 Slot Id :

SlotId = crc32(key) % 1024 每一个
slot 都会有一个且必须有一个特定的 server group id 来表示这个 slot 的数据由哪个 server group 来提供.
cd $CODIS_HOME
codis-config slot range-set <slot_from> <slot_to> <group_id> <status>
./codis-config -c ../config.ini slot range-set 0 511 1 online
./codis-config -c ../config.ini slot range-set 512 1023 2 online

 

启动 codis-proxy

节点一:
cd $CODIS_HOME

./codis-proxy -c ./config.ini -L /var/log/proxy.log --cpu=2 --addr=0.0.0.0:19000 --http-addr=0.0.0.0:11000 &

节点二:

cd $CODIS_HOME

./codis-proxy -c ./config.ini -L /var/log/proxy.log --cpu=2 --addr=0.0.0.0:19000 --http-addr=0.0.0.0:11000 &

刚启动的 codis-proxy 默认是处于 offline状态的, 然后设置 proxy 为 online 状态, 只有处于 online 状态的 proxy 才会对外提供服务(codis

3..0.3之前版本需要online操作)

节点一:

./codis-config -c ../config.ini proxy online cinyicodis-poryx_1

节点二:

./codis-config -c ../config.ini proxy online cinyicodis-poryx_2

 

五.遇到的问题

[root@mvxl2530 codis]# bin/codis-config dashboard &
[1] 14429
2016/05/11 17:45:30 dashboard.go:160: [INFO] dashboard listening on addr: :18087
[root@mvxl2530 codis]# 2016/05/11 17:45:30 dashboard.go:234: [PANIC] create zk node failed
[error]: dashboard already exists: {"addr": "172.16.230.167:18087", "pid": 13819}
[stack]:
3 /apps/svr/src/github.com/CodisLabs/codis/cmd/cconfig/dashboard.go:234
main.runDashboard
2 /apps/svr/src/github.com/CodisLabs/codis/cmd/cconfig/dashboard.go:54
main.cmdDashboard
1 /apps/svr/src/github.com/CodisLabs/codis/cmd/cconfig/main.go:85
main.runCommand
0 /apps/svr/src/github.com/CodisLabs/codis/cmd/cconfig/main.go:152
main.main
... ...
[1]+ Exit 1 bin/codis-config dashboard
原因:由于在停dashboard时,采用kill -9强杀进程方法引起,应采用kill pid方法来关闭dashboard.
临时处理:
[root@mvxl2530 zookeeper]# cd /usr/local/zookeeper
[root@mvxl2530 zookeeper]# ./bin/zkCli.sh -server 127.0.0.1:2181
[zk: 127.0.0.1:2181(CONNECTED) 1]
[zk: 127.0.0.1:2181(CONNECTED) 6] ls /zk/codis/db_zh_news/dashboard --其中zh_news为codis配置文件中的product
[fence, servers, slots, proxy, migrate_tasks, dashboard, LOCK, actions, ActionResponse]
[migrate_tasks, dashboard, actions, slots, ActionResponse]
[zk: 127.0.0.1:2181(CONNECTED) 2] rmr /zk/codis/db_zh_news/dashboard
[zk: 127.0.0.1:2181(CONNECTED) 3]

六.相关命令和参数用法:
1.codis-config使用
[root@mvxl2530 bin]# ./codis-config -h
usage: codis-config [-c <config_file>] [-L <log_file>] [--log-level=<loglevel>]
<command> [<args>...]
options:
-c set config file
-L set output log file, default is stdout
--log-level=<loglevel> set log level: info, warn, error, debug [default: info]
commands:
server
slot
dashboard
action
proxy
[root@mvxl2530 bin]# ./codis-proxy -h
2.codis proxy使用
usage: proxy [-c <config_file>] [-L <log_file>] [--log-level=<loglevel>] [--log-filesize=<filesize>] [--cpu=<cpu_num>] [--
addr=<proxy_listen_addr>] [--http-
addr=<debug_http_server_addr>]
options:
-c set config file
-L set output log file, default is stdout
--log-level=<loglevel> set log level: info, warn, error, debug [default: info]
--log-filesize=<maxsize> set max log file size, suffixes "KB", "MB", "GB" are allowed, 1KB=1024 bytes, etc. Default is 1GB.
--cpu=<cpu_num> num of cpu cores that proxy can use
--addr=<proxy_listen_addr> proxy listen address, example: 0.0.0.0:9000
--http-addr=<debug_http_server_addr> debug vars http server
3.codis-config用于增删server组
每一个 Server Group 作为一个 Redis 服务器组存在, 只允许有一个 master, 可以有多个 slave, group id 仅支持大于等于1的整数。
命令说明:
$ bin/codis-config server -h
usage:
codis-config server list
codis-config server add <group_id> <redis_addr> <role>
codis-config server remove <group_id> <redis_addr>
codis-config server promote <group_id> <redis_addr>
codis-config server add-group <group_id>
codis-config server remove-group <group_id>
如: 添加两个 server group, 每个 group 有两个 redis 实例,group的id分别为1和2, redis实例为一主一从。
添加一个group,group的id为1, 并添加一个redis master到该group

类似的,再添加group,group的id为3
$ bin/codis-config server add 3 localhost:6479 master
$ bin/codis-config server add 3 localhost:6480 slave

 

数据迁移,slot 从1000到1023 迁移到group3中

bin/codis-config slot migrate 1000 1023 3 --delay=10

Auto Rebalance

Codis 支持动态的根据实例内存, 自动对slot进行迁移, 以均衡数据分布.

$ bin/codis-config slot rebalance

 

若需要移除,参考如下:
./bin/codis-config -c ./config.ini server remove 1 172.16.230.167:9002
./bin/codis-config -c ./config.ini server remove 2 172.16.230.167:9004
./bin/codis-config -c ./config.ini server remove-group 1
./bin/codis-config -c ./config.ini server remove-group 2
redis-benchmark -h codis1 -p 19000 -n 1000000 -c 300 -r 1048576 -d 256 -t lpush ---压测

4.codis-config用于slot操作

命令说明:
$ bin/codis-config slot -h
usage:
codis-config slot init
codis-config slot info <slot_id>
codis-config slot set <slot_id> <group_id> <status>
codis-config slot range-set <slot_from> <slot_to> <group_id> <status>
codis-config slot migrate <slot_from> <slot_to> <group_id> [--delay=<delay_time_in_ms>]

数据迁移,slot 从1000到1023 迁移到group3中

bin/codis-config slot migrate 1000 1023 3 --delay=10

Auto Rebalance

Codis 支持动态的根据实例内存, 自动对slot进行迁移, 以均衡数据分布.

$ bin/codis-config slot rebalance

 

 

5.移除分片流程

---假设将分片3移除---
1. 设置codis-proxy为offline状态.
./bin/codis-config -c codis-config.ini proxy offline proxy_1

2. 迁移分片3上的数据到分片1
./bin/codis-config -c codis-config.ini slot migrate 256 511 1

3. 彻底移除分片3
./bin/codis-config -c codis-config.ini server remove-group 3

6.zk的查看操作
查看slot:
ls /zk/codis/db_gls/slots
proxy:
ls /zk/codis/db_gls/proxy
server:
ls /zk/codis/db_gls/servers
dashboard:
ls /zk/codis/db_gls/dashboard
查看迁移任务:
ls /zk/codis/db_gls/migrate_tasks

 

转载于:https://www.cnblogs.com/fengjian2016/p/5633971.html

你可能感兴趣的文章
国外常见互联网盈利创新模式
查看>>
android:scaleType属性
查看>>
shell脚本
查看>>
Upload Image to .NET Core 2.1 API
查看>>
【雷电】源代码分析(二)-- 进入游戏攻击
查看>>
Linux中防火墙centos
查看>>
如何设置映射网络驱动器的具体步骤和方法
查看>>
centos下同时启动多个tomcat
查看>>
Leetcode Balanced Binary Tree
查看>>
[JS]递归对象或数组
查看>>
linux sed命令
查看>>
湖南多校对抗赛(2015.03.28) H SG Value
查看>>
hdu1255扫描线计算覆盖两次面积
查看>>
hdu1565 用搜索代替枚举找可能状态或者轮廓线解(较优),参考poj2411
查看>>
程序存储问题
查看>>
优雅地书写回调——Promise
查看>>
AX 2009 Grid控件下多选行
查看>>
PHP的配置
查看>>
Struts框架----进度1
查看>>
Round B APAC Test 2017
查看>>