Detailed Codis installation and deployment

Detailed Codis installation and deployment

The introduction and installation on Codis github is very complete, and there are also Chinese/English, but follow the steps of github to install, there will be some holes, so there is such an article.

In the previous article, "Redis Practical Monitoring Tools List" , the monitoring tools commonly used in Redis were introduced. Codis has a graphical panel and management tools. So there is such an article. Desktop system: Centos7.

v Introduction

Codis is a distributed Redis solution. For upper-layer applications, there is no obvious difference between connecting to Codis Proxy and connecting to native Redis Server (list of unsupported commands). The upper-layer application can be used like a stand-alone Redis. Codis The bottom layer will handle request forwarding, non-stop data migration and other tasks.All the things behind are transparent to the previous client. You can simply think that the back connection is a Redis service with unlimited memory.

  • Codis Proxy (codis-proxy)
  • Codis Manager (codis-config)
  • Codis Redis (codis-server)
  • ZooKeeper

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

codis-config is a management tool for Codis. It supports operations such as adding/deleting Redis nodes, adding/deleting Proxy nodes, and initiating data migration. codis-config itself also comes with an http server that will start a dashboard, and users can directly Observe the running status of the Codis cluster on the browser.

codis-server is a Redis branch maintained by the Codis project. It is developed based on 2.8.13 and added slot support and atomic data migration instructions. Codis-proxy and codis-config on the upper layer of Codis can only interact with this version of Redis to be normal run.

Codis relies on ZooKeeper to store the data routing table and the meta-information of the codis-proxy node.Commands initiated by codis-config will be synchronized to each surviving codis-proxy through ZooKeeper.

Codis supports distinguishing different products according to Namespace. Products with different product names will not conflict with each other.

Codis architecture diagram

The picture comes from the Internet and is invaded.

v Features

  • Auto balance
  • Very easy to use
  • Graphical panel and management tools
  • Supports most Redis commands and is fully compatible with twemproxy
  • Support Redis native client
  • Safe and transparent data migration, nodes can be easily added and deleted as needed
  • Provide command line interface
  • RESTful APIs

Attention, in order to avoid duplication of wheels. The above "Introduction" part is an excerpt from Baidu Baike .

v Installation steps

1.1 Install Go

1.1.1 Download Go compression package

The habit is in the latest environment, the latest version of go is 1.12.5, here we will use the latest version. The latest update can be seen here. golang.org/dl/

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

1.1.2 Decompress the Go archive

tar -zxvf go1.12.5.linux-amd64.tar.gz

1.1.3 Setting environment variables

As shown in the figure, the installation directory of go is

/usr/local

vim/etc/profile

export GOROOT=/usr/local/go #Set to the path of go installation export GOPATH=/usr/local/gopath #Path of the default installation package export PATH=$PATH:$GOROOT/bin:$GOPATH/bin Copy code

Update/etc/profile,

wq
Save and use
source/etc/profile
The command can make the newly created environment variable take effect immediately without restarting the system.

1.1.4 helloword go go go

Create a new go file and run it.

package main import "fmt" func main(){ fmt.Printf("hello,world\n") } Copy code

1.2 Install JDK

Friends who have not installed Java JDK can directly look here. "CentOS install Java JDK"

1.3 Install ZooKeeper

1.3.1 Download ZooKeeper compressed package

wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.13/zookeeper-3.4.13.tar.gz

1.3.2 Decompress the ZooKeeper compressed package

tar -zxvf zookeeper-3.4.13.tar.gz

1.3.3 Delete ZooKeeper compressed package

rm -f zookeeper-3.4.13.tar.gz

1.3.4 Copy configuration file

cd/usr/local/zookeeper-3.4.13/conf

cp zoo_sample.cfg zoo.cfg

vim zoo.cfg

This zoo.cfg is the configuration file of zookeeper. Here I am using the stand-alone version. If you want to use the cluster version, you can modify the configuration file.

