{"id":28243,"date":"2022-12-03T13:14:25","date_gmt":"2022-12-03T05:14:25","guid":{"rendered":"http:\/\/gulass.cn\/?p=28243"},"modified":"2022-12-03T13:14:37","modified_gmt":"2022-12-03T05:14:37","slug":"deploy-codis-cluster","status":"publish","type":"post","link":"https:\/\/gulass.cn\/deploy-codis-cluster.html","title":{"rendered":"\u5b9e\u6218Centos\u7cfb\u7edf\u90e8\u7f72Codis\u96c6\u7fa4\u670d\u52a1"},"content":{"rendered":"\n\n\n
\u5bfc\u8bfb<\/td>\nCodis \u662f\u4e00\u4e2a\u5206\u5e03\u5f0f Redis \u89e3\u51b3\u65b9\u6848, \u5bf9\u4e8e\u4e0a\u5c42\u7684\u5e94\u7528\u6765\u8bf4, \u8fde\u63a5\u5230 Codis Proxy \u548c\u8fde\u63a5\u539f\u751f\u7684 Redis Server \u6ca1\u6709\u660e\u663e\u7684\u533a\u522b (\u4e0d\u652f\u6301\u7684\u547d\u4ee4\u5217\u8868), \u4e0a\u5c42\u5e94\u7528\u53ef\u4ee5\u50cf\u4f7f\u7528\u5355\u673a\u7684 Redis \u4e00\u6837\u4f7f\u7528, Codis \u5e95\u5c42\u4f1a\u5904\u7406\u8bf7\u6c42\u7684\u8f6c\u53d1, \u4e0d\u505c\u673a\u7684\u6570\u636e\u8fc1\u79fb\u7b49\u5de5\u4f5c, \u6240\u6709\u540e\u8fb9\u7684\u4e00\u5207\u4e8b\u60c5, \u5bf9\u4e8e\u524d\u9762\u7684\u5ba2\u6237\u7aef\u6765\u8bf4\u662f\u900f\u660e\u7684, \u53ef\u4ee5\u7b80\u5355\u7684\u8ba4\u4e3a\u540e\u8fb9\u8fde\u63a5\u7684\u662f\u4e00\u4e2a\u5185\u5b58\u65e0\u9650\u5927\u7684 Redis \u670d\u52a1.<\/strong><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\"8-28-01\"<\/a><\/p>\n

\u4e00\u3001Codis\u7b80\u4ecb<\/strong><\/div>\n

Codis \u662f Wandoujia Infrastructure Team \u5f00\u53d1\u7684\u4e00\u4e2a\u5206\u5e03\u5f0f Redis \u670d\u52a1, \u7528\u6237\u53ef\u4ee5\u770b\u6210\u662f\u4e00\u4e2a\u65e0\u9650\u5185\u5b58\u7684 Redis \u670d\u52a1, \u6709\u52a8\u6001\u6269\/\u7f29\u5bb9\u7684\u80fd\u529b. \u5bf9\u504f\u5b58\u50a8\u578b\u7684\u4e1a\u52a1\u66f4\u5b9e\u7528, \u5982\u679c\u4f60\u9700\u8981 SUBPUB \u4e4b\u7c7b\u7684\u6307\u4ee4, Codis \u662f\u4e0d\u652f\u6301\u7684. \u65f6\u523b\u8bb0\u4f4f Codis \u662f\u4e00\u4e2a\u5206\u5e03\u5f0f\u5b58\u50a8\u7684\u9879\u76ee. \u5bf9\u4e8e\u6d77\u91cf\u7684 key, value\u4e0d\u592a\u5927( <= 1M ), \u968f\u7740\u4e1a\u52a1\u6269\u5c55\u7f13\u5b58\u4e5f\u8981\u968f\u4e4b\u6269\u5c55\u7684\u4e1a\u52a1\u573a\u666f\u6709\u7279\u6548.<\/p>\n

Codis github\u5730\u5740\uff1ahttps:\/\/github.com\/CodisLabs\/codis<\/span><\/p>\n

Codis FAQ\uff1ahttps:\/\/github.com\/CodisLabs\/codis\/blob\/master\/doc\/FAQ_zh.md<\/span><\/p>\n

\u4e8c\u3001Codis\u67b6\u6784\u56fe<\/strong><\/div>\n

\"8-28-02\"<\/a><\/p>\n

1\u3001\u7ec4\u4ef6\u8bf4\u660e<\/strong><\/span><\/div>\n

Codis \u7531\u56db\u90e8\u5206\u7ec4\u6210:<\/p>\n

Codis Proxy (codis-proxy)<\/p>\n

Codis Dashboard (codis-config)<\/p>\n

Codis Redis (codis-server)<\/p>\n

ZooKeeper\/Etcd<\/p>\n

codis-proxy:\u662f\u5ba2\u6237\u7aef\u8fde\u63a5\u7684Redis\u4ee3\u7406\u670d\u52a1\uff0ccodis-proxy \u672c\u8eab\u5b9e\u73b0\u4e86Redis\u534f\u8bae\uff0c\u8868\u73b0\u5f97\u548c\u4e00\u4e2a\u539f\u751f\u7684Redis\u6ca1\u4ec0\u4e48\u533a\u522b\uff08\u5c31\u50cfTwemproxy\uff09\uff0c\u5bf9\u4e8e\u4e00\u4e2a\u4e1a\u52a1\u6765\u8bf4\uff0c\u53ef\u4ee5\u90e8\u7f72\u591a\u4e2acodis-proxy\uff0ccodis-proxy\u672c\u8eab\u662f\u6ca1\u72b6\u6001\u7684\u3002<\/p>\n

codis-config:\u662fCodis\u7684\u7ba1\u7406\u5de5\u5177\uff0c\u652f\u6301\u5305\u62ec\uff0c\u6dfb\u52a0\/\u5220\u9664Redis\u8282\u70b9\uff0c\u6dfb\u52a0\/\u5220\u9664Proxy\u8282\u70b9\uff0c\u53d1\u8d77\u6570\u636e\u8fc1\u79fb\u7b49\u64cd\u4f5c\uff0ccodis-config\u672c\u8eab\u8fd8\u81ea\u5e26\u4e86\u4e00\u4e2ahttp server\uff0c\u4f1a\u542f\u52a8\u4e00\u4e2adashboard\uff0c\u7528\u6237\u53ef\u4ee5\u76f4\u63a5\u5728\u6d4f\u89c8\u5668\u4e0a\u89c2\u5bdfCodis\u96c6\u7fa4\u7684\u72b6\u6001\u3002<\/p>\n

codis-server:\u662fCodis\u9879\u76ee\u7ef4\u62a4\u7684\u4e00\u4e2aRedis\u5206\u652f\uff0c\u57fa\u4e8e2.8.13\u5f00\u53d1\uff0c\u52a0\u5165\u4e86slot\u7684\u652f\u6301\u548c\u539f\u5b50\u7684\u6570\u636e\u8fc1\u79fb\u6307\u4ee4\uff0cCodis\u4e0a\u5c42\u7684codis-proxy\u548ccodis-config\u53ea\u80fd\u548c\u8fd9\u4e2a\u7248\u672c\u7684Redis\u4ea4\u4e92\u624d\u80fd\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n

ZooKeeper:\u7528\u6765\u5b58\u653e\u6570\u636e\u8def\u7531\u8868\u548ccodis-proxy\u8282\u70b9\u7684\u5143\u4fe1\u606f\uff0ccodis-config\u53d1\u8d77\u7684\u547d\u4ee4\u90fd\u4f1a\u901a\u8fc7ZooKeeper\u540c\u6b65\u5230\u5404\u4e2a\u5b58\u6d3b\u7684codis-proxy<\/p>\n

\u6ce8\uff1aCodis\u652f\u6301\u6309\u7167Namespace\u533a\u5206\u4e0d\u540c\u7684\u4ea7\u54c1\uff0c\u62e5\u6709\u4e0d\u540c\u7684product name \u7684\u4ea7\u54c1\uff0c\u5404\u9879\u914d\u7f6e\u90fd\u4e0d\u4f1a\u51b2\u7a81\u3002<\/p>\n

2\u3001\u5b9e\u9a8c\u73af\u5883<\/strong><\/span><\/div>\n\n\n\n\n\n\n
\u4e3b\u673a\u540d<\/th>\nIP\u5730\u5740<\/th>\n\u89d2\u8272<\/th>\n<\/tr>\n
linux-node1<\/td>\n10.1.1.148<\/td>\nZookeeper\u3001redis_master,redis_slave<\/td>\n<\/tr>\n
linux-node2<\/td>\n10.1.1.149<\/td>\nZookeeper\u3001redis_master,redis_slave<\/td>\n<\/tr>\n
linux-node3<\/td>\n10.1.1.150<\/td>\nzookeeper,codis-proxy\u3001redis_master,redis_slave<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n

\u6ce8\uff1a\u751f\u4ea7\u73af\u5883\u5efa\u8baeredis\u653e\u5230\u5355\u72ec\u7684\u670d\u52a1\u5668\u4e0a\u9762<\/p>\n

3\u3001\u5b89\u88c5\u914d\u7f6e<\/strong><\/span><\/div>\n

\u6ce8\uff1a\u90e8\u7f72\u5355\u4e2acodis-proxy\u8282\u70b9\u7684\u73af\u5883\uff0c\u5efa\u8bae\u76f8\u5173\u7684\u5b89\u88c5\u5305\u672c\u5730\u4e0b\u8f7d\u5b8c\u4e0a\u4f20\u5230\u670d\u52a1\u5668\u4e0a\u9762\u3002<\/p>\n

#\u5728codis-proxy(linux-node3)\u670d\u52a1\u5668\u4e0a\u9762\u64cd\u4f5c<\/p>\n

yum install -y git gcc make g++ gcc-c++ automake openssl-devel zlib-devel<\/pre>\n
3.1\u3001\u5b89\u88c5GO<\/strong><\/span><\/div>\n

Go\u4e0b\u8f7d\u5730\u5740\uff1ahttp:\/\/www.golangtc.com\/download<\/p>\n

cd \/usr\/local\/src\/\r\ntar zxvf go1.7.linux-amd64.tar.gz -C \/opt<\/pre>\n

\u6ce8\u610f\uff1aZookeeper\u5df2\u642d\u5efa\u5b8c\u6210\u7684\u4e0b\u9762\u5b89\u88c5JDK\u548czookeeper\u7684\u6b65\u9aa4\u53ef\u4ee5\u8df3\u8fc7\u3002<\/p>\n

3.2\u3001\u5b89\u88c5JDK<\/strong>
\n<\/span><\/div>\n

JDK\u4e0b\u8f7d\u5730\u5740\uff1ahttp:\/\/www.oracle.com\/technetwork\/java\/javase\/downloads\/index.html<\/p>\n

rpm -ivh jdk-8u65-linux-x64.rpm<\/pre>\n
3.3\u3001\u5b89\u88c5zookeeper<\/strong>
\n<\/span><\/div>\n

Zookeeper\u4e0b\u8f7d\u5730\u5740\uff1ahttp:\/\/zookeeper.apache.org\/releases.html#download<\/p>\n

wget http:\/\/mirrors.cnnic.cn\/apache\/zookeeper\/zookeeper-3.4.8\/zookeeper-3.4.8.tar.gz\r\ntar zxvf zookeeper-3.4.8.tar.gz -C \/opt\/<\/pre>\n
3.4\u3001\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e<\/strong>
\n<\/span><\/div>\n

\u4fee\u6539\u73af\u5883\u53d8\u91cf\uff1avim \/etc\/profile \u5728\u6700\u540e\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9<\/p>\n

#codis path\r\nexport GOROOT=\/opt\/go\r\nexport GOPATH=\/opt\/codis\r\nJAVA_HOME=\/usr\/java\/jdk1.8.0_101\r\nCLASS_PATH=$JAVA_HOME\/lib:$JAVA_HOME\/jre\/lib\r\nexport PATH=$PATH:$GOROOT\/bin:$JAVA_HOME\/bin:<\/pre>\n

#\u6d4b\u8bd5\u73af\u5883\u53d8\u91cf\u8bbe\u7f6e
\n\"8-28-03\"<\/a><\/p>\n

#\u6267\u884csource \/etc\/profile\u662f\u73af\u5883\u53d8\u91cf\u751f\u6548\uff0c\u6d4b\u8bd5go\u662f\u5426\u6b63\u5e38\u5b89\u88c5\uff1a<\/p>\n

cat hello.go\r\npackage main\r\nimport \"fmt\"\r\nfunc main(){\r\nfmt.Printf(\"hello,world\\n\")\r\n}<\/pre>\n
[root@linux-node-2 ~]# go run hello.go\r\nhello,world!<\/pre>\n
\u4e09\u3001\u5b89\u88c5codis<\/strong><\/div>\n
[root@linux-node-3 ~]# yum -y install git\r\n[root@linux-node-3 opt]# go get -u -d github.com\/CodisLabs\/codis<\/pre>\n

\u53ef\u4ee5\u770b\u5230no buildable Go source files in \/opt\/codis\/src\/github.com\/wandoulabs\/codis\uff0c\u6211\u4eec\u5728\u4e0a\u9762\u73af\u5883\u5c31\u662f\u8bbe\u7f6eGOAPTH=\/opt\/codis\uff0c\u6240\u4ee5\u53ea\u8981\u6267\u884c\u4e0a\u9762\u7684\u83b7\u53d6\u547d\u4ee4\uff0c\u5c31\u4f1a\u4e0b\u8f7d\u5728\/opt\/codis\u4e0b\uff1a<\/p>\n

\"8-28-04\"<\/a><\/p>\n

\u6211\u4eec\u8fdb\u5230\u63d0\u793a\u7684\u8def\u5f84\u8fdb\u884c\u5b89\u88c5\uff0c\u5b89\u88c5\u8fc7\u7a0b\u6bd4\u8f83\u4e45\uff0c\u8010\u5fc3\u7b49\u5f85\uff1a<\/p>\n

[root@linux-node-3 ~]# cd \/opt\/codis\/src\/github.com\/CodisLabs\/codis<\/pre>\n

\u76ee\u5f55\u6267\u884cmake\u547d\u4ee4\u7f16\u8bd1\u4ee3\u7801\uff0c\u5e76\u6267\u884cmake gotest\u6765\u8dd1\u6d4b\u8bd5<\/p>\n

make<\/pre>\n

\"8-28-05\"<\/a><\/p>\n

make gotest<\/pre>\n

\"8-28-06\"<\/a><\/p>\n

\u5efa\u8bae\u53ea\u901a\u8fc7go get\u547d\u4ee4\u6765\u4e0b\u8f7dcodis\uff0c\u9664\u975e\u4f60\u975e\u5e38\u719f\u6089go\u8bed\u8a00\u7684\u76ee\u5f55\u5f15\u7528\u5f62\u5f0f\u4ece\u800c\u4e0d\u4f1a\u5bfc\u81f4\u4ee3\u7801\u653e\u9519\u5730\u65b9\u3002\u8be5\u547d\u4ee4\u4f1a\u4e0b\u8f7dmaster\u5206\u652f\u7684\u6700\u65b0\u7248\uff0c\u6211\u4eec\u4f1a\u786e\u4fddmaster\u5206\u652f\u7684\u7a33\u5b9a\u3002<\/strong><\/p>\n

\u6267\u884c\u5168\u90e8\u6307\u4ee4\u540e\uff0c\u4f1a\u5728 bin \u6587\u4ef6\u5939\u5185\u751f\u6210 codis-config\u3001codis-proxy\u3001codis-server\u4e09\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u53e6\u5916, bin\/assets \u6587\u4ef6\u5939\u662f codis-config \u7684 dashboard http \u670d\u52a1\u9700\u8981\u7684\u524d\u7aef\u8d44\u6e90, \u9700\u8981\u548c codis-config \u653e\u7f6e\u5728\u540c\u4e00\u6587\u4ef6\u5939\u4e0b)
\n
\"QQ\u56fe\u724720160903205049\"<\/a><\/p>\n

\u901a\u8fc7git\u65b9\u5f0f\u5b89\u88c5codis<\/strong><\/span><\/div>\n
git clone https:\/\/github.com\/CodisLabs\/codis.git<\/pre>\n

git\u4ed3\u5e93\u4e0b\u8f7d\u5b8c\u6bd5\u540e\uff0c\u6211\u4eec\u63a5\u4e0b\u6765\u8fdb\u884c\u5982\u4e0b\u7684\u64cd\u4f5c\u3002\u5982\u4e0b\uff1a<\/p>\n

mkdir -p \/opt\/codis \/src\/github.com\/CodisLabs\/\r\ncp -r codis \/opt\/codis\/src\/github.com\/CodisLabs\/\r\ncd \/opt\/codis\/src\/github.com\/CodisLabs\/codis\/<\/pre>\n

#\u4ee5\u4e0a\u64cd\u4f5c\u5b8c\u6bd5\u540e\uff0c\u5c31\u548c\u901a\u8fc7go\u4e0b\u8f7d\u5b89\u88c5\u65b9\u5f0f\u4e00\u6837,\u6267\u884cmake\u547d\u4ee4\u8fdb\u884c\u7f16\u8bd1\uff0c\u7136\u540e\u6267\u884cmake gotest\u547d\u4ee4\u8fdb\u884c\u6d4b\u8bd5<\/p>\n

\u901a\u8fc7\u6e90\u7801\u5305\u5b89\u88c5<\/strong><\/span><\/div>\n
wget https:\/\/github.com\/CodisLabs\/codis\/archive\/3.0.3.tar.gz -P \/usr\/local\/src\r\ntar zxvf 3.0.3.tar.gz && cd codis-3.0.3 && make && make gotest<\/pre>\n
codis\u76f8\u5173\u914d\u7f6e\u6587\u4ef6\u8be6\u89e3<\/strong><\/span><\/div>\n

#codis\u5b89\u88c5\u5b8c\u6210\u4e4b\u540ecodis-config\u4e3b\u8981\u7684\u4f7f\u7528\u65b9\u6cd5<\/p>\n

# .\/bin\/codis-config -h (master)\r\nusage: codis-config [-c ] [-L ] [--log-level=]\r\n [...]\r\n options:\r\n -c \u914d\u7f6e\u6587\u4ef6\u5730\u5740\r\n -L \u65e5\u5fd7\u8f93\u51fa\u6587\u4ef6\u5730\u5740\r\n --log-level= \u8f93\u51fa\u65e5\u5fd7\u7ea7\u522b (debug < info (default) < warn < error < fatal)\r\ncommands:\r\nserver redis \u670d\u52a1\u5668\u7ec4\u7ba1\u7406\r\nslot slot \u7ba1\u7406\r\ndashboard \u542f\u52a8 dashboard \u670d\u52a1\r\naction \u4e8b\u4ef6\u7ba1\u7406 (\u76ee\u524d\u53ea\u6709\u5220\u9664\u5386\u53f2\u4e8b\u4ef6\u7684\u65e5\u5fd7)\r\nproxy proxy \u7ba1\u7406<\/pre>\n
# .\/bin\/codis-proxy -h\r\nusage: codis-proxy [-c ] [-L ] [--log-level=] [--cpu=] [--addr=] [--http-addr=]\r\n\r\noptions:\r\n-c \u914d\u7f6e\u6587\u4ef6\u5730\u5740\r\n-L \u65e5\u5fd7\u8f93\u51fa\u6587\u4ef6\u5730\u5740\r\n--log-level= \u8f93\u51fa\u65e5\u5fd7\u7ea7\u522b (debug < info (default) < warn < error < fatal)\r\n--cpu= proxy\u5360\u7528\u7684 cpu \u6838\u6570, \u9ed8\u8ba41, \u6700\u597d\u8bbe\u7f6e\u4e3a\u673a\u5668\u7684\u7269\u7406cpu\u6570\u7684\u4e00\u534a\u52302\/3\u5de6\u53f3\r\n--addr= proxy \u7684 redis server \u76d1\u542c\u7684\u5730\u5740, \u683c\u5f0f :, \u5982: localhost:9000, :9001\r\n--http-addr= proxy \u7684\u8c03\u8bd5\u4fe1\u606f\u542f\u52a8\u7684http server, \u53ef\u4ee5\u8bbf\u95ee http:\/\/debug_http_server_addr\/debug\/vars\r\n<\/pre>\n
\u56db\u3001\u914d\u7f6ecodis\u96c6\u7fa4<\/strong><\/div>\n

codis\u5b89\u88c5\u5b8c\u6bd5\u540e\uff0c\u6211\u4eec\u73b0\u5728\u6765\u914d\u7f6ecodis\u96c6\u7fa4\uff0c\u5728\u6b63\u5f0f\u914d\u7f6e\u96c6\u7fa4\u4e4b\u524d\uff0c\u5148\u521b\u5efa\u76f8\u5173\u7684\u76ee\u5f55\uff0c\u7136\u540e\u590d\u5236\u76f8\u5173\u6587\u4ef6\u5230\u65b0\u7684\u76ee\u5f55\u4e0b\u3002<\/p>\n

1\u3001codis\u96c6\u7fa4\u914d\u7f6e<\/strong><\/span><\/div>\n

\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\uff1a<\/p>\n

cd \/opt\/codis\/src\/github.com\/CodisLabs\/codis\/\r\nmkdir -p \/opt\/codis\/{log,redis_conf}\r\ncp -rf bin\/ \/opt\/codis\/\r\ncp config.ini \/opt\/codis\/\r\ncp extern\/redis-test\/conf\/6379.conf \/opt\/codis\/redis_conf\/\r\ncp extern\/redis-test\/conf\/6380.conf \/opt\/codis\/redis_conf\/<\/pre>\n

\"8-28-07\"<\/a><\/p>\n

2\u3001\u7f16\u8f91codis\u914d\u7f6e\u6587\u4ef6<\/strong><\/span><\/div>\n
[root@linux-node3 codis]# egrep -v \"^#|^$\" config.ini<\/pre>\n
coordinator=zookeeper\r\nzk=192.168.1.148:2181,192.168.1.149:2181,192.168.1.150:2181\r\nproduct=test\r\ndashboard_addr=192.168.1.150:18087\r\npassword=\r\nbackend_ping_period=5\r\nsession_max_timeout=1800\r\nsession_max_bufsize=131072\r\nsession_max_pipeline=1024\r\nzk_session_timeout=30000\r\nproxy_id=proxy_3<\/pre>\n

\u8be5\u914d\u7f6e\u6587\u4ef6\u4e2d\uff0c\u6211\u4eec\u9700\u8981\u6ce8\u610f\u4e09\u4e2a\u53c2\u6570\uff1azk\u3001dashboard_addr\u3001proxy_id\u3002<\/p>\n

\u5176\u4e2dzk\u662f\u8868\u793azookeeper\u96c6\u7fa4\u7684\u670d\u52a1\u5668IP\u5730\u5740\uff0cdashboard_addr\u8868\u793acodis web\u7ba1\u7406\u7684IP\u5730\u5740\u53ca\u7aef\u53e3\uff0cproxy_id\u8868\u793acodis\u7684id\uff0c\u6ce8\u610f\u6bcf\u53f0codis\u670d\u52a1\u5668\u8be5\u503c\u8981\u552f\u4e00\u3002<\/p>\n

#linux-node1<\/strong><\/span><\/div>\n

\"8-28-08\"<\/a><\/p>\n

#linux-node2<\/strong><\/span><\/div>\n

\"8-28-09\"<\/a><\/p>\n

#linux-node3<\/strong><\/span><\/div>\n

\"8-28-10\"<\/a><\/p>\n

3\u3001\u7f16\u8f91redis\u914d\u7f6e\u6587\u4ef6<\/strong><\/span><\/div>\n

\u6bcf\u53f0codis\u670d\u52a1\u5668\u4e0a\uff0c\u542f\u52a8\u4e24\u4e2aredis\u5b9e\u4f8b\uff08\u4e5f\u53ef\u4ee5\u542f\u52a8\u591a\u4e2aredis\u5b9e\u4f8b\uff09\uff0c\u914d\u7f6e\u4e24\u4e2aredis\uff0c\u5982\u4e0b\uff1a<\/p>\n

daemonize no\r\npidfile \/var\/run\/redis.pid\r\nport 6379<\/span>\r\ntcp-backlog 511\r\ntimeout 0\r\ntcp-keepalive 0\r\nloglevel notice\r\nlogfile \/var\/log\/redis\/6379.log<\/span>\r\ndatabases 16\r\nstop-writes-on-bgsave-error yes\r\nrdbcompression yes\r\nrdbchecksum yes\r\ndbfilename dump6379.rdb\r\ndir \/opt\/codis\/<\/span>\r\nslave-serve-stale-data yes\r\nslave-read-only yes\r\nrepl-disable-tcp-nodelay no\r\nslave-priority 100\r\nappendonly no\r\nappendfilename \"appendonly.aof\"\r\nappendfsync everysec\r\nno-appendfsync-on-rewrite no\r\nauto-aof-rewrite-percentage 100\r\nauto-aof-rewrite-min-size 64mb\r\nlua-time-limit 5000\r\nslowlog-log-slower-than 10000\r\nslowlog-max-len 128\r\nlatency-monitor-threshold 0\r\nnotify-keyspace-events \"\"\r\nhash-max-ziplist-entries 512\r\nhash-max-ziplist-value 64\r\nlist-max-ziplist-entries 512\r\nlist-max-ziplist-value 64\r\nset-max-intset-entries 512\r\nzset-max-ziplist-entries 128\r\nzset-max-ziplist-value 64\r\nhll-sparse-max-bytes 3000\r\nactiverehashing yes\r\nclient-output-buffer-limit normal 0 0 0\r\nclient-output-buffer-limit slave 256mb 64mb 60\r\nclient-output-buffer-limit pubsub 32mb 8mb 60\r\nhz 10\r\naof-rewrite-incremental-fsync yes<\/pre>\n

#\u6ce8\u610f\u7ea2\u7ebf\u6807\u6ce8\u7684\u4e00\u4e2a\u53c2\u6570\uff0c\u914d\u7f6e\u7b2c\u4e8c\u4e2aredis\u5b9e\u4f8b<\/p>\n

\\cp \/opt\/codis\/redis_conf\/6379.conf 6380.conf\r\nsed -i 's\/6379\/6380\/g' \/opt\/codis\/redis_conf\/6380.conf\r\nmkdir -p \/var\/log\/redis\/<\/pre>\n

#\u4e0a\u9762\u64cd\u4f5c\u9700\u8981\u5728\u6bcf\u53f0codis\u670d\u52a1\u4e0a\u9762\u90fd\u6267\u884c\u3002<\/p>\n

echo 512 > \/proc\/sys\/net\/core\/somaxconn\r\nsysctl vm.overcommit_memory=1<\/pre>\n

\u6ce8\uff1a\u4f18\u5316\u7cfb\u7edf\u7684\u53c2\u6570<\/p>\n

4\u3001 \u521d\u59cb\u5316 slots<\/strong><\/span><\/div>\n

\u6267\u884c bin\/codis-config slot init\uff0c\u8be5\u547d\u4ee4\u4f1a\u5728zookeeper\u4e0a\u521b\u5efaslot\u76f8\u5173\u4fe1\u606f<\/p>\n

\/opt\/codis\/bin\/codis-config -c \/opt\/codis\/config.ini slot init<\/pre>\n

#linux-node3\u3001linux-node1\u3001linux-node2<\/p>\n

\/opt\/codis\/bin\/codis-server \/opt\/codis\/redis_conf\/6379.conf &\r\n\/opt\/codis\/bin\/codis-server \/opt\/codis\/redis_conf\/6380.conf &\r\nps -ef | grep codis-server<\/pre>\n

\"8-28-11\"<\/a><\/p>\n

#\u5728\u4e09\u53f0codis-proxy\u4e0a\u9762\u5206\u522b\u542f\u52a8redis\u5b9e\u4f8b<\/p>\n

5\u3001\u542f\u52a8codis dashboard<\/strong><\/span><\/div>\n

#\u5c3d\u91cf\u5728redis\u5b89\u88c5\u76ee\u5f55\u6216\u8005\u8ba9redi\u7684log\u76ee\u5f55\u4e0b\u542f\u52a8dashboard\uff0c\u8fd9\u6837\u65b9\u4fbf\u67e5\u770b\u542f\u52a8\u4ea7\u751f\u7684\u65e5\u5fd7\uff0cnohup.out<\/p>\n

nohup \/opt\/codis\/bin\/codis-config -c \/opt\/codis\/config.ini dashboard &<\/pre>\n

\"8-28-12\"<\/a><\/p>\n

#\u4ece\u56fe\u4e2d\u53ef\u4ee5\u770b\u51fadashboard\u5df2\u7ecf\u542f\u52a8\u5b8c\u6210\uff0c\u7136\u540e\u53bbweb\u9875\u9762\u8bbf\u95ee\uff0ccodis dashboard\u8bbf\u95ee\u7aef\u53e3\u662f18087<\/p>\n

#\u67e5\u770bcodis dashboard\uff0c\u6d4f\u89c8\u5668\u8bbf\u95eehttp:\/\/192.168.1.150:18087\/\uff0c\u5982\u4e0b\uff1a
\n
\"08-28-13\"<\/a><\/p>\n

#codis dashboard\u542f\u52a8\u5b8c\u6210\u4e4b\u540e\u9ed8\u8ba4\u9875\u9762\u5982\u4e0a\u56fe\u6240\u793a\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7web\u9875\u9762\u65b0\u5efaredis_group\uff0c\u628a\u521a\u521a\u542f\u52a8\u597d\u7684redis\u5b9e\u4f8b\u52a0\u5230\u4e0d\u540c\u7684\u7ec4\u5f53\u4e2d\u3001\u4e5f\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u6267\u884c\u521b\u5efaredis_group\u7684\u64cd\u4f5c\u3002<\/span><\/p>\n

6\u3001\u6dfb\u52a0 Redis Server Group<\/strong><\/span><\/div>\n

# \u6bcf\u4e00\u4e2a Server Group \u4f5c\u4e3a\u4e00\u4e2aRedis\u670d\u52a1\u5668\u7ec4\u5b58\u5728, \u53ea\u5141\u8bb8\u6709\u4e00\u4e2amaster, \u53ef\u4ee5\u6709\u591a\u4e2aslave, group id\u4ec5\u652f\u6301\u5927\u4e8e\u7b49\u4e8e1\u7684\u6574\u6570<\/p>\n

#\u5728codis dashboard\u4e0a\u4f7f\u7528\u547d\u4ee4\u65b0\u5efaserver group<\/p>\n

[root@linux-node3 ~]# cd \/opt\/codis\/\r\n[root@linux-node3 codis]# .\/bin\/codis-config server -h\r\nusage:\r\ncodis-config server list\r\ncodis-config server add\r\ncodis-config server remove\r\ncodis-config server promote\r\ncodis-config server add-group\r\ncodis-config server remove-group<\/pre>\n

#\u5982: \u6dfb\u52a0\u4e09\u4e2a server group, \u6bcf\u4e2a group \u6709\u4e24\u4e2a redis \u5b9e\u4f8b\uff0cgroup\u7684id\u5206\u522b\u4e3a1\u548c2\uff0c redis\u5b9e\u4f8b\u4e3a\u4e00\u4e3b\u4e00\u4ece\u3002<\/p>\n

#\u6ce8\uff1a\u8fd9\u91cc\u6211\u628alinux-node3\uff0clinux-node2\uff0clinux-node1\u4e0a\u9762\u7684\u4e24\u4e2aredis\u5b9e\u4f8b\u5206\u522b\u52a0\u5230\u4e0d\u540c\u7684server group\u5f53\u4e2d\uff0c\u8be6\u7ec6\u5982\u4e0b\uff1a<\/p>\n

group_1: linux-node3 redis_6379 linux-node2 redis_6380\r\ngroup_2: linux-node2 redis_6379 linux-node1 redis_6380\r\ngroup_3: linux-node1 redis_5379 linux-node3 redis_6380<\/pre>\n

\u5176\u4e2dredis\u76846379\u7aef\u53e3\u4f5c\u4e3aredis master\uff0c6380\u4f5c\u4e3aslave<\/p>\n

#\u6dfb\u52a0\u4e00\u4e2agroup\uff0cgroup\u7684id\u4e3a1\uff0c \u5e76\u6dfb\u52a0\u4e00\u4e2aredis master\uff08192.168.1.150:6379\uff09\u5230\u8be5group<\/p>\n

.\/bin\/codis-config server add 1 192.168.1.150:6379 master<\/pre>\n

#\u6dfb\u52a0\u4e00\u4e2aredis slave(192.168.1.149:6380)\u5230\u8be5group<\/p>\n

.\/bin\/codis-config server add 1 192.168.1.149:6380 slave<\/pre>\n

\"8-28-13\"<\/a><\/p>\n

#\u6dfb\u52a0\u4e00\u4e2agroup\uff0cgroup\u7684id\u4e3a2\uff0c \u5e76\u6dfb\u52a0\u4e00\u4e2aredis master\uff08192.168.1.149:6379\uff09\u5230\u8be5group<\/p>\n

.\/bin\/codis-config server add 2 192.168.1.149:6379 master<\/pre>\n

#\u6dfb\u52a0\u4e00\u4e2aredis slave(192.168.1.148:6380)\u5230\u8be5group<\/p>\n

.\/bin\/codis-config server add 2 192.168.1.148:6380 slave<\/pre>\n

#\u6dfb\u52a0\u4e00\u4e2agroup\uff0cgroup\u7684id\u4e3a3\uff0c \u5e76\u6dfb\u52a0\u4e00\u4e2aredis master\uff08192.168.1.148:6379\uff09\u5230\u8be5group<\/p>\n

.\/bin\/codis-config server add 3 192.168.1.148:6379 master<\/pre>\n

#\u6dfb\u52a0\u4e00\u4e2aredis slave(192.168.1.150:6380)\u5230\u8be5group<\/p>\n

.\/bin\/codis-config server add 3 192.168.1.150:6380 slave<\/pre>\n

\"8-28-14\"
\n\"8-28-15\"<\/a><\/p>\n

\u6ce8\u610f\uff1a\u6bcf\u7ec4\u6dfb\u52a0\u7684\u7b2c\u4e00\u4e2aredis\u5b9e\u4f8b\u4e0d\u80fd\u88ab\u5220\u9664\uff0c\u56e0\u4e3acodis\u9ed8\u8ba4\u628a\u8be5redis\u5b9e\u4f8b\u8bbe\u7f6e\u4e3amaster\u3002<\/p>\n

#\u4ece\u56fe\u4e2d\u6211\u4eec\u53ef\u4ee5\u770b\u51faserver group \u5df2\u7ecf\u521b\u5efa\u6210\u529f\uff0c\u5230codis dashboard\u4e0a\u9762\u67e5\u770b\uff1a
\n
\"08-28-16\"<\/a><\/p>\n

7\u3001\u8bbe\u7f6e server group \u670d\u52a1\u7684 slot \u8303\u56f4\uff0c<\/strong><\/span><\/div>\n
https:\/\/github.com\/CodisLabs\/codis\/blob\/master\/doc\/FAQ_zh.md<\/pre>\n

Codis \u91c7\u7528 Pre-sharding \u7684\u6280\u672f\u6765\u5b9e\u73b0\u6570\u636e\u7684\u5206\u7247, \u9ed8\u8ba4\u5206\u6210 1024 \u4e2a slots (0-1023), \u5bf9\u4e8e\u6bcf\u4e2akey\u6765\u8bf4, \u901a\u8fc7\u4ee5\u4e0b\u516c\u5f0f\u786e\u5b9a\u6240\u5c5e\u7684 Slot Id : SlotId = crc32(key) % 1024 \u6bcf\u4e00\u4e2a slot \u90fd\u4f1a\u6709\u4e00\u4e2a\u4e14\u5fc5\u987b\u6709\u4e00\u4e2a\u7279\u5b9a\u7684 server group id \u6765\u8868\u793a\u8fd9\u4e2a slot \u7684\u6570\u636e\u7531\u54ea\u4e2a server group \u6765\u63d0\u4f9b.<\/p>\n

[root@linux-node3 codis]# .\/bin\/codis-config slot -h\r\nusage:\r\ncodis-config slot init [-f]\r\ncodis-config slot info\r\ncodis-config slot set\r\ncodis-config slot range-set\r\ncodis-config slot migrate [--delay=]\r\ncodis-config slot rebalance [--delay=]<\/pre>\n

#\u8bbe\u7f6e\u7f16\u53f7\u4e3a[0, 340]\u7684 slot \u7531 server group 1 \u63d0\u4f9b\u670d\u52a1, \u7f16\u53f7 [341, 682] \u7684 slot \u7531 server group 2 \u63d0\u4f9b\u670d\u52a1\uff0c\u7f16\u53f7[683, 1023] \u7684 slot \u7531 server group 3 \u63d0\u4f9b\u670d\u52a1<\/p>\n

.\/bin\/codis-config slot range-set 0 340 1 online\r\n.\/bin\/codis-config slot range-set 341 682 2 online\r\n.\/bin\/codis-config slot range-set 683 1023 3 online<\/pre>\n

\"8-28-17\"<\/a><\/p>\n

#\u67e5\u770bslot\u7684\u4fe1\u606f<\/strong><\/span><\/div>\n
\/opt\/codis\/bin\/codis-config -c \/opt\/codis\/config.ini slot info 1\r\n\/opt\/codis\/bin\/codis-config -c \/opt\/codis\/config.ini slot info 2\r\n\/opt\/codis\/bin\/codis-config -c \/opt\/codis\/config.ini slot info 3<\/pre>\n

#slot\u64cd\u4f5c\u5b8c\u6210\u53ef\u4ee5\u5230codis dashboard\u67e5\u770b\u72b6\u6001\u3002\u5982\u4e0b\uff1a<\/p>\n

\"8-28-19\"<\/a><\/p>\n

8\u3001\u542f\u52a8 codis-proxy<\/strong><\/span><\/div>\n
.\/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<\/pre>\n

\"8-28-20\"<\/a><\/p>\n

nohup \/opt\/codis\/bin\/codis-proxy -c \/opt\/codis\/config.ini --log-level=error -L \/opt\/codis\/log\/proxy.log --cpu=1 --addr=0.0.0.0:19000 --http-addr=0.0.0.0:11000 &<\/span><\/p>\n

#\u4e0b\u9762\u5bf9\u4ee5\u4e0a\u547d\u4ee4\u4e2d\u7684\u53c2\u6570\u8fdb\u884c\u89e3\u91ca\uff1a<\/p>\n

-c \u914d\u7f6e\u6587\u4ef6\u5730\u5740\u3002\r\n-L \u65e5\u5fd7\u8f93\u51fa\u6587\u4ef6\u5730\u5740\u3002\r\n\u2013log-level= \u8f93\u51fa\u65e5\u5fd7\u7ea7\u522b(debug \u2013cpu= proxy\u5360\u7528\u7684cpu\u6838\u6570,\u9ed8\u8ba41,\u6700\u597d\u8bbe\u7f6e\u4e3a\u673a\u5668\u7684\u7269\u7406cpu\u6570\u7684\u4e00\u534a\u52302\/3\u5de6\u53f3\u3002\r\n\u2013addr= proxy\u7684redis server\u76d1\u542c\u7684\u5730\u5740, \u683c\u5f0f:, \u5982: localhost:9000, :9001\u3002\r\n\u2013http-addr= proxy\u7684\u8c03\u8bd5\u4fe1\u606f\u542f\u52a8\u7684http server,\u53ef\u4ee5\u8bbf\u95ee http:\/\/debug_http_server_addr\/debug\/vars\u3002<\/pre>\n

\"8-28-21\"<\/a><\/p>\n

#codis-proxy\u542f\u52a8\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5728dashboard\u4e0a\u8fdb\u884c\u67e5\u770b\uff0c\u5982\u4e0b\uff1a<\/p>\n

\"8-28-22\"<\/a><\/p>\n

#\u5230\u6b64codis\u96c6\u7fa4\u642d\u5efa\u5b8c\u6bd5\uff0c\u4e3a\u4e86\u6027\u80fd\u9700\u6c42\uff0c\u5efa\u8baeredis\u5b9e\u4f8b\u548ccodis-proxy\u653e\u5230\u4e0d\u540c\u7684\u670d\u52a1\u5668\u4e0a\u9762\u3002<\/p>\n

9\u3001\u8fde\u63a5codis\u96c6\u7fa4<\/strong><\/span><\/div>\n

codis\u96c6\u7fa4\u642d\u5efa\u5b8c\u6bd5\u540e\uff0c\u6d4b\u8bd5\u8fde\u63a5codis\u96c6\u7fa4\u3002\u8981\u8fde\u63a5codis\u96c6\u7fa4\uff0c\u6211\u4eec\u53ea\u9700\u8981\u8fde\u63a5codis-proxy\u5373\u53ef\u3002codis-proxy\u670d\u52a1\u5668\u5730\u5740\uff1a192.168.1.150\uff0c\u7136\u540e\u52a019000\u7aef\u53e3\u3002\u4f7f\u7528redis-cli\u547d\u4ee4\u8fde\u63a5\uff0c\u5982\u4e0b\uff1a<\/p>\n

#\u5728\u67d0\u53f0\u5df2\u5b89\u88c5redis\u5b9e\u4f8b\u7684\u670d\u52a1\u5668\u4e0a\u9762\u6d4b\u8bd5\uff1a
\n
\"8-28-23\"<\/a><\/p>\n

\u901a\u8fc7\u4e0a\u56fe\uff0c\u6211\u4eec\u53ef\u4ee5\u5f88\u660e\u663e\u7684\u770b\u5230\u8fde\u63a5codis\u96c6\u7fa4\u662fok\u7684\u3002<\/p>\n

10\u3001codis\u96c6\u7fa4\u538b\u6d4b<\/strong><\/span><\/div>\n

\u6211\u4eec\u73b0\u5728\u5bf9codis\u96c6\u7fa4\u505a\u4e00\u4e9b\u538b\u529b\u6d4b\u8bd5\uff0c\u540c\u65f6\u5728dashboard\u4e0a\u89c2\u5bdf\u952e\u503c\u5bf9\u7684\u60c5\u51b5\u3002\u5982\u4e0b\uff1a<\/p>\n

.\/redis-benchmark -h 192.168.1.150 -p 19000 -c 1000 -d 1000 -t set -n 100000 -r 100000<\/pre>\n

\u4e0a\u8ff0\u547d\u4ee4\u7684\u610f\u601d\u662f\uff0c\u4f7f\u7528redis-benchmark\u538b\u529b\u6d4b\u8bd5\u547d\u4ee4\u8fde\u63a5codis\u96c6\u7fa4\uff0c\u540c\u65f6\u5e76\u53d110000\u4e2a\uff08-c\uff09\uff0c\u6d4b\u8bd5set\u64cd\u4f5c(-t)\uff0c\u6bcf\u4e2a\u6d4b\u8bd5\u6570\u636e\u96c6\u662f100\u5b57\u8282(-d),\u8bf7\u6c42\u6570\u662f100000\uff08-n\uff09\uff0c\u4f7f\u7528\u4f7f\u7528\u968f\u673a\u6570\u63d2\u5165\u6570\u503c\uff08-r\uff09<\/p>\n

11\u3001\u6570\u636e\u8fc1\u79fb<\/strong><\/span><\/div>\n

\u5b89\u5168\u548c\u900f\u660e\u7684\u6570\u636e\u8fc1\u79fb\u662f Codis \u63d0\u4f9b\u7684\u4e00\u4e2a\u91cd\u8981\u7684\u529f\u80fd, \u4e5f\u662f Codis \u533a\u522b\u4e8e Twemproxy \u7b49\u9759\u6001\u7684\u5206\u5e03\u5f0f Redis \u89e3\u51b3\u65b9\u6848\u7684\u5730\u65b9
\n\u6570\u636e\u8fc1\u79fb\u7684\u6700\u5c0f\u5355\u4f4d\u662f key, \u6211\u4eec\u5728 codis redis \u4e2d\u6dfb\u52a0\u4e86\u4e00\u4e9b\u6307\u4ee4, \u5b9e\u73b0\u57fa\u4e8ekey\u7684\u8fc1\u79fb, \u5982 SLOTSMGRT\u7b49 (\u547d\u4ee4\u5217\u8868), \u6bcf\u6b21\u4f1a\u5c06\u7279\u5b9a slot \u4e00\u4e2a\u968f\u673a\u7684 key \u53d1\u9001\u7ed9\u53e6\u5916\u4e00\u4e2a codis redis \u5b9e\u4f8b, \u8fd9\u4e2a\u547d\u4ee4\u4f1a\u786e\u8ba4\u5bf9\u65b9\u5df2\u7ecf\u63a5\u6536, \u540c\u65f6\u5220\u9664\u672c\u5730\u7684\u8fd9\u4e2a k-v \u952e\u503c, \u8fd4\u56de\u8fd9\u4e2a slot \u7684\u5269\u4f59 key \u7684\u6570\u91cf, \u6574\u4e2a\u64cd\u4f5c\u662f\u539f\u5b50\u7684.<\/p>\n

\u5728 codis-config \u7ba1\u7406\u5de5\u5177\u4e2d, \u6bcf\u6b21\u8fc1\u79fb\u4efb\u52a1\u7684\u6700\u5c0f\u5355\u4f4d\u662f slot
\n\u5982: \u5c06slot id \u4e3a [0-340] \u7684slot\u7684\u6570\u636e, \u8fc1\u79fb\u5230 server group 2\u4e0a, --delay \u53c2\u6570\u8868\u793a\u6bcf\u8fc1\u79fb\u4e00\u4e2a key \u540e sleep \u7684\u6beb\u79d2\u6570, \u9ed8\u8ba4\u662f 0, \u7528\u4e8e\u9650\u901f.<\/p>\n

#codis dashboard\u4e0a\u9762\u67e5\u770b\u6bcf\u4e2a\u7ec4\u4e2d\u7684\u6570\u636e\u72b6\u6001\uff0c
\n
\"8-28-24\"<\/a><\/p>\n

#\u53ef\u4ee5\u770b\u51fa\u521a\u521a\u6211\u4eec\u505a\u8fc7\u538b\u6d4b\u4e4b\u540e\uff0c\u6bcf\u4e2aredis\u7ec4\u5904\u7406\u7684key\u57fa\u672c\u4e00\u81f4\uff0c\u7136\u540e\u6211\u4eec\u628agroup_1\u4e2dslot\u4e0a\u7684\u6570\u636e\u8fc1\u79fb\u5230group_2\u4e0a\uff0c--delay \u53c2\u6570\u8868\u793a\u6bcf\u8fc1\u79fb\u4e00\u4e2a key \u540e sleep \u7684\u6beb\u79d2\u6570, \u9ed8\u8ba4\u662f 0, \u7528\u4e8e\u9650\u901f.<\/p>\n

$ bin\/codis-config slot migrate 0 511 2 --delay=10<\/pre>\n

\"8-28-25\"<\/a><\/p>\n

\/opt\/codis\/bin\/codis-config -c \/opt\/codis\/config.ini slot migrate 0 340 2 --delay=10<\/pre>\n

#\u67e5\u770bcodis dashboard\u4e0a\uff0cgroup\u72b6\u6001\uff1a
\n
\"8-28-26\"<\/a><\/p>\n

#\u518d\u6b21\u5237\u65b0\uff0c3s\u540e
\n
\"8-28-27\"<\/a><\/p>\n

#\u5bf9\u6bd4group\u4e2d\u4e24\u6b21\u7684key\u53d8\u5316\uff0c\u6211\u4eec\u53ef\u4ee5\u770b\u51fagroup_1\u4e2d\u7684slot\u6570\u636e\u6b63\u5728\u5411group_2\u8fc1\u79fb\u3002<\/p>\n

\u8fc1\u79fb\u7684\u8fc7\u7a0b\u5bf9\u4e8e\u4e0a\u5c42\u4e1a\u52a1\u6765\u8bf4\u662f\u5b89\u5168\u4e14\u900f\u660e\u7684, \u6570\u636e\u4e0d\u4f1a\u4e22\u5931, \u4e0a\u5c42\u4e0d\u4f1a\u4e2d\u6b62\u670d\u52a1.<\/p>\n

\u6ce8\u610f, \u8fc1\u79fb\u7684\u8fc7\u7a0b\u4e2d\u6253\u65ad\u662f\u53ef\u4ee5\u7684, \u4f46\u662f\u5982\u679c\u4e2d\u65ad\u4e86\u4e00\u4e2a\u6b63\u5728\u8fc1\u79fb\u67d0\u4e2aslot\u7684\u4efb\u52a1, \u4e0b\u6b21\u9700\u8981\u5148\u8fc1\u79fb\u6389\u6b63\u5904\u4e8e\u8fc1\u79fb\u72b6\u6001\u7684 slot, \u5426\u5219\u65e0\u6cd5\u7ee7\u7eed (\u5373\u8fc1\u79fb\u7a0b\u5e8f\u4f1a\u68c0\u67e5\u540c\u4e00\u65f6\u523b\u53ea\u80fd\u6709\u4e00\u4e2a slot \u5904\u4e8e\u8fc1\u79fb\u72b6\u6001).<\/p>\n

Auto Rebalance<\/strong><\/span><\/div>\n

Codis \u652f\u6301\u52a8\u6001\u7684\u6839\u636e\u5b9e\u4f8b\u5185\u5b58, \u81ea\u52a8\u5bf9slot\u8fdb\u884c\u8fc1\u79fb, \u4ee5\u5747\u8861\u6570\u636e\u5206\u5e03.<\/p>\n

$ bin\/codis-config slot rebalance<\/pre>\n

\u8981\u6c42:<\/p>\n

\u6240\u6709\u7684codis-server\u90fd\u5fc5\u987b\u8bbe\u7f6e\u4e86maxmemory\u53c2\u6570\r\n\u6240\u6709\u7684 slots \u90fd\u5e94\u8be5\u5904\u4e8e online \u72b6\u6001, \u5373\u6ca1\u6709\u8fc1\u79fb\u4efb\u52a1\u6b63\u5728\u6267\u884c\r\n\u6240\u6709 server group \u90fd\u5fc5\u987b\u6709 Master<\/pre>\n
\u4e94\u3001Codis\u96c6\u7fa4\u67b6\u6784\u6a21\u62df\u6545\u969c\u6d4b\u8bd5<\/strong><\/div>\n

Server group\u5b9e\u73b0\u4e3b\u4ece\u5207\u6362\uff0c\u5f53\u540c\u4e00\u4e2a\u7ec4\u4e2d\u7684\u67d0\u4e00\u53f0redis\u5b9e\u4f8b\u505c\u6b62\u7684\u65f6\u5019,\u7ec4\u4e2d\u7684\u5176\u5b83redis\u5b9e\u4f8b\u81ea\u52a8\u5207\u6362\u4e3amaster\u89d2\u8272\uff0c\u63d0\u4f9b\u670d\u52a1\u3002<\/p>\n

\u9700\u8981\u5b89\u88c5codis-ha\u63d2\u4ef6\uff0ccodis-ha\u53ef\u4ee5\u5b89\u88c5\u5728\u4efb\u610f\u8282\u70b9\u5373\u53ef\uff0c\u53ea\u9700\u8981\u5728\u4e00\u4e2a\u8282\u70b9\u4e0a\u9762\u5b89\u88c5\u3002\uff08\u672c\u5b9e\u9a8c\u5b89\u88c5\u5728linux-node2\u4e0a\uff09<\/p>\n

go get github.com\/ngaut\/codis-ha\r\n[root@linux-node2 ~]# cd \/opt\/codis\/src\/github.com\/ngaut\/\r\n[root@linux-node2 ngaut]# cp -r codis-ha \/opt\/\r\n[root@linux-node2 ngaut]# cd \/opt\/codis-ha\/\r\n[root@linux-node2 codis-ha]# go build<\/pre>\n
1\u3001\u542f\u52a8codis-ha\u670d\u52a1<\/strong><\/span><\/div>\n
nohup $codis_ha_home\/codis-ha -codis-config=192.168.1.150:18087 -log-level=info -productName=test &> \/opt\/codis-ha\/codis-ha.log<\/pre>\n

\u6ce8\uff1a-codis-config\u540e\u8ddfdashboard\u6240\u5728\u670d\u52a1\u5668ip<\/p>\n

\u91cd\u65b0\u542f\u52a8codis-proxy\u670d\u52a1<\/p>\n

\u6ce8\uff1a\uff08\u4ee5150\u673a\u5668\u914d\u7f6e\u4e3a\u4f8b\uff0c\u5176\u4f59codis-proxy\u53ea\u9700\u8981\u4fee\u6539\u4e0b\u540d\u79f0\u5373\u53ef\uff09<\/p>\n

\u5148\u505c\u6389codis-proxy<\/strong><\/p>\n

[root@linux-node3 ~]# \/opt\/codis\/bin\/codis-config -c \/opt\/codis\/config.ini proxy offline codis_proxy_3<\/pre>\n

#\u4e0d\u540c\u7684\u673a\u5668\u53ea\u9700\u8981\u66f4\u6539codis_proxy\u5373\u53ef\uff08\u672c\u5b9e\u9a8c\u4e4b\u91cd\u542f\u4e86\u4e00\u53f0codis-proxy\uff0c\u4e14codis-ha\u670d\u52a1\u5df2\u751f\u6548\uff09<\/p>\n

\u91cd\u65b0\u542f\u52a8codis-proxy<\/strong><\/p>\n

nohup \/opt\/codis\/bin\/codis-proxy -c \/opt\/codis\/config.ini --log-level=error -L \/opt\/codis\/log\/proxy.log --cpu=1 --addr=0.0.0.0:19000 --http-addr=0.0.0.0:11000 &<\/pre>\n

\u8bbe\u7f6ecodis-proxy\u72b6\u6001\u4e3aonline<\/strong><\/p>\n

[root@linux-node3 ~]# \/opt\/codis\/bin\/codis-config -c \/opt\/codis\/config.ini proxy online codis_proxy_3<\/pre>\n

\u6ce8\uff1a\u5982\u679c\u91cd\u542f\u4e00\u53f0codis-proxy\u4e4b\u540ecodis-ha\u670d\u52a1\u6ca1\u751f\u6548\uff0c\u9700\u8981\u91cd\u542f\u4e09\u53f0codis-proxy<\/p>\n

\u505c\u6b62\u4efb\u610f\u8282\u70b9\u7684zookeeper\uff0c\u68c0\u67e5codis-proxy\uff0cdashboard\u662f\u5426\u6b63\u5e38><\/p>\n

\u4ee5zookeeper\u72b6\u6001\u4e3aleader\u90a3\u53f0\u670d\u52a1\u5668\u6d4b\u8bd5\uff08linux-node2\uff09<\/p>\n

\u67e5\u770bzookeeper\u72b6\u6001\u786e\u8ba4\u662f\u5426\u4e3aleader<\/strong><\/p>\n

[root@linux-node2 ~]# \/opt\/zookeeper\/bin\/zkServer.sh status<\/pre>\n

\u505c\u6b62linux-node2\u4e0a\u9762\u7684zookeeper\u8282\u70b9\uff0c\u8ba9\u5176\u4ed6zookeeper\u8282\u70b9\u81ea\u52a8\u9009\u62e9leader\u8282\u70b9\u5e76\u63d0\u4f9b\u670d\u52a1<\/p>\n

[root@linux-node2 ~]# \/opt\/zookeeper\/bin\/zkServer.sh stop<\/pre>\n

\"08-30-1\"<\/a><\/p>\n

#\u968f\u673a\u68c0\u6d4b\u5176\u4ed6\u8282\u70b9\u7684zookeeper\u72b6\u6001\uff0c\u68c0\u6d4b\u5230linux-node2\u7684zookeeper\u8282\u70b9\u5df2\u7ecf\u88ab\u9009\u4e3aleader\uff0c\u5f00\u59cb\u63d0\u4f9b\u670d\u52a1<\/p>\n

\"08-30-2\"<\/a><\/p>\n

#\u91cd\u542f\u5237\u65b0codis dashboard\u53ef\u4ee5\u770b\u5230dashboard\u662f\u6b63\u5e38\u7684\u3002<\/p>\n

\u68c0\u6d4bredis\u5ba2\u6237\u7aef\u662f\u5426\u80fd\u6b63\u5e38\u8bbf\u95eecodis-proxy<\/strong><\/p>\n

\u4ee5linux-node3\u4e3a\u4f8b\uff1a<\/p>\n

[root@linux-node3 ~]# cd \/opt\/codis\/src\/github.com\/CodisLabs\/codis\/extern\/redis-2.8.21\/src\/<\/pre>\n

#\u65b0\u5efascripts\u76ee\u5f55\uff0c\u5b58\u653eredis\u5e38\u7528\u547d\u4ee4<\/strong><\/p>\n

[root@linux-node3 src]# mkdir -p \/opt\/codis\/scripts\/\r\n[root@linux-node3 src]# cp redis-cli redis-server redis-benchmark redis-check-dump \/opt\/codis\/scripts\/<\/pre>\n

\"08-30-3\"<\/a><\/p>\n

\u4ece\u4e0a\u9762\u53ef\u4ee5\u770b\u51fa\u6211\u4e4b\u524dset\u7684\u4e24\u4e2akey\u90fd\u80fd\u6b63\u5e38get\u5230<\/p>\n

\u505c\u6b62\u4efb\u610fgroup\u4e2d\u7684redis master\u5b9e\u4f8b\uff0c\u68c0\u67e5redis slave\u662f\u5426\u81ea\u52a8\u5207\u6362\u4e3amaster\u6a21\u62dflinux-node1(192.168.1.148)\u4e0a\u9762\u7684redis-master 6379\u7aef\u53e3\u6302\u6389
\n<\/a>
\"08-30-9\"<\/a><\/p>\n

\u767b\u5f55\u5230codis-ha\u6240\u5728\u7684\u8282\u70b9\uff08linux-node2\uff09\u67e5\u770bcodis-ha\u65e5\u5fd7\uff0c\u6253\u5370\u5982\u4e0b<\/strong>
\n
\"08-30-4\"<\/a><\/p>\n

\u6253\u5f00dashboard\u754c\u9762\uff0c\u53ef\u4ee5\u770b\u5230\u5982\u4e0b\uff1a<\/strong>
\n
\"08-30-5\"<\/a><\/p>\n

\u4ece\u56fe\u4e2d\u53ef\u4ee5\u770b\u5230group_3\u7684salve\u8282\u70b9\u5df2\u7ecf\u81ea\u52a8\u5207\u6362\u5230master\u72b6\u6001<\/p>\n

\u5ba2\u6237\u7aef\u5199\u5165\u6570\u636e\uff0c\u68c0\u67e5\u5207\u6362\u540e\u7684redis master\u5b9e\u4f8b\u662f\u5426\u6709\u65b0key\u589e\u52a0<\/strong><\/p>\n

#linux-nod3\u65b0\u589ekey<\/strong>
\n
\"08-30-6\"<\/a><\/p>\n

\u91cd\u65b0\u5237\u65b0dashboard\u754c\u9762\uff0c\u67e5\u770bkey\u53d8\u5316<\/strong>
\n
\"08-30-7\"<\/a><\/p>\n

#\u6062\u590dlinux-node1\u4e0a\u7684redis\u5b9e\u4f8b\u76846379\u7aef\u53e3<\/strong><\/p>\n

[root@linux-node1 ~]# \/opt\/codis\/bin\/codis-server \/opt\/codis\/redis_conf\/6379.conf &\r\n[root@linux-node1 ~]# ps -ef | grep -v grep | grep codis-server\r\nroot\u00a0\u00a0\u00a0\u00a0 16620 13759\u00a0 0 Aug27 pts\/0\u00a0\u00a0\u00a0 00:04:52 \/opt\/codis\/bin\/codis-server *:6380\r\nroot\u00a0\u00a0\u00a0\u00a0 27574 13759\u00a0 2 19:40 pts\/0\u00a0\u00a0\u00a0 00:00:00 \/opt\/codis\/bin\/codis-server *:6379<\/pre>\n

\u5237\u65b0dashboard\u754c\u9762\u67e5\u770bgroup\u4e2dredis\u5b9e\u4f8b\u72b6\u6001\u53d8\u5316<\/strong>
\n
\"08-30-8\"<\/a><\/p>\n

\u53ef\u4ee5\u770b\u5230linux-node1\u4e0a\u9762\u7684\u7aef\u53e3\u4e3a6379\u7684redis\u5b9e\u4f8b\u5df2\u7ecf\u542f\u52a8\u5e76\u81ea\u52a8\u6210\u4e3agroup_3\u4e2d\u7684slave<\/p>\n

\u5907\u6ce8\uff1a\u5047\u5982\u5f53maste\u6302\u6389\u662f\uff0credis-ha\u68c0\u6d4b\u81ea\u52a8\u5c06slave\u5207\u6362\u4e3amaster\uff0c\u4f46\u662fmaster\u6062\u590d\u540e\uff0c\u5982\u679c\u72b6\u6001\u4ecd\u4e3aoffline\uff0c\u53ef\u4ee5\u628a\u8fd9\u4e2aredis\u8282\u70b9\u4ecegroup\u4e2d\u79fb\u51fa\uff0c\u518d\u91cd\u65b0\u6dfb\u52a0\u3002<\/p>\n

2\u3001\u62a5\u9519\u89e3\u51b3\uff1a<\/strong><\/span><\/div>\n
\/opt \/bin\/zkCli.sh\r\ndelete \/zk\/codis\/db_test\/dashboard<\/pre>\n

#\u91cd\u542fcodis dashboard<\/strong><\/p>\n

nohup \/usr\/local\/codis\/bin\/codis-config -c \/usr\/local\/codis\/config.ini dashbo\r\nard &<\/pre>\n

\u672c\u6587\u539f\u521b\u5730\u5740\uff1ahttp:\/\/gulass.cn\/deploy-codis-cluster.html<\/a>\u4f5c\u8005\uff1a\u738b\u8f89\uff0c\u5ba1\u6838\u5458\uff1a\u5cb3\u6c38<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"

\u5bfc\u8bfb Codis \u662f\u4e00\u4e2a\u5206\u5e03\u5f0f Redis \u89e3\u51b3\u65b9\u6848, \u5bf9\u4e8e\u4e0a\u5c42\u7684\u5e94\u7528\u6765\u8bf4, \u8fde\u63a5\u5230 Codis Proxy […]<\/p>\n","protected":false},"author":63,"featured_media":28271,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[55],"tags":[],"class_list":["post-28243","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-thread"],"acf":[],"_links":{"self":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/28243","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/users\/63"}],"replies":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/comments?post=28243"}],"version-history":[{"count":21,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/28243\/revisions"}],"predecessor-version":[{"id":258748,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/posts\/28243\/revisions\/258748"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media\/28271"}],"wp:attachment":[{"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/media?parent=28243"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/categories?post=28243"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gulass.cn\/wp-json\/wp\/v2\/tags?post=28243"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}