How to Set Up a Codis Cluster on Linux with Go: Step‑by‑Step Guide
This article provides a comprehensive, step‑by‑step tutorial for installing Go 1.4, compiling Codis from source, configuring Zookeeper, setting up Codis server, proxy, and dashboard, and deploying a three‑node Codis cluster on Linux, including all necessary environment variables and command examples.
Preparation Plan
Golang Environment Setup
Environment setup is simple: download go1.4.2.linux-amd64.tar.gz, extract, and add to the PATH.
Assume extraction to /usr/local/go (GOROOT) and a workspace at /workspace/golang. The workspace will contain subdirectories:
1. src – source code
2. pkg – compiled package files
3. bin – compiled binaries (e.g., godep)Set environment variables:
export GOROOT=/usr/local/go
export GOPATH=/workspace/golang
PATH=".:$PATH:$GOROOT/bin:$GOPATH/bin:$ZOOKEEPER/bin"After reloading, run go version to verify.
Adding $GOPATH/bin to PATH allows global use of Go tools such as godep.
Codis Download and Build
The latest Codis source is at https://github.com/CodisLabs/codis. Get the source with: go get -u -d github.com/CodisLabs/codis Enter the source directory and run make to compile.
Compilation uses godep; install it if missing: go get github.com/tools/godep After installation, ensure godep is in $GOPATH/bin and added to PATH.
With Go 1.5+ you may encounter GO15VENDOREXPERIMENT errors. Disable it before building:
export GO15VENDOREXPERIMENT=0Compiled Files
After compilation, a bin directory is created containing:
assets // dashboard static files
codis-config // configuration management component
codis-proxy // proxy core component
codis-server // custom Redis based on redis 2.8.21These are the files needed for cluster deployment; cross‑compilation may be required for other platforms.
Cluster Plan
Use three machines, each running a Zookeeper instance and two Codis server instances (Redis). Two machines run Codis proxy, and one runs the Codis dashboard.
host ip zookeeper port redis master/slave ports codis proxy codis dashboard
slave1 192.168.4.124 2181 6379/6380 Y
slave2 192.168.4.126 2181 6379/6380 Y
slave3 192.168.4.128 2181 6379/6380 YZookeeper Cluster
Nodes:
1. slave1:2181
2. slave2:2181
3. slave3:2181Start Zookeeper on each node.
Codis Service Cluster
Create Codis directories on each node:
mkdir -p /usr/local/codis/{log,redis_conf}
cp -rf bin /usr/local/codis/
cp config.ini /usr/local/codis/conf/
cp extern/redis-test/6379.conf /usr/local/codis/redis_conf/Modify config.ini according to comments (settings for dashboard and proxies):
# coordinator (zookeeper or etcd)
coordinator=zookeeper
# multiple instances, comma‑separated
zk=slave1:2181,slave2:2181,slave3:2181
product=test
dashboard_addr=192.168.4.126:18087
# proxy settings
backend_ping_period=5
session_max_timeout=1800
session_max_bufsize=131072
session_max_pipeline=1024
zk_session_timeout=30000
proxy_id=proxy_1Start the dashboard on slave2: bin/codis-config dashboard Initialize slots on any machine:
bin/codis-config slot initStart Codis Redis Servers
Run on each machine:
/usr/local/codis/bin/codis-server /usr/local/codis/redis_conf/6379.conf &
/usr/local/codis/bin/codis-server /usr/local/codis/redis_conf/6380.conf &Add Redis Server Groups
Use codis-config server commands:
bin/codis-config server add 1 slave1:6379 master
bin/codis-config server add 1 slave1:6380 slave
bin/codis-config server add 2 slave2:6379 master
bin/codis-config server add 2 slave2:6380 slave
bin/codis-config server add 3 slave3:6379 master
bin/codis-config server add 3 slave3:6380 slaveAssign slot ranges (Codis uses 1024 slots by default):
bin/codis-config slot range-set 0 334 1 online
bin/codis-config slot range-set 335 669 2 online
bin/codis-config slot range-set 670 1023 3 onlineStart Codis Proxy
bin/codis-proxy -c config.ini -L ./log/proxy.log --cpu=8 --addr=0.0.0.0:19000 --http-addr=0.0.0.0:11000The proxy starts offline; bring it online:
bin/codis-config -c config.ini proxy online <proxy_name>Browser Management
Access the dashboard at http://192.168.4.126:18087/admin to manage the cluster.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
