|
2 | 2 |
|
3 | 3 | Codes is a distributed Redis solution, there is no obvious difference between connecting to a Codis proxy and an original Redis server(?), top layer application can connect to Codis as normal standalone Redis, Codis will forward low layer requests. Hot data migration and all things in the shadow are transparent to client. Simply treat Coids as a Redis service with unlimited RAM. |
4 | 4 |
|
5 | | -Codis has four parts: |
6 | | -* Codis Proxy(proxy) |
7 | | -* Codis manager(cconfig) |
8 | | -* Codis Redis |
9 | | -* ZooKeeper |
10 | 5 |
|
11 | | -`codis-proxy` is the proxy service of client connections, `codis-proxy` is a Redis protocol implementation, perform as an original Redis(just like Twemproxy). You can deploy multiple `codis-proxy` for one business, `codis-proxy` is none-stateful. |
| 6 | +Codis 3.x consists of the following components: |
12 | 7 |
|
13 | | -`codis-config` is the configuration to for Codis, support actions like add/remove Redis node, add/remove Proxy node and start data migaration, etc. `codis-config` has a built-in http server which can start a dashboard for user to monitor the status of Codis cluster in browser. |
| 8 | +* ** Codis Server **: based on redis-3.2.8 branch development. Added additional data structures to support slot-related operations and data migration instructions. Specific changes can refer to the document [redis changes] (redis_change_zh.md). |
14 | 9 |
|
15 | | -`codis-server` is a branch of Redis maintain by Codis project, based on 2.8.13, add support for slot and atomic data migration. `codis-proxy` and `codis-config` can only work properly with this specific version of Redis. |
| 10 | +* ** Codis Proxy **: is the proxy service of client connections. Codis Proxy Implements Redis Protocol. In addition to some commands do not support ([unsupported command list] (unsupported_cmds.md)). |
16 | 11 |
|
17 | | -Codis depend on ZooKeeper to store data routing table and meta data of `codis-proxy` node, `codis-config` actions will go through ZooKeeper, then synchronize up to alive `codis-proxy`. |
| 12 | + + For the same product cluster, you can deploy multiple codis-proxy instances at the same time; |
| 13 | + + Different codis-proxy by codis-dashboard to ensure state synchronization. |
18 | 14 |
|
19 | | -Codis support namespace, configs of products with different name won’t be conflict. |
| 15 | +* ** Codis Dashboard **: cluster management tools, support codis-proxy, codis-server add, delete, slot migrate(sync/async), and other operations. When a cluster state changes, the codis-dashboard maintains the consistency of all codis-proxy states under the cluster. |
20 | 16 |
|
21 | | -## Build codis-proxy & codis-config |
| 17 | + + For the same product cluster, the same time codis-dashboard can only have 0 or 1; |
| 18 | + + All changes to the cluster must be done via codis-dashboard. |
22 | 19 |
|
| 20 | +* ** Codis Admin **: Command-line tool for cluster management. |
23 | 21 |
|
24 | | -* install go [see official doc](https://golang.org/doc/install) |
25 | | -* set $GOPATH correctly and set PATH=$GOPATH/bin:$PATH to execute commands installed by `go get` |
26 | | -* execute `go get -u -d github.com/CodisLabs/codis` to download codis |
27 | | -* change directory to `$GOPATH/src/github.com/CodisLabs/codis` and execute `make` to compile, execute `make gotest` to run unit test |
| 22 | + + Can be used to control the codis-proxy, codis-dashboard status, and access external storage. |
28 | 23 |
|
29 | | -Two executable file `codas-config` and `codis-proxy` should be generated in `codis/bin`(`bin/assets` is the resources for `codis-config` dashboard, should be placed at same directory with `codis-config`). |
| 24 | +* ** Codis FE **: cluster management Web Interface. |
30 | 25 |
|
31 | | -``` |
32 | | -cd sample |
| 26 | + + Multiple cluster instances can share the same front-end display page; |
| 27 | + + FE reads all cluster instances name from external storage. |
33 | 28 |
|
34 | | -$ bin/codis-config -h (master) |
35 | | -usage: codis-config [-c <config_file>] [-L <log_file>] [--log-level=<loglevel>] |
36 | | - <command> [<args>...] |
37 | | -options: |
38 | | - -c config file path, default: ./config.ini |
39 | | - -L log output path, default: stdout |
40 | | - --log-level=<loglevel> (debug < info (default) < warn < error < fatal) |
| 29 | +* ** Storage **: Provides external storage for cluster status, and saves cluster metadata. |
41 | 30 |
|
42 | | -commands: |
43 | | - server redis group management |
44 | | - slot slot management |
45 | | - dashboard start dashboard |
46 | | - action action management |
47 | | - proxy proxy management |
48 | | -``` |
| 31 | + + Provide the concept of Namespace, different clusters will be organized according to different product name; |
| 32 | + + Currently only provides Zookeeper, Etcd, Fs three implementations, but provides an abstract interface can be self-expansion. |
49 | 33 |
|
50 | | -``` |
51 | | -$ bin/codis-proxy -h |
52 | 34 |
|
53 | | -usage: proxy [-c <config_file>] [-L <log_file>] [--log-level=<loglevel>] [--cpu=<cpu_num>] [--addr=<proxy_listen_addr>] [--http-addr=<debug_http_server_addr>] |
| 35 | +## Getting Codis |
54 | 36 |
|
55 | | -options: |
56 | | - -c set config file |
57 | | - -L set output log file, default is stdout |
58 | | - --log-level=<loglevel> set log level: info, warn, error, debug [default: info] |
59 | | - --cpu=<cpu_num> num of cpu cores that proxy can use |
60 | | - --addr=<proxy_listen_addr> proxy listen address, example: 0.0.0.0:9000 |
61 | | - --http-addr=<debug_http_server_addr> debug vars http server |
62 | | -``` |
| 37 | +### Download Pre-built Release Binaries |
63 | 38 |
|
64 | | -## Deploy |
| 39 | +The easiest way to get codis is to use one of the pre-built release binaries which are available for OSX, Linux. Instructions for using these binaries are on the [GitHub releases page][github-release]. |
65 | 40 |
|
66 | | -### Configuration file |
67 | | -`codis-config` and `codis-proxy` will take `config.ini` in current directory by default without a specific `-c`. |
| 41 | +### Compile Source Code |
68 | 42 |
|
69 | | -See [config.ini](https://github.com/CodisLabs/codis/blob/master/config.ini)'s comments. |
| 43 | +For those wanting to try the very latest version, build the latest version of codis from the `master` branch. This first needs [*Go*](https://golang.org/) installed (version 1.7+ is required). All development occurs on `master`, including new features and bug fixes. Bug fixes are first targeted at `master` and subsequently ported to release branches. |
70 | 44 |
|
71 | | -### Workflow |
72 | | -0. Execute `codis-config dashboard` , start dashboard. |
73 | | -1. Execute `codis-config slot init` to initialize slots |
74 | | -2. Starting and compiling a Codis Redis has no difference from a normal Redis Server |
75 | | -3. Add Redis server group, each server group as a Redis server group, only one master is allowed while could have multiple slaves. Group id only support integer lager than 1. |
76 | 45 |
|
77 | | -``` |
78 | | -$ bin/codis-config server -h |
79 | | -usage: |
80 | | - codis-config server list |
81 | | - codis-config server add <group_id> <redis_addr> <role> |
82 | | - codis-config server remove <group_id> <redis_addr> |
83 | | - codis-config server promote <group_id> <redis_addr> |
84 | | - codis-config server add-group <group_id> |
85 | | - codis-config server remove-group <group_id> |
| 46 | +#### 1. Install Go Environment [reference](https://golang.org/doc/install) |
| 47 | + |
| 48 | +After the installation is complete, you can run the following command to detect: |
| 49 | + |
| 50 | +```bash |
| 51 | +$ go version |
| 52 | +go version go1.7.3 linux/amd64 |
86 | 53 | ``` |
87 | 54 |
|
88 | | -For example: Add two server group with the ids of 1 and 2, each has two Redis instances, a master and a slave. |
| 55 | +#### 2. Set the compilation environment |
89 | 56 |
|
90 | | -First, add a group with id of 1 and assign a Redis master to it: |
| 57 | +Add `$GOPATH/bin` To `$PATH`,For Example:`PATH=$PATH:$GOPATH/bin`。 |
91 | 58 |
|
92 | | -``` |
93 | | -$ bin/codis-config server add 1 localhost:6379 master |
| 59 | +```bash |
| 60 | +$ go env GOPATH |
| 61 | +/home/codis/gopath |
94 | 62 | ``` |
95 | 63 |
|
96 | | -Second, assign a Redis slave to this group: |
| 64 | +#### 3. Download Codis Source Code |
97 | 65 |
|
98 | | -``` |
99 | | -$ bin/codis-config server add 1 localhost:6380 slave |
| 66 | +The Codis source code needs to be downloaded to `$GOPATH/src/github.com/CodisLabs/codis`: |
| 67 | + |
| 68 | +```bash |
| 69 | +$ mkdir -p $GOPATH/src/github.com/CodisLabs |
| 70 | +$ cd $_ && git clone https://github.com/CodisLabs/codis.git -b release3.2 |
100 | 71 | ``` |
101 | 72 |
|
102 | | -Then the group with id of 2: |
| 73 | +#### 4. Compile Codis Source Code |
103 | 74 |
|
104 | | -``` |
105 | | -$ bin/codis-config server add 2 localhost:6479 master |
106 | | -$ bin/codis-config server add 2 localhost:6480 slave |
| 75 | +* use make tool to compile: |
| 76 | + |
| 77 | +```bash |
| 78 | +$ cd $GOPATH/src/github.com/CodisLabs/codis |
| 79 | +$ make |
| 80 | +make -j -C extern/redis-3.2.8/ |
| 81 | +... ... |
| 82 | +go build -i -o bin/codis-dashboard ./cmd/dashboard |
| 83 | +go build -i -o bin/codis-proxy ./cmd/proxy |
| 84 | +go build -i -o bin/codis-admin ./cmd/admin |
| 85 | +go build -i -o bin/codis-fe ./cmd/fe |
| 86 | + |
| 87 | +$ ls bin/ |
| 88 | +total 69124 |
| 89 | +drwxr-xr-x 4 codis codis 4096 Jan 4 14:55 assets |
| 90 | +-rwxr-xr-x 1 codis codis 17600752 Jan 4 14:55 codis-admin |
| 91 | +-rwxr-xr-x 1 codis codis 18416320 Jan 4 14:55 codis-dashboard |
| 92 | +-rwxr-xr-x 1 codis codis 9498040 Jan 4 14:55 codis-fe |
| 93 | +-rwxr-xr-x 1 codis codis 11057280 Jan 4 14:55 codis-proxy |
| 94 | +-rwxr-xr-x 1 codis codis 4234432 Jan 4 14:55 codis-server |
| 95 | +-rw-r--r-- 1 codis codis 148 Jan 4 14:55 version |
| 96 | +... ... |
| 97 | + |
| 98 | +$ cat bin/version |
| 99 | +version = 2016-01-03 14:53:22 +0800 @51f06ae3b58a256a58f857f590430977638846a3 |
| 100 | +compile = 2016-01-04 15:00:17 +0800 by go version go1.5.2 linux/amd64 |
107 | 101 | ``` |
108 | 102 |
|
109 | | -4. Config slot range of server group |
| 103 | +## 1. Running Codis Cluster |
110 | 104 |
|
111 | | -Codes implement data segmentation with Pre-sharding mechanism, 1024 slots will be segmented by default,a single key use following formula to determine which slot to resident, each slot has a server group id represents the server group which will provide service. |
| 105 | +Build a standalone codis cluster in 2 minutes,without any external component dependencies. |
| 106 | +The admin folder in the source code provides a series of scripts to quickly start, stop the codis components, improve the efficiency of operation and maintenance. |
112 | 107 |
|
| 108 | + |
| 109 | +### Start codis-dashboard |
| 110 | +Use codis-dashboard-admin.sh script to start dashboard and check the dashboard log to confirm whether there is an exception. |
| 111 | +``` |
| 112 | +./admin/codis-dashboard-admin.sh start |
| 113 | + tail -100 ./log/codis-dashboard.log.2017-04-08 |
113 | 114 | ``` |
114 | | -$ bin/codis-config slot -h |
115 | | -usage: |
116 | | - codis-config slot init |
117 | | - codis-config slot info <slot_id> |
118 | | - codis-config slot set <slot_id> <group_id> <status> |
119 | | - codis-config slot range-set <slot_from> <slot_to> <group_id> <status> |
120 | | - codis-config slot migrate <slot_from> <slot_to> <group_id> [--delay=<delay_time_in_ms>] |
121 | 115 | ``` |
| 116 | +2017/04/08 15:16:57 fsclient.go:197: [INFO] fsclient - create /codis3/codis-demo/topom OK |
| 117 | +2017/04/08 15:16:57 main.go:140: [WARN] [0xc42025f7a0] dashboard is working ... |
| 118 | +2017/04/08 15:16:57 topom.go:424: [WARN] admin start service on [::]:18080 |
122 | 119 |
|
123 | | -For exmaple, config server group 1 provide service for slot [0, 511], server group 2 provide service for slot [512, 1023] |
| 120 | +``` |
| 121 | + |
| 122 | +The default external storage Uses filesystem, the default data path is saved in /tmp/codis. If the startup fails, please check whether the current user has read/write access to the path. |
124 | 123 |
|
| 124 | + |
| 125 | +### Start codis-proxy |
| 126 | +Use codis-proxy-admin.sh script to start codis-proxy and check the proxy log to confirm whether there is an exception. |
125 | 127 | ``` |
126 | | -$ bin/codis-config slot range-set 0 511 1 online |
127 | | -$ bin/codis-config slot range-set 512 1023 2 online |
| 128 | +./admin/codis-proxy-admin.sh start |
| 129 | +tail -100 ./log/codis-proxy.log.2017-04-08 |
128 | 130 | ``` |
129 | 131 |
|
130 | | -5. Start `codis-proxy` |
| 132 | +``` |
| 133 | +2017/04/08 15:39:37 proxy.go:293: [WARN] [0xc4200df760] set sentinels = [] |
| 134 | +2017/04/08 15:39:37 main.go:320: [WARN] rpc online proxy seems OK |
| 135 | +2017/04/08 15:39:38 main.go:210: [WARN] [0xc4200df760] proxy is working ... |
| 136 | +``` |
131 | 137 |
|
| 138 | +### Start codis-server |
| 139 | +Use codis-server-admin.sh script to start codis-server and check the redis log to confirm whether there is an exception. |
132 | 140 | ``` |
133 | | - 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 |
| 141 | +./admin/codis-server-admin.sh start |
| 142 | +tail -100 /tmp/redis_6379.log |
134 | 143 | ``` |
135 | 144 |
|
136 | | -`codas-proxy`’s status are now `offline`, put it `online` to provide service: |
| 145 | +``` |
| 146 | +5706:M 08 Apr 16:04:11.748 * DB loaded from disk: 0.000 seconds |
| 147 | +5706:M 08 Apr 16:04:11.748 * The server is now ready to accept connections on port 6379 |
| 148 | +``` |
| 149 | +redis.conf pidfile,logfile default saves in the /tmp directory. If the startup fails, please check whether the current user has read/write access to the path. |
137 | 150 |
|
| 151 | +### Start codis-fe |
| 152 | +Use codis-fe-admin.sh script to start codis-fe and check the redis log to confirm whether there is an exception. |
| 153 | +``` |
| 154 | +./admin/codis-fe-admin.sh start |
| 155 | +tail -100 ./log/codis-fe.log.2017-04-08 |
138 | 156 | ``` |
139 | | - bin/codis-config -c config.ini proxy online <proxy_name> <---- proxy id, e.g. proxy_1 |
| 157 | +``` |
| 158 | +2017/04/08 16:12:13 main.go:100: [WARN] set ncpu = 1 |
| 159 | +2017/04/08 16:12:13 main.go:103: [WARN] set listen = 0.0.0.0:9090 |
| 160 | +2017/04/08 16:12:13 main.go:115: [WARN] set assets = /home/codis/go/src/github.com/CodisLabs/codis/admin/../bin/assets |
| 161 | +2017/04/08 16:12:13 main.go:153: [WARN] set --filesystem = /tmp/codis |
140 | 162 | ``` |
141 | 163 |
|
142 | | -6. Open http://localhost:18087/admin in browser |
| 164 | +### Add group by fe |
143 | 165 |
|
144 | | -Now you can achieve operations in browser. Enjoy! |
| 166 | +Please visit the cluster management web page(fe url:127.0.0.1:9090) |
| 167 | +Select the cluster(codis-demo) we have just built, in the Proxy column we can see that we have activated the Proxy, |
| 168 | +But the Group column is empty, because codis-server is not joined the cluster. |
145 | 169 |
|
146 | | -## Data Migration |
| 170 | +Add NEW GROUP |
| 171 | +In the `NEW GROUP` row, please input a number such as 1, and click NEWGROUP |
147 | 172 |
|
148 | | -Codis offers a reliable and transparent data migration mechanism, also it’s a killer feature which made Codis distinguished from other static distributed Redis solution, such as Twemproxy. |
| 173 | +Add Codis Server |
149 | 174 |
|
150 | | -The minimum data migration unit is `key`, we add some specific actions—such as `SLOTSMGRT`—to Codis to support migration based on `key`, which will send a random record of a slot to another Codis Redis instance each time, after the transportation is confirmed the original record will be removed from slot and return slot’s length. The action is atomically. |
| 175 | +In the `Add Server` row, please input the codis-server address we just started, add it to GROUP, and then click the Add Server button, as shown below |
151 | 176 |
|
152 | | -For example: migrate data in slot with ID from 0 to 511 to server group 2, `--delay` is the sleep duration after each transportation of record, which is used to limit speed, default value is 0. |
| 177 | + |
153 | 178 |
|
154 | | -``` |
155 | | -$ bin/codis-config slot migrate 0 511 2 --delay=10 |
156 | | -``` |
| 179 | +### Initialize slot by fe |
| 180 | + |
| 181 | +The new cluster slot status is offline, so we need to initialize it (allocate 1024 slots to each group), and the fastest way to initialize a cluster is to click the `rebalance all slots` button provided by fe, as shown in the following figure. |
157 | 182 |
|
158 | | -Migration progress is reliable and transparent, data won’t vanish and top layer application won’t terminate service. |
| 183 | + |
159 | 184 |
|
160 | | -Notice that migration task could be paused, but if there is a paused task, it must be fulfilled before another start(means only one migration task is allowed at the same time). |
161 | 185 |
|
162 | | -### Auto Rebalance |
| 186 | +## Quickly deploy the cluster by ansible |
| 187 | + |
| 188 | +Use ansible to quickly deploy multiple clusters in standalone and multi-machine environment. |
| 189 | +The ansible folder contains the playbook for deploying the codis cluster, modifying the parameters in the groups_var / all file according to your own deployment environment, and modifying the hosts file to add the deployed environment IP. |
| 190 | + |
| 191 | +Ansible installation is simple.Once Ansible is installed, there will be no daemons to start or keep running. You only need to install it on one machine and it can manage an entire fleet of remote machines from that central point. |
| 192 | +Ansible by default manages machines over the SSH protocol. |
163 | 193 |
|
164 | | -Codis support dynamic slots migration based on RAM usage to balance data distribution. |
165 | | - |
166 | 194 | ``` |
167 | | -$bin/codis-config slot rebalance |
| 195 | +git clone git://github.com/ansible/ansible.git -b stable-2.3 |
| 196 | +cd ./ansible |
| 197 | +source ./hacking/env-setup |
| 198 | +cd $codis_dir/ansible |
| 199 | +ansible-playbook -i hosts site.yml |
168 | 200 | ``` |
169 | 201 |
|
170 | | -Requirements: |
171 | | - * all codis-server must set maxmemory. |
172 | | - * All slots’ status should be `online`, namely no transportation task is running. |
173 | | - * All server groups must have a master. |
174 | | - |
175 | 202 |
|
176 | 203 | ##HA |
177 | 204 |
|
|