特性
- 会话
客户端连接到ZooKeeper
服务器时,建立一个会话
每个会话都存在一个有效时间
在真实的系统环境中,通过Ping
请求保持会话不过期
- 版本号
版本号是一种乐观加锁的机制,使客户端能检测出对节点的修改冲突
- 监控
当节点的状态发生变化时,监控(Watcher
)机制可以让客户端得到通知
集群部署
主机名 |
IP |
服务 |
ubuntu02 |
192.168.0.152 |
java、zookeeper |
ubuntu03 |
192.168.0.153 |
java、zookeeper |
ubuntu04 |
192.168.0.154 |
java、zookeeper |
java环境部署
wget -c http://~/jdk-8u181-linux-x64.tar.gz
tar -zxvf jdk-8u181-linux-x64.tar.gz && mv jdk1.8.0_181/ /usr/local/
cd /usr/local && ln -s jdk1.8.0_181/ java
cat >> /etc/profile << EOF
# for java
export JAVA_HOME=/usr/local/java
export CLASSPATH=.:\$JAVA_HOME/lib/dt.jar:\$JAVA_HOME/lib/tools.jar
export PATH=\$JAVA_HOME/bin:\$PATH
EOF
source /etc/profile
java -version
zookeeper环境部署
wget -c http://mirror.bit.edu.cn/apache/zookeeper/current/zookeeper-3.4.12.tar.gz
tar -zxvf zookeeper-3.4.12.tar.gz && mv zookeeper-3.4.12/ /usr/local/
cd /usr/local && ln -s zookeeper-3.4.12/ zookeeper
cat >> /etc/profile << EOF
# for zookeeper
export ZOOKEEPER_HOME=/usr/local/zookeeper
export PATH=\$ZOOKEEPER_HOME/bin:\$PATH
EOF
source /etc/profile
关于配置文件
mkdir -p /data/zookeeper && mkdir -p /log/zookeeper
echo "1" > /data/zookeeper/myid
cp conf/zoo_sample.cfg conf/zoo.cfg
vim conf/zoo.cfg
...
dataDir=/data/zookeeper
dataLogDir=/log/zookeeper
...
server.1=192.168.0.152:2888:3888
server.2=192.168.0.153:2888:3888
server.3=192.168.0.154:2888:3888
分发zookeeper到节点
scp -r zookeeper-3.4.12 root@192.168.0.153:`pwd`
scp -r zookeeper-3.4.12 root@192.168.0.154:`pwd`
ssh root@192.168.0.* # 每个节点
> mkdir -p /data/zookeeper && mkdir -p /log/zookeeper
> echo "1" > /data/zookeeper/myid # 不同机器对应id不同
> cat >> /etc/profile << EOF
# for zookeeper
export ZOOKEEPER_HOME=/usr/local/zookeeper
export PATH=\$ZOOKEEPER_HOME/bin:\$PATH
EOF
> source /etc/profile
启动服务并校验
zkServer.sh start
zkServer.sh status
ps aux | grep zookeeper
netstat -an | grep 2181
telnet 192.168.0.152 2181
nmap 192.168.0.152 -p 2181
jps
zkCli连接
zkCli.sh -timeout 5000 -server 192.168.0.152:2181
zkCli.sh -timeout 5000 -server 192.168.0.152:2181 ls /
网友评论