由于codis环境复杂,新手搭建容易犯错,因此笔者建议先把 codis-test(https://github.com/CodisLabs/codis/tree/release3.1/scripts/test.sh) 跑起来;熟悉这个 codis-test 之后,再重新搭建自己的 codis环境就比较容易了
本系列安装实践文档,参考codis 官方安装说明文档
https://github.com/CodisLabs/codis/blob/release3.1/doc/tutorial_zh.md
参考 Zookeeper 安装和配置
http://coolxing.iteye.com/blog/1871009
#三台服务器,每台服务器的 hosts 增加内容
192.168.42.102 zk1
192.168.42.25 zk2
192.168.42.26 zk3
#下载源码到服务器
[root@dev9102 src]# pwd
/usr/local/src
[root@dev9102 src]# ls
zookeeper-3.4.8.tar.gz
#安装
#tar zxvf zookeeper-3.4.8.tar.gz
[root@dev9102 conf]# pwd
#改配置文件
#
以下 clientPort=2180 是集群的服务端口, 2888 、3888 是集群内部端口,其中2888 是leader 才会建立的
/usr/local/src/zookeeper-3.4.8/conf
[root@dev9102 conf]# cp zoo_sample.cfg zoo.cfg
#cat zoo.cfg
...
clientPort=2180
...
server.1=zk1:2888:3888
server.2=zk2:2888:3888
server.3=zk3:2888:3888
...
#配置 myid
[root@dev9102 conf]# mkdir -p /tmp/zookeeper/
[root@dev9102 conf]# echo 1 > /tmp/zookeeper/myid
[root@dev9102 bin]# pwd
/usr/local/src/zookeeper-3.4.8/bin
#【服务器1的启动尝试】
#使用 前台模式 ,试启动,查看其中的报错(如无法解析 zk1 、 端口绑定错之类的)
[root@dev9102 bin]# ./zkServer.sh start-foreground
#前台模式没问题后, 改用后台模式
[root@dev9102 bin]# ./zkServer.sh start
#查看状态
[root@dev9102 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/src/zookeeper-3.4.8/bin/../conf/zoo.cfg
Mode:
follower
#【服务器2的启动尝试】
参考以上 服务器1的启动尝试
[root@dev25 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/src/zookeeper-3.4.8/bin/../conf/zoo.cfg
Mode:
follower
#【服务器3的启动尝试】
参考以上 服务器1的启动尝试
[root@dev926 bin]# ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /usr/local/src/zookeeper-3.4.8/bin/../conf/zoo.cfg
Mode:
leader
#查看已经监听的端口, 从以上 ./zkServer.sh status 得知 42.26 是leader, 从 以下端口情况看, 只有 leader 监听了 2888 端口
[root@dev9102 bin]# netstat -anp | egrep -e "2180|2888|3888"
tcp 0 0 ::ffff:192.168.42.102:3888 :::* LISTEN 8553/java
tcp 0 0 :::2180 :::* LISTEN 8553/java
tcp 0 0 ::ffff:192.168.42.102:3888 ::ffff:192.168.42.25:41068 ESTABLISHED 8553/java
tcp 0 0 ::ffff:192.168.42.102:3888 ::ffff:192.168.42.26:46617 ESTABLISHED 8553/java
tcp 0 0 ::ffff:192.168.42.102:58489 ::ffff:192.168.42.26:2888 ESTABLISHED 8553/java
[root@dev25 bin]# netstat -anp | egrep -e "2180|2888|3888"
tcp 0 0 ::ffff:192.168.42.25:3888 :::* LISTEN 13461/java
tcp 0 0 :::2180 :::* LISTEN 13461/java
tcp 0 0 ::ffff:192.168.42.25:41193 ::ffff:192.168.42.26:2888 ESTABLISHED 13461/java
tcp 0 0 ::ffff:192.168.42.25:3888 ::ffff:192.168.42.26:39621 ESTABLISHED 13461/java
tcp 0 0 ::ffff:192.168.42.25:41068 ::ffff:192.168.42.102:3888 ESTABLISHED 13461/java
[root@
dev926 bin]# netstat -anp | egrep -e "2180|2888|3888"
tcp 0 0 :::2180 :::* LISTEN 11123/java
tcp 0 0 ::ffff:192.168.42.26:
2888 :::* LISTEN 11123/java
tcp 0 0 ::ffff:192.168.42.26:3888 :::* LISTEN 11123/java
tcp 0 0 ::ffff:192.168.42.26:2888 ::ffff:192.168.42.102:58489 ESTABLISHED 11123/java
tcp 0 0 ::ffff:192.168.42.26:46617 ::ffff:192.168.42.102:3888 ESTABLISHED 11123/java
tcp 0 0 ::ffff:192.168.42.26:39621 ::ffff:192.168.42.25:3888 ESTABLISHED 11123/java
tcp 0 0 ::ffff:192.168.42.26:2888 ::ffff:192.168.42.25:41193 ESTABLISHED 11123/java
#在 服务器1 连接 zookeeper
[root@dev9102 bin]# pwd
/usr/local/src/zookeeper-3.4.8/bin
[root@dev9102 bin]# ./zkCli.sh -server 127.0.0.1:2180
[zk: 127.0.0.1:2180(CONNECTED) 0] ls /
[testRootPath1, mytest, zookeeper]
[zk: 127.0.0.1:2180(CONNECTED) 1] create /zk1Add test
Created /zk1Add
[zk: 127.0.0.1:2180(CONNECTED) 2] ls /
[zk1Add, testRootPath1, mytest, zookeeper]
#在 服务器2 连接 zookeeper
[root@dev25 bin]# pwd
/usr/local/src/zookeeper-3.4.8/bin
[root@dev25 bin]# ./zkCli.sh -server 127.0.0.1:2180
#此时发现 已经有生成了 zk1Add 目录
[zk: 127.0.0.1:2180(CONNECTED) 0] ls /
[zk1Add, mytest, testRootPath1, zookeeper]