codis 部署和测试
git clone https://github.com/CodisLabs/codis.git
1:下載go環境 官網:https://golang.org/doc/install
wget https://storage.googleapis.com/golang/go1.6.2.linux-amd64.tar.gz
tar -C /usr/local -xzf go1.6.2.linux-amd64.tar.gz
cd /usr/local/go
cat >> /etc/profile <<EOF
export GOROOT=/usr/local/go
export GOPATH=/workspace/golang
export PATH=\$PATH:\$GOROOT/bin:\$GOPATH/bin
export CODIS_HOME=$GOPATH/src/github.com/CodisLabs/codis
export GO15VENDOREXPERIMENT=0
EOF
source /etc/profile
2:下載安裝codis 官網:https://github.com/CodisLabs/codis/blob/master/doc/tutorial_zh.md? 根據官網推薦采用這種方式,而不是git clone ...codis
go get -u -d github.com/CodisLabs/codis
go get github.com/tools/godep
cd $GOPATH/src/github.com/CodisLabs/codis
make
make gotest
#mkdir -p /usr/local/codis/{logs,conf,scripts}
#mkdir -p /data/codis_server/{logs,conf,data}
cd $GOPATH/src/github.com/CodisLabs/codis/bin
3:安裝zookeeper
wget http://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz? -P /opt
tar -C /opt -xvf /opt/zookeeper-3.4.6.tar.gz ?
cd /opt/zookeeper-3.4.6/conf
cp zoo_sample.cfg zoo.cfg
/opt/zookeeper-3.4.6/bin/zkServer.sh start
read -p "請輸入zookeeper的地址: " zookeeper-ip
sed -i? 's/192\.168\.0\.123/$zookeeper-ip/g' config.ini
###assets //dashboard的靜態文件目錄
###codis-config codis命令式配置管理組件
###codis-proxy codis 代理也就是核心組件
###codis-server codis基于redis2.8.21定制版redis
mkdir /workspace/golang/src/github.com/CodisLabs/codis/wk
cp /workspace/golang/src/github.com/CodisLabs/codis/config.ini? /workspace/golang/src/github.com/CodisLabs/codis/wk/
4:啟動 dashboard(codis-config上操作)
cd $CODIS_HOME && ./bin/codis-config -c $CODIS_HOME/wk/config.ini dashboard &
可以從瀏覽器打開http://192.168.16.239:18087/admin/
5:初始化 slot,該命令會在zookeeper上創建slot相關信息
cd $CODIS_HOME &&? ./bin/codis-config -c $CODIS_HOME/wk/config.ini slot init &
6:啟動 Codis Redis , 和官方的Redis Server參數一樣(codis-server上操作)
cp extern/redis-2.8.21/redis.conf wk/
cd $CODIS_HOME && ./codis-server ../extern/redis-2.8.21/redis.conf??????????????????? (端口6379)作為16.241的6380的master
?? ??? ??? ??? ?? ./codis-server ../extern/redis-2.8.21/redis6380.conf ?? ??? ??? ??? ?? (端口6380)作為16.241的6379的slave
7:添加 Redis Server Group , 每一個 Server Group 作為一個 Redis 服務器組存在, 只允許有一個 master,
?? ? 可以有多個 slave, group id 僅支持大于等于1的整數(codis-config上操作)
?? ?./codis-config -c ../wk/config.ini server add 1 192.168.16.239:6379 master
?? ?./codis-config -c ../wk/config.ini server add 1 192.168.16.241:6380 slave
?? ?
?? ?
?? ?./codis-config -c ../wk/config.ini server add 2 192.168.16.241:6379 master
?? ?./codis-config -c ../wk/config.ini server add 2 192.168.16.239:6380 slave
?? ?
8: 啟動241上面的redis服務,作為slave
/codis-server ../extern/redis-2.8.21/redis.conf??????????????? 作為16.239的6380 的master
/codis-server ../extern/redis-2.8.21/redis6380.conf ??? ??? ??? ?作為16.239的6379 的slave
****************注意,不需要從redis.conf 去配置slave,必須用codis-server 去啟動redis***************
[root@shell bin]# 2016/04/28 14:16:48 dashboard.go:160: [INFO] dashboard listening on addr: :18087
2016/04/28 14:16:49 dashboard.go:234: [PANIC] create zk node failed
[error]: dashboard already exists: {"addr": "192.168.16.239:18087", "pid": 2280}
[stack]:
??? 3?? /workspace/golang/src/github.com/CodisLabs/codis/cmd/cconfig/dashboard.go:234
??????????? main.runDashboard
??? 2?? /workspace/golang/src/github.com/CodisLabs/codis/cmd/cconfig/dashboard.go:54
??????????? main.cmdDashboard
??? 1?? /workspace/golang/src/github.com/CodisLabs/codis/cmd/cconfig/main.go:85
??????????? main.runCommand
??? 0?? /workspace/golang/src/github.com/CodisLabs/codis/cmd/cconfig/main.go:152
??????????? main.main
??????? ... ...
?? ??? ?
解決:
./zkCli.sh
[zk: localhost:2181(CONNECTED) 11] rmr? /zk/codis
原因:
2016/04/28 14:52:44 dashboard.go:143: [INFO] dashboard node created: /zk/codis/db_wk/dashboard, {"addr": "192.168.16.239:18087", "pid": 8578}
2016/04/28 14:52:44 dashboard.go:144: [WARN] ********** Attention **********
2016/04/28 14:52:44 dashboard.go:145: [WARN] You should use `kill {pid}` rather than `kill -9 {pid}` to stop me,
2016/04/28 14:52:44 dashboard.go:146: [WARN] or the node resisted on zk will not be cleaned when I'm quiting and you must remove it manually
9:設置 server group 服務的 slot 范圍
Codis 采用 Pre-sharding 的技術來實現數據的分片, 默認分成 1024 個 slots (0-1023), 對于每個key來說, 通過以下公式確定所屬的
Slot Id : SlotId = crc32(key) % 1024 每一個 slot 都會有一個且必須有一個特定的 server group id 來表示這個 slot 的數據由哪個 server group 來提供
[root@shell bin]# ./codis-config? -c ../wk/config.ini slot -h
usage:
??????? codis-config slot init [-f]
??????? codis-config slot info <slot_id>
??????? codis-config slot set <slot_id> <group_id> <status>
??????? codis-config slot range-set <slot_from> <slot_to> <group_id> <status>
??????? codis-config slot migrate <slot_from> <slot_to> <group_id> [--delay=<delay_time_in_ms>]
??????? codis-config slot rebalance [--delay=<delay_time_in_ms>]
?? ??? ?
[root@shell bin]# ./codis-config? -c ../wk/config.ini slot? range-set 0 511 1 online
{
? "msg": "OK",
? "ret": 0
}
到瀏覽器上看看效果
或者
[root@shell bin]# ./codis-config? -c ../wk/config.ini slot? info 1
{
? "group_id": 1,
? "id": 1,
? "product_name": "wk",
? "state": {
??? "last_op_ts": "0",
??? "migrate_status": {
????? "from": -1,
????? "to": -1
??? },
??? "status": "online"
? }
?
10:啟動 codis-proxy
[root@shell bin]# ./codis-proxy -c ../wk/config.ini -L ./log/proxy.log? --cpu=4 --addr=0.0.0.0:19000 --http-addr=0.0.0.0:11000 &
? _____? ____??? ____/ /? (_)? _____
?/ ___/ / __ \? / __? /? / /? / ___/
/ /__? / /_/ / / /_/ /? / /? (__? )
\___/? \____/? \__,_/? /_/? /____/
在241上啟動第二個代理服務器
?./codis-proxy -c ../wk/config.ini -L ./log/proxy.log? --cpu=4 --addr=0.0.0.0:19000 --http-addr=0.0.0.0:11000 &
?
?在瀏覽器上看到proxy_2是offile狀態,如果用命令去啟動proxy_2 online狀態,則提示下面錯誤,需要去啟動dashboard,我們直接在界面上啟動為online狀態
[root@zabbix bin]# ./codis-config -c ../wk/config.ini proxy online proxy_2
2016/05/03 13:43:12 utils.go:49: [ERROR] can't connect to dashboard, please check 'dashboard_addr' is corrent in config file
[stack]:
轉載于:https://www.cnblogs.com/liangsky/p/5546129.html
總結
以上是生活随笔為你收集整理的codis 部署和测试的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 原创:既生“苏”,何生“德”,二战中纵横
- 下一篇: 【bzoj4385】[POI2015]W