Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What's the use of codis?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article is to share with you about the usefulness of codis. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. Brief introduction to Codis

Codis is a distributed Redis solution. For upper layer applications, there is no obvious difference between connecting to Codis Proxy and connecting native Redis Server (unsupported command list). The upper application can be used like a stand-alone Redis. The bottom layer of Codis will handle request forwarding, non-stop data migration and other work. Everything behind is transparent to the front client. It can be simply thought that what is connected behind is a Redis service with unlimited memory.

Codis consists of four parts:

Codis Proxy (codis-proxy)

Codis Manager (codis-config)

Codis Redis (codis-server)

ZooKeeper

Codis-proxy is a Redis proxy service connected by the client. Codis-proxy itself implements the Redis protocol, which is no different from a native Redis (like Twemproxy). For a business, multiple codis-proxy can be deployed, and codis-proxy itself is stateless.

Codis-config is a management tool for Codis, which supports operations such as adding / deleting Redis nodes, adding / deleting Proxy nodes, initiating data migration and so on. Codis-config itself also comes with a http server, which launches a dashboard, and users can observe the running status of the Codis cluster directly in the browser.

Codis-server is a Redis branch of Codis project maintenance, based on 2.8.21 development, adding slot support and atomic data migration instructions. Codis-proxy and codis-config in the upper layer of Codis can only interact with this version of Redis to work properly.

Codis relies on ZooKeeper to store data routing tables and meta-information of codis-proxy nodes. Commands initiated by codis-config are synchronized to each surviving codis-proxy through ZooKeeper.

Codis supports distinguishing different products according to Namespace, products with different product name, each configuration will not conflict.

2. Codis architecture 3. Codis deployment

Install 3 centos servers: 192.168.92.136192.168.92.138192.168.92.138

3.1. Deploy Architectur

3.2. Deploy role 3.2.1. Zookeeper cluster

192.168.92.136:2181

192.168.92.137:2181

192.168.92.138:2181

3.2.2. Codis-config

192.168.92.136:18078

3.2.3. Codis-proxy

192.168.92.137:19000

192.168.92.138:19000

3.2.4. Codis-server

192.168.92.137Vol 7000, 192.168.92.137Rd 7001 (master, slave)

192.168.92.138VR 7000, 192.168.92.138VR 7001 (Master, Slave)

3.3. Deploy 3.3.1. Turn off the firewall and selinux (slightly) 3.3.2. Install jdk (abbreviated)

3.3.3. Install zookeeper3.3.3.1. Download zookeeper

Download address: http://zookeeper.apache.org/releases.html

3.3.3.2. Decompress zookeeper

Tar xf zookeeper-3.4.6.tar.gz-C / usr/local/

3.3.3.3. Edit the zookeeper file

The configuration file is stored in the $ZOOKEEPER_HOME/conf/ directory and the name of the zoo_sample.cfg file is changed to zoo.cfg

Mv zoo_sample.cfg zoo.cfg

Edit zoo.cfg: vizoo.cfg to add nodes

Server.1=192.168.92.136:2888:3888

Server.2=192.168.92.137:2888:3888

Server.3=192.168.92.138:2888:3888

Modify data path: dataDir=/var/lib/zookeeper

Add a myid file under the data path, and store the content in pid, which is consistent with server.x.

3.3.3.4. Start zookeeper

Execute:. / bin/zkServer.sh start

3.4. Install go3.4.1. Download go

Address: http://golangtc.com/static/go/go1.4.2.linux-amd64.tar.gz

3.4.2. Decompress go

Tar xf go1.4.2.linux-amd64.tar.gz-C/usr/local/

3.4.3. Add go environment variable

Vi / etc/profile, add the following

GOROOT=/usr/local/go

GOPATH=/usr/local/go/work

Source / etc/profile

3.5. Install Development Tool,git

Yum install-y "Development Tool"

Yum install-y git

3.6. Install codis3.6.1. Download and compile codis

Go get-umurd github.com/wandoulabs/codis

Cd $GOPATH/src/github.com/wandoulabs/codis

. / bootstrap.sh

Make gotest

3.6.2. Edit the config.ini file

Modify zookeeper address and dashboard address: vi config.ini

The proxy_id for each proxy must be different

3.6.3. Start dashboard

Mkdir log