# The number of milliseconds of each tick tickTime=2000 # The number of ticks that the initial # synchronization phase can take initLimit=10 # The number of ticks that can pass between # sending a request and getting an acknowledgement syncLimit=5 # the directory where the snapshot is stored. # do not use/tmp for storage,/tmp here is just # example sakes. dataDir=/usr/local/zookeeper-3.4.13/data #It is best to set it yourself here # the port at which the clients will connect clientPort=2181 # the maximum number of client connections. # increase this if you need to handle more clients #maxClientCnxns=60 # # Be sure to read the maintenance section of the # administrator guide before turning on autopurge. # # http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance # # The number of snapshots to retain in dataDir #autopurge.snapRetainCount=3 # Purge task interval in hours # Set to "0" to disable auto purge feature #autopurge.purgeInterval=1 server.1=cnblogs01:8888:9888 #Modify here to your own hostname or IP server.2=cnblogs02:8888:9888 server.3=cnblogs03:8888:9888 Copy code

Create/usr/local/zookeeper-3.4.13/data folder, create a new myid, write 1

mkdir data

vim myid

1.3.5 Start ZooKeeper

/usr/local/zookeeper-3.4.13/bin/zkServer.sh start

1.4 Install Codis

1.4.1 Install Codis

Codis source code needs to be downloaded to $GOPATH/src/github.com/CodisLabs/codis

mkdir -p $GOPATH/src/github.com/CodisLabs

cd $_ && git clone https://github.com/CodisLabs/codis.git -b release3.2

1.4.2 Compile Codis

cd $GOPATH/src/github.com/CodisLabs/codis

make

Compile directly through make, here is an error

./autogen.sh: Line 5: autoconf: Command not found

Install autoconf

yum install autoconf

After installing autoconf, continue to pass

make
Compile.

The components of dashboard, proxy, admin, ha, fe and codis have been compiled.

Note that the directory structure must be its own definition of gopath, and the directory after the order needs to be created. It must be the same as the official website, but not the same, and an error should be reported.

$GOPATH/src/github.com/CodisLabs/

1.4.3 Start codis-dashboard

use

codis-dashboard-admin.sh
The script starts the dashboard, and checks the dashboard log to confirm whether there is any abnormality in the startup.

./admin/codis-dashboard-admin.sh start

tail -100 ./log/codis-dashboard.log.2019-05-26
Note: 2019-05-26 is the current date.

1.4.3 Start codis-proxy

use

codis-proxy-admin.sh
The script starts codis-proxy, and check the proxy log to confirm whether the startup is abnormal.

./admin/codis-proxy-admin.sh start

tail -100 ./log/codis-proxy.log.2019-05-26

1.4.4 Start codis-server

use

codis-server-admin.sh
The script starts the codis-server and checks the redis log to confirm whether there is any abnormality in the startup.

./admin/codis-server-admin.sh start

tail -100/tmp/redis_6379.log

Check the log as shown in the figure below, an error message is reported when starting codis:

21875:M 26 May 20:51:24.154 * Increased maximum number of open files to 10032 (it was originally set to 1024). 21875:M 26 May 20:51:24.154 # Creating Server TCP listening socket 127.0.0.1:6379: bind: Address already in use Copy code

Because the default port number of Redis is 6379, because the machine is set to start Redis by default before ( centos install Redis ), 6379 is already occupied.

solution

As shown in the figure below, modify

/usr/local/gopath/src/github.com/CodisLabs/codis/config/redis.conf
The port number of the configuration file. Change to 6380

Modify the port number and then pass

./admin/codis-server-admin.sh start
Start codis-server.

tail -100/tmp/redis_6379.log
View the log as follows:

Note: If the corresponding logfile in redis.conf is also changed to 6380, you must use it to view the log

tail -100/tmp/redis_6380.log

1.4.5 Start codis-fe

