安装部署
wget -c https://archive.apache.org/dist/zookeeper/zookeeper-3.5.5/apache-zookeeper-3.5.5-bin.tar.gz
tar zxvf apache-zookeeper-3.5.5-bin.tar.gz -C /usr/local/
每台主机执行
变量环境
vi /etc/profile
ZOOKEEPER_HOME=/usr/local/apache-zookeeper-3.5.5-bin
export PATH=$PATH:$ZOOKEEPER_HOME/bin
source /etc/profile
# 载入环境变量
配置文件
vi $ZOOKEEPER_HOME/conf/zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/tmp/zookeeper
clientPort=2181
dataDir=/data/zookeeper/data
dataLogDir=/data/zookeeper/log
autopurge.snapRetainCount=20
autopurge.purgeInterval=48
#保留48小时内的日志,并且保留20个文件
4lw.commands.whitelist=*
admin.serverPort=3999
# 内嵌的管理控制台默认8080
server.1=192.168.10.152:2888:3888
server.2=192.168.10.153:2888:3888
server.3=192.168.10.154:2888:3888
#指定zookeeper集群的server编号、地址和端口
建数据目录
mkdir -p /data/zookeeper/{data,log}
# 三台都要创建数据和日志路径
指定每台主机id
主机1
echo 1 > /data/zookeeper/data/myid
主机2
echo 2 > /data/zookeeper/data/myid
主机3
echo 3 > /data/zookeeper/data/myid
启动集群
zkServer.sh start
# 启动服务
zkServer.sh status
# 查看服务状态;leader 是被选举的主节点,其他节点为follower
echo mntr | nc localhost 2181
# 测试
连接参考
config/application.properties
dubbo.registryAddress=zookeeper://192.168.1.20:2181
dubbo.protocol=dubbo
dubbo.port=28021
server.port=8021
logging.path=/home/logs
logging.config=classpath:server-logback.xml
redis.host=192.168.1.10
redis.pass=123456
dubbo中zookeeper的配置
<dubbo:registryaddress="zookeeper://10.20.153.10:2181"/>
# 单机
<dubbo:registryaddress="zookeeper://10.20.153.10:2181?backup=10.20.153.11:2181,10.20.153.12:2181"/>
# 集群方式
<dubbo:registryprotocol="zookeeper"address="10.20.153.10:2181,10.20.153.11:2181,10.20.153.12:2181"/>
# 集群方式