. / bin/codis-config-c config.ini-L. / log/dashboard.log dashboard &

3.6.4. Initialize solts

. / bin/codis-config-c config.ini slot init-f

3.6.5. Start codis-server

Start master:mkdir 7000

Cp extern/redis-2.8.21/redis.conf 7000/

Modify port, bind, maxmemory:vi 7000/redis.conf

Start:. / bin/codis-server 7000/redis.conf

Start slave: mkdir 7001

Cp extern/redis-2.8.21/redis.conf 7001/

Modify port, bind, maxmemory:vi 7001/redis.conf

Start:. / bin/codis-server 7001/redis.conf

3.6.6. Add redis server group

. / bin/codis-config-cconfig.ini server add 1 192.168.92.137 master

. / bin/codis-config-c config.ini server add1 192.168.92.137 slave

192.168.92.138 node starts redis as above

3.6.7. Set the slot scope of the server group service

. / bin/codis-config-c config.ini slotrange-set 0 600 1 online

. / bin/codis-config-c config.ini slotrange-set 601 1023 2 online

3.6.8. Start codis-proxy

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

3.6.9. Browser access

Http://192.168.92.136:18087/admin/

4. Data migration

Migrate solt:599600 of group_1 to group_2

4.1. Command line migration: bin/codis-config-c config.ini slot migrate 599600 2-delay=104.2.Dashboard migration

5. Auto Rebalance

Codis supports automatic migration of slot according to instance memory to balance data distribution.

Request:

All codis-server must have the maxmemory parameter set

All slots should be in the online state, that is, no migration task is in progress

All server group must have Master

5.1. Command line mode:

$bin/codis-config slot rebalance

5.2.Dashboard mode

6. HA

When a group master dies, codis does not automatically upgrade a slave to master

The tool will take master offline when it detects that it is dead and select one of the slave to be promoted to master to continue to provide services.

Go get github.com/ngaut/codis-ha

Cd / usr/local/go/work/src/github.com/ngaut/codis-ha

Go build

. / codis-ha--codis-config=192.168.92.136:18087-- productName=test &

7. Jodis client

Multiple proxy using round robin scheduling strategy

Com.wandoulabs.jodis jodis 0.1.2JedisResourcePool jedisPool = RoundRobinJedisPool (, 30000, JedisPoolConfig ()); (Jedis jedis = jedisPool.getResource ()) {jedis.set (,); String value = jedis.get (); System..println (value);} 8. Commands not supported by Codis

Command Type

Command Name

Keys

KEYS

MIGRATE

MOVE

OBJECT

RANDOMKEY

RENAME

RENAMENX

SCAN

Strings

BITOP

MSETNX

Lists

BLPOP

BRPOP

BRPOPLPUSH

Pub/Sub

PSUBSCRIBE

PUBLISH

PUNSUBSCRIBE

SUBSCRIBE

UNSUBSCRIBE

Transactions

DISCARD

EXEC

MULTI

UNWATCH

WATCH

Scripting

SCRIPT

Server

BGREWRITEAOF

BGSAVE

CLIENT

CONFIG

DBSIZE

DEBUG

FLUSHALL

FLUSHDB

LASTSAVE

MONITOR

RESTORE

SAVE

SHUTDOWN

SLAVEOF

SLOWLOG

SYNC

TIME

Codis Slot

SLOTSCHECK

SLOTSDEL

SLOTSINFO

SLOTSMGRTONE

SLOTSMGRTSLOT

SLOTSMGRTTAGONE

SLOTSMGRTTAGSLOT

9. Commands semi-supported by Codis

You need to put the following key into the same slot to support it. If the key is "bar {zap}", only the zap will be hash.

Command Type

Command Name

Lists

RPOPLPUSH

Sets

SDIFF

SINTER

SINTERSTORE

SMOVE

SUNION

SUNIONSTORE

Sorted Sets

ZINTERSTORE

ZUNIONSTORE

HyperLogLog

PFMERGE

Scripting

EVAL

EVALSHA

10. Appendix 10.1. Modify dashboard port number

1. Modify the config file

Dashboard_addr=192.168.92.136:19001

two。 The startup command is changed to:

. / bin/codis-config-cconfig.ini-L. / log/dashboard.log dashboard-- addr=192.168.92.136:19001 &

Thank you for reading! This is the end of this article on "what's the use of codis?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report