use

codis-fe-admin.sh
The script starts codis-fe, and check the fe log to confirm whether there is any abnormality in startup.

./admin/codis-fe-admin.sh start

tail -100 ./log/codis-fe.log.2019-05-26

1.5 Add group through fe

Access the cluster management page through a web browser (fe address: 127.0.0.1:9090) and select the cluster codis-demo we just built. You can see the Proxy we have started in the Proxy column, but the Group column is empty because we started it. codis-server is not added to the cluster to add NEW GROUP, enter 1 in the NEW GROUP line, and then click NEW GROUP to add Codis Server, and enter the address of the codis-server we just started in the Add Server line, add it to the group we just created, and then Then click the Add Server button, as shown in the figure below:

1.6 Initialize slot through fe

The newly added cluster slot status is offline, so we need to initialize it (assign 1024 slots to each group), and the fastest way to initialize can be provided by fe

rebalance all slots
Button to do it, as shown in the figure below, click this button, we quickly completed the construction of a cluster.

1.7 Quickly deploy a cluster through ansible

Use ansible to quickly deploy multiple codis clusters on a single machine or multiple machines. The ansible folder contains the playbook for deploying the codis cluster, modified according to your own deployment environment

groups_var/all
Parameters in the file, modify the hosts file and add the environment IP for deployment. The installation of ansible is also extremely simple. Each deployment machine does not need to install any additional agents, and communicates with each other through ssh.

git clone https://github.com/ansible/ansible.git -b stable-2.3 cd ./ansible source ./hacking/env-setup cd $codis_dir/ansible ansible-playbook -i hosts site.yml Copy code

v Cluster configuration

2.1 Add Redis instance

Add two Redis instances, 6381 and 6382, respectively.

cp config/redis.conf config/redis6381.conf

cp config/redis.conf config/redis6382.conf

Update the port, pidfile and logfile of 6381 and 6382.conf respectively

vim config/redis6381.conf

After the update, start the two new Redis instances.

./bin/codis-server ./config/redis6381.conf

./bin/codis-server ./config/redis6382.conf

Add two instances according to the method of add server above (as shown in the figure below). Note that if it is not executed

./bin/codis-server ./config/redis6381.conf
, An error will be reported when adding.

The default state just added is NO:ONE, as shown in the figure below, click the small wrench (SLAVEOF 127.0.0.1:6380).

Test effect:

Note: As shown in the figure above, after opening the cluster management, 6380 can be read and written, 81 and 82 only have read-only permissions.

2.2 Create a new group

Follow the steps above to continue to create 7380 and 7381.

Add new groups and server members in Codis Dashboard (http://ip:9090/#codis-demo).

v Blog summary

This article only talks about codis, not about clusters. If you are interested in clusters, you can read the previous article. "Detailed Redis Cluster Cluster"

The "Installation Steps" section of this article uses the introduction on Codis github in a large area. You can also go to github to see this section. Of course, this article also adds some details that are not too clear or not well understood on github.

I originally planned to introduce springboot to introduce codis directly in this article, but this article is already very long and it is really inconvenient to typeset. So you can read about springboot here. "SpringBoot Advanced Tutorial (59) Integrating Codis" .

Other references:


Author: Please call me the head brother
. Place: www.cnblogs.com/toutou/
About the author: Focus on the project development of the basic platform. If you have any questions or suggestions, please enlighten me!
Copyright statement: The copyright of this article belongs to the author and the blog garden, welcome to reprint, but this statement must be retained without the author s consent, and a link to the original text should be given in an obvious place on the article page.
Hereby declare: All comments and private messages will be replied as soon as possible. Also welcome everyone in the garden to correct mistakes and make progress together. Or directly message me in
support of the blogger: If you think the article is helpful to you, you can click [ Recommend ] in the lower right corner of the article . Your encouragement is the author's greatest motivation to persist in original and continuous writing!/