The Codis is made up of four parts:
Codis Proxy (codis-proxy) proxy server to do the request forwarding, codis-proxy itself implementation of the Redis protocol, codis-proxy itself is stateless. You can perform multiple
Codis Dashboard (codis-config) Codis tool, including adding a delete node, and bringing a Dashboard, point to
Codis Redis (Codis-server) is based on 2.8.13-developed branch and can only use Codis-server
Zookeeper/etcd Codis relies on zookeeper to hold the metadata of the data routing table and Codis-proxy node, and the commands Codis-config initiate are synchronized to each surviving zookeeper via Codis-proxy.
Architecture (1). png
Codis support to differentiate different products according to Namespace, with different product name products, the configuration will not conflict
1,codis is written in the go language, so you need to install the Go Language pack
[Root@yum-down local]# wget https://storage.googleapis.com/golang/go1.6.linux-amd64.tar.gz
[Root@yum-down local]# TAR-ZXVF go1.6.linux-amd64.tar.gz
[Root@yum-down local]# cd/usr/local/go/src/
[Root@yum-down src]# Go version
Go version go1.6 linux/amd64
[Root@yum-down src]# mkdir/gopath/src/golang.org/x
[Root@yum-down src]# Go get GITHUB.COM/TOOLS/GODEP
[Root@yum-down src]# Vim/etc/profile
Export path= $PATH:/usr/local/go/bin
Export Goroot=/usr/local/go
Export path= $PATH:/gopath/bin
[Root@yum-down local]# Source/etc/profile
You can also install Yum:
[Root@yum-down local]# yum-y install gcc gcc-c++ make git wget go
[Root@yum-down codis]# cat/etc/profile.d/go.sh
Export Gopath=/gopath
Export path= $GOPATH/bin: $JAVA _home/bin: $PATH
2, install Java
[Root@yum-down local]# wget http://download.oracle.com/otn-pub/java/jdk/8u73-b02/jdk-8u73-linux-x64.rpm
[Root@yum-down local]# RPM-IVH jdk-8u73-linux-x64.rpm
Preparing ... ########################################### [100%]
1:jdk1.8.0_73 ########################################### [100%]
Unpacking JAR files ...
Tools.jar ...
Plugin.jar ...
Javaws.jar ...
Deploy.jar ...
Rt.jar ...
Jsse.jar ...
Charsets.jar ...
Localedata.jar ...
Jfxrt.jar ...
[Root@yum-down opt]# Cat/etc/profile.d/java
Export Java_home=/usr/java/latest
Export path= $JAVA _home/bin/: $PATH
Export path= $PATH:/gopath/bin
[Root@yum-down opt]#. /etc/profile.d/java
[Root@yum-down local]# Java-version
Java Version "1.8.0_73"
Java (TM) SE Runtime Environment (build 1.8.0_73-b02)
Java HotSpot (TM) 64-bit Server VM (build 25.73-b02, Mixed mode)
[Root@yum-down local]#
3,zookeeper Download Address
[Root@yum-down local]# wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
[Root@yum-down local]# Tar XF zookeeper-3.4.6.tar.gz
[Root@yum-down local]# ln-s zookeeper-3.4.6 Zookeeper
[Root@yum-down zookeeper]# Mkdir/opt/{zk1,zk2,zk3}
To copy a configuration file:
[Root@yum-down local]# Cp/usr/local/zookeeper/conf/zoo_sample.cfg/opt/zoo.cfg
Edit the configuration file and modify the DataDir. and add server (because it is a machine, the port cannot be the same), as follows:
Datadir=/opt/zk1
clientport=2181
server.1=10.10.0.250:2887:3887
server.2=10.10.0.250:2888:3888
server.3=10.10.0.250:2889:3889
Copy the configuration file to each directory:
[Root@yum-down local]# Cp/opt/zoo.cfg/opt/zk1/zk1.cfg
[Root@yum-down local]# Cp/opt/zoo.cfg/opt/zk2/zk2.cfg
[Root@yum-down local]# Cp/opt/zoo.cfg/opt/zk3/zk3.cfg
After the modification is done as follows:
[Root@yum-down local]# grep ' ^[a-z] '/opt/zk1/zk1.cfg
ticktime=2000 Heartbeat Time
initlimit=10 Heartbeat detection Interval number
Synclimit=5
Datadir=/opt/zk1
clientport=2181
server.1=10.10.0.250:2887:3887 cluster 1
server.2=10.10.0.250:2888:3888 Cluster 2
server.3=10.10.0.250:2889:3889 Cluster 3
Modified as follows:
[Root@yum-down local]# grep ' ^[a-z] '/opt/zk2/zk2.cfg
ticktime=2000
initlimit=10
Synclimit=5
Datadir=/opt/zk2
clientport=2182
server.1=10.10.0.250:2887:3887
server.2=10.10.0.250:2888:3888
server.3=10.10.0.250:2889:3889
[Root@yum-down local]# grep ' ^[a-z] '/opt/zk3/zk3.cfg
ticktime=2000
initlimit=10
Synclimit=5
Datadir=/opt/zk3
clientport=2183
server.1=10.10.0.250:2887:3887
server.2=10.10.0.250:2888:3888
server.3=10.10.0.250:2889:3889
[Root@yum-down local]#
4, running on a single machine, in three directories, and creating IDs
[Root@yum-down local]# cd/opt/
[Root@yum-down opt]# echo "1" > Zk1/myid
[Root@yum-down opt]# echo "2" > Zk2/myid
[Root@yum-down opt]# echo "3" > Zk3/myid
Zookeeper environment variable *********
[Root@yum-down opt]# echo-e "Export zookeeper=/usr/local/zookeeper \nexport path=\ $ZOOKEEPER/bin:\ $PATH" >>/etc /profile && Source/etc/profile
*****************************
Start three zookeeper
[Root@yum-down local]#/usr/local/zookeeper/bin/zkserver.sh start/opt/zk1/zk1.cfg
Zookeeper JMX enabled by Default
Using config:/opt/zk1/zk1.cfg
Starting zookeeper ... Started
[Root@yum-down local]#/usr/local/zookeeper/bin/zkserver.sh start/opt/zk2/zk2.cfg
Zookeeper JMX Enabled by default
Using config:/opt/zk2/zk2.cfg
Starting zookeeper ... Started
[Root@yum-down local]#/usr/local/zookeeper/bin/zkserver.sh start/opt/zk3/zk3.cfg
Zookeeper JMX Enabled by default
Using config:/opt/zk3/zk3.cfg
Starting zookeeper ... Started
[Root@yum-down local]#
To see if it has been automatically elected:
[Root@yum-down opt]#/usr/local/zookeeper/bin/zkserver.sh status/opt/zk3/zk3.cfg
JMX enabled by default
Using Config:/opt/zk3/zk3.cfg
Mode:follower followers
[Root@yum-down opt]#/usr/local/zookeeper/bin/zkserver.sh status/opt/zk2/zk2.cfg
JMX enabled by default
Using Config:/opt/zk2/zk2.cfg
Mode:leader leader
[Root@yum-down opt]#/usr/local/zookeeper/bin/zkserver.sh status/opt/zk1/zk1.cfg
JMX enabled by default
Using Config:/opt/zk1/zk1.cfg
Mode:follower followers
[Root@yum-down opt]#
Connection test:
[Root@yum-down opt]#/usr/local/zookeeper/bin/zkcli.sh-server 10.10.0.250:2181
[zk:10.10.0.250:2181 (CONNECTED) 0] LS/
[Zookeeper]
[Zk:10.10.0.250:2181 (CONNECTED) 1] Ls/zookeeper
[Quota]
[Zk:10.10.0.250:2181 (CONNECTED) 2]
Download Codis
[Root@yum-down ~]# Go get-u-D Github.com/codislabs/codis
Package Github.com/codislabs/codis:no buildable Go source files In/opt/gopath/src/github.com/codislabs/codis
[Root@yum-down local]# cd/gopath/src/github.com/codislabs/codis/
[Root@yum-down codis]# make
[Root@yum-down codis]# make Gotest
Codis-config, Codis-proxy, codis-server three executable files have been generated
[Root@yum-down bin]# ls
Assets Codis-config Codis-proxy Codis-server
To perform Bin/codis-config dashboard, you will see a page
Codis.png
[Root@yum-down codis]# Bin/codis-config Dashboard
2016/03/04 07:22:03 dashboard.go:160: [INFO] Dashboard listening on addr:: 18087
2016/03/04 07:22:03 dashboard.go:143: [INFO] Dashboard node created:/zk/codis/db_test/dashboard, {"Addr": " 10.10.0.250:18087 "," pid ": 33434}
2016/03/04 07:22:03 dashboard.go:144: [WARN] ********** Attention **********
2016/03/04 07:22:03 dashboard.go:145: [WARN] You should use ' Kill {pid} ' rather than ' kill-9 {pid} ' to stop me,
2016/03/04 07:22:03 dashboard.go:146: [WARN] or the node resisted on ZK'll not is cleaned when I ' m quiting and your must Remove it manually
2016/03/04 07:22:03 dashboard.go:147: [WARN] *******************************
2016/03/04 07:23:07 dashboard_apis.go:88: [ERROR] Get server groups failed
[ERROR]: Zk:node does not exist
1/gopath/src/github.com/codislabs/codis/pkg/models/server_group.go:110
Github.com/codislabs/codis/pkg/models.servergroups
0/gopath/src/github.com/codislabs/codis/cmd/cconfig/dashboard_apis.go:86
Main.apigetservergrouplist
... ...
[Stack]:
0/gopath/src/github.com/codislabs/codis/cmd/cconfig/dashboard_apis.go:88
Main.apigetservergrouplist
... ...
Start two Redis (make sure Redis is installed)
Create two Redis
[Root@yum-down opt]# mkdir date1
[Root@yum-down opt]# mkdir Date2
[Root@yum-down opt]# cp/etc/redis/6379.conf./
[Root@yum-down opt]# Vim 6379.conf
Change the port, PID, such as: 8001
[Root@yum-down opt]# grep "8001" 6379.conf
Pidfile/var/run/redis_8001.pid
# Accept connections on the specified port, default is 8001.
Port 8001
Dir/opt/date1
# Cluster-config-file Nodes-8001.conf
[Root@yum-down opt]# CP 6379.conf date1/8001.conf
8002
[Root@yum-down opt]# grep "8002" 6379.conf
Pidfile/var/run/redis_8002.pid
# Accept connections on the specified port, default is 8002.
Port 8002
Dir/opt/date2
# Cluster-config-file Nodes-8002.conf
[Root@yum-down opt]#
Start
[Root@yum-down opt]#/usr/local/redis/bin/redis-server/opt/date1/8001.conf
[Root@yum-down opt]#/usr/local/redis/bin/redis-server/opt/date2/8002.conf
[Root@yum-down opt]# PS aux|grep Redis
Root 36449 0.1 0.7 137448 7484? SSL 07:38 0:00/usr/local/redis/bin/redis-server *:6379
Root 36485 0.0 0.7 137448 7436? SSL 07:48 0:00/usr/local/redis/bin/redis-server *:8001
Root 36491 0.1 0.7 137448 7436? SSL 07:48 0:00/usr/local/redis/bin/redis-server *:8002
Manually add after startup
Cordis-crete-1.png
View after connection
[Root@yum-down opt]#/usr/local/redis/bin/redis-cli-h 10.10.0.250-p 8002
Role:slave
master_host:10.10.0.250
master_port:8001
Master_link_status:up
Master_last_io_seconds_ago:8
master_sync_in_progress:0
Slave_repl_offset:85
slave_priority:100
Slave_read_only:1
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
Manually submitted to the ascending master will be orphaned and the master and slave will disappear offline:
codis-Promotion master. png
10.10.0.250:8002>
# Replication
Role:master
connected_slaves:0
master_repl_offset:239
repl_backlog_active:0
repl_backlog_size:1048576
repl_backlog_first_byte_offset:0
repl_backlog_histlen:0
Unlike previous versions, codis3.0.1 scripts are placed under Codislabs/codis/bin:
[Root@yum-down bin]# ls
Assets Codis-config Codis-proxy Codis-server
[Root@yum-down bin]# LL
Total 37520
Drwxr-xr-x 4 root 4096 Mar 4 06:30 assets
-rwxr-xr-x 1 root 16141960 Mar 4 06:30 codis-config
-rwxr-xr-x 1 root 15961984 Mar 4 06:29 codis-proxy
-rwxr-xr-x 1 root 6311107 Mar 4 06:30 codis-server
[Root@yum-down bin]# pwd
/gopath/src/github.com/codislabs/codis/bin
Configuration file is still Config.ini
Coordinator=zookeeper
zk=10.10.0.250:2181
Product=test
dashboard_addr=10.10.0.250:18087
And he can add a slot range of services
Data migration:
Using the Gitlab author's words is: the smallest unit of data migration is key, we have added some instructions in Codis Redis, implementation based on key migration, such as SLOTSMGRT, etc. (command list), each will be specific slot a random key sent to another cod Is Redis instance, this command confirms that the other party has received, deletes the local k-v key value, returns the number of the slot's remaining key, the whole operation is atomic.
It supports dynamic migration of slot based on instance memory to balance data distribution.
He has many commands not supported: HTTPS://GITHUB.COM/CODISLABS/CODIS/BLOB/3.0.1/DOC/UNSUPPORTED_CMDS.MD
As for codis-proxy design to zookeeper, if not familiar with the zookeeper, there are many problems can not be solved
Initialize Slots
[Root@yum-down codis]# bin/codis-config slot Init
{
"MSG": "OK",
"ret": 0
}
[Root@yum-down codis]#
Set the slot scope of the server group service
Add group2
[Root@yum-down codis]# bin/codis-config Server add 2 10.10.0.250:6379 Master
{
"MSG": "OK",
"ret": 0
}
[Root@yum-down codis]# bin/codis-config server add 2 10.10.0.250:8001 slave
{
"MSG": "OK",
"ret": 0
}
Add Group3
[Root@yum-down codis]# bin/codis-config Server add 3 10.10.0.250:8001 Master
{
"MSG": "OK",
"ret": 0
}
[Root@yum-down codis]# bin/codis-config Server add 3 10.10.0.250:8002 slave
{
"MSG": "OK",
"ret": 0
}
Set the slot range for server group servers
[Root@yum-down codis]# Bin/codis-config slot range-set 0 511 1 Online
{
"MSG": "OK",
"ret": 0
}
[Root@yum-down codis]# bin/codis-config slot Range-set 2 online
{
"MSG": "OK",
"ret": 0
}
codis-three. png
Start Codis-proxy
[Root@yum-down codis]# bin/codis-proxy-c config.ini-l./log/proxy.log--cpu=8--addr=0.0.0.0:19000--http-addr= 0.0.0.0:11000
_____ ____ ____/ / (_) _____
/ ___/ / __ \ / __ / / / / ___/
/ /__ / /_/ / / /_/ / / / (__ )
\___/ \____/ \__,_/ /_/ /____/
[Root@yum-down codis]#
Data migration:
[Root@yum-down codis]# Bin/codis-config slot migrate 0 511 2--delay=10
{
"MSG": "OK",
"ret": 0
}
[Root@yum-down codis]#
Codis so far, understand!