The construction and use of Codis cluster

Source: Internet
Author: User
Tags install go mkdir redis zookeeper redis server
the construction and use of Codis cluster

First, Introduction

Codis is a distributed Redis solution, for upper-level applications, there is no obvious difference between connecting Codis proxy and connecting to native Redis server (unsupported list of commands), and upper-level applications can be used like a single redis, Codis the bottom layer will handle the request forwarding, non-stop data migration, and so on, all the things behind, for the front of the client is transparent, you can simply think behind the connection is an infinite memory of the Redis service.

Codis Frame Composition:

Above we can see that Codis-proxy is a single node, because we can combine keepalived to achieve high availability:

Codis-proxy provides access to the cluster Redis service

Codis-redis-group enables Redis read-write level scaling, high performance

Codis-redis implements Redis instance services, enabling high availability of services through Codis-ha

Ii. Description of the components

Codis-proxy: is a client-attached Redis Proxy service, Codis-proxy itself implements the Redis protocol and behaves as if it were a native redis (like Twemproxy), for a business Multiple codis-proxy,codis-proxy can be deployed in itself without state.

Codis-config: is a CODIS management tool that supports including, adding/removing REDIS nodes, adding/removing proxy nodes, initiating data migration, and so on, Codis-config itself has an HTTP server, Launches a dashboard that allows the user to view the status of the Codis cluster directly on the browser.

Codis-server: is a redis branch maintained by the CODIS project, Based on 2.8.13 development, added slot support and atomic data migration instructions, Codis Upper Codis-proxy and Codis-config can only work with this version of Redis interaction.

ZooKeeper: The meta-information used to store data routing tables and Codis-proxy nodes, codis-config commands are synchronized through ZooKeeper to each surviving Codis-proxy

Description

Codis supports differentiating between different products according to namespace, with different product name products and no conflicting configurations.

Lab Environment:

   Role                  IP address            host name          
codis-redis-master  192.168.10.128      redis-master             
codis-redis-slave   192.168.10.129      redis-slave
zk,codis-proxy      192.168.10.130      


installation Configuration (I am only deploying a single codis-proxy node environment here), operate on the Codis-proxy server:

1. Install go:

Download the installation package: (seemingly overseas server to download)

wget https://storage.googleapis.com/golang/go1.4.1.linux-amd64.tar.gz

After the download, the decompression can be used:

[Root@codis-proxy ~]# tar-zxf go1.4.1.linux-amd64.tar.gz-c/usr/local/

2, install the JDK, you download an installation on the official website, the version requirements are not strict, the following zookeeper will use the JDK:

[Root@codis-proxy ~]# sh jdk-6u34-fcs-bin-b04-linux-amd64-19_jul_2012.bin
[root@codis-proxy ~]# MV jdk1.6.0_34/ usr/local/ 
[Root@codis-proxy ~]# MV/USR/LOCAL/JDK1.6.0_34/USR/LOCAL/JDK

3, Installation Zookeeper

[Root@codis-proxy ~]# wget http://mirrors.cnnic.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
[ Root@codis-proxy ~]# tar-xzf zookeeper-3.4.6.tar.gz-c/usr/local/

Then modify the environment variable to vim/etc/profile at the end to add the following:

Export Goroot=/usr/local/go
export Gopath=/usr/local/codis
java_home=/usr/local/jdk
class_path= $JAVA _home/lib: $JAVA _home/jre/lib
export zookeeper_home=/usr/local/zookeeper-3.4.6
export path= $PATH: $GOROOT/ Bin: $JAVA _home/bin: $ZOOKEEPER _home/bin

Then execute Source/etc/profile
Edit a file to test if the go is working:

[Root@codis-proxy ~]# Cat Hello.go Package 
        main
    import "FMT"

    func Main () {
        fmt. Printf ("hello,world\n")
 }
[Root@codis-proxy ~]# go run hello.go 
hello,world

As you can see, normal printing Hello,world, in the command input Java directly, if a lot of usage instructions, it means that the Java installation is successful.

4, install Codis, install Codis depends on go, so in the installation Codis first loaded go, the above has been installed:

Get Codis:

[Root@codis-proxy ~]# yum install-y git
[root@codis-proxy ~]# go get github.com/wandoulabs/codis package
GitHub . Com/wandoulabs/codis
        Imports Github.com/wandoulabs/codis
        Imports Github.com/wandoulabs/codis:no buildable Go Source Files In/usr/local/codis/src/github.com/wandoulabs/codis

Can see no buildable Go source files In/usr/local/codis/src/github.com/wandoulabs/codis, we are in the above environment is set goapth=/usr/local/ Codis, so as long as the above command is executed, it will be downloaded under/usr/local/codis:
We enter the path of the prompt to install, the installation process is relatively long, patient wait:

[Root@codis-proxy ~]# Cd/usr/local/codis/src/github.com/wandoulabs/codis
[root@codis-proxy codis]# ls
bootstrap.sh  cmd  doc  Docker  Dockerfile  extern  godeps  Makefile  mit-license.txt  Pkg  README.MD  Sample  test  vitess_license
[root@codis-proxy codis]# sh bootstrap.sh 
Downloading dependcies, it may take a few minutes ...

When the script finishes, you see the result of make gotest:

Hint:to run ' make test ' was a good idea;) make[2]: Leaving directory '/usr/local/codis/src/github.com/wandoulabs/codis/e Xtern/redis-2.8.13/src ' make[1]: Leaving directory '/usr/local/codis/src/github.com/wandoulabs/codis/extern/ redis-2.8.13 ' Go test./pkg/....       /cmd/...-race? github.com/wandoulabs/codis/pkg/env [no test files] OK github.com/wandoulabs/codis/pkg/models 5.773s ok git       Hub.com/wandoulabs/codis/pkg/proxy/cachepool 0.009s? github.com/wandoulabs/codis/pkg/proxy/group [no test files] OK Github.com/wandoulabs/codis/pkg/proxy/parser 0.       016s?       github.com/wandoulabs/codis/pkg/proxy/redisconn [no test files]? Github.com/wandoulabs/codis/pkg/proxy/redispool [no test files] OK github.com/wandoulabs/codis/pkg/proxy/router 16       .092s? github.com/wandoulabs/codis/pkg/proxy/router/topology [no test files] OK github.com/wandoulabs/codis/pkg/utils 0.      008s OK github.com/wandoulabs/codis/cmd/cconfig 0.016s? github.com/wandoulabs/codis/cmd/proxy [no test files] [Root@codis-proxy codis]#  

Generates Codis-config in the Codis/bin folder, Codis-proxy two executables, (in addition, the Bin/assets folder is the front-end resource required for Codis-config HTTP service, and the CO Dis-config placed in the same folder)

After compiling, copy the bin directory and some scripts to the past/usr/local/codis directory:

[Root@codis-proxy codis]# mkdir-p/usr/local/codis/{log,redis_conf}
[Root@codis-proxy codis]# cp-rf bin/usr/ local/codis/
[root@codis-proxy codis]# cp sample/config.ini/usr/local/codis/bin/
[Root@codis-proxy codis]# CP sample/redis_conf/6381.conf/usr/local/codis/redis_conf/
[root@codis-proxy codis]# cp-rf src/github.com/ wandoulabs/codis/sample/*./

To stop, the CODIS-PROXY environment is almost set up, the following configuration:

5, to configure

Operating on the Codis-proxy

To configure zookeeper, modify the configuration file:

[Root@codis-proxy ~]# Cp/usr/local/zookeeper-3.4.6/conf/zoo_sample.cfg/usr/local/zookeeper-3.4.6/conf/zoo.cfg
[Root@codis-proxy ~]# cd/usr/local/zookeeper-3.4.6/conf/
[Root@codis-proxy conf]# vim zoo.cfg
ticktime=2000
initlimit=10
synclimit=5
datadir=/data/ Zookeeper/data
autopurge.snapretaincount=500
autopurge.purgeinterval=24
clientport=2181
# server.1=codis-1:2888:3888
#server. 2=codis-2:2888:3888
#server. 2=codis-3:2888:3888

Set myID:
Set myID under the directory specified by the DATADIR we configured, create a myID file with a number that identifies the current host, conf/ Zoo.cfg file Configuration srver.x X Why number, then myID file input This number, I only have a ZK, so configuration file can not configure server.x, but still want to configure myID, echo a number 1 in can. If there are more than one ZK, the corresponding number in the ZK server echo corresponds to the corresponding myID file

[Root@codis-proxy conf]# mkdir-p/data/zookeeper/data
[Root@codis-proxy conf]# echo "1" >/data/zookeeper/data /myid

Start zookeeper, because the environment variable has already added the path, executes the command directly, executes zkserver.sh start, waits for a while to execute Zkserver status:

[Root@codis-proxy ~]# zkserver.sh start
JMX enabled by default
Using config:/usr/local/zookeeper-3.4.6/bin/. /conf/zoo.cfg
Starting Zookeeper ... STARTED
[root@codis-proxy ~]# zkserver.sh status
JMX enabled by default
Using config:/usr/local/ zookeeper-3.4.6/bin/. /conf/zoo.cfg
Mode:standalone

In that directory to start, in that directory to generate a startup log zookeeper.out, check this log to see if it started properly. Because of a single zookeeper, this indicates mode:standalone, if there are multiple ZK nodes, there is only one Mode:leader state, and the other is the Mode:follower state.

Since I am now making a machine to do ZK, there is almost no modification here:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.