目录
一、Apache Dubbo支持的几个注册中心
点击文档 (https://dubbo.apache.org/zh/docs/)
如下,可看到支持5个注册中心,官方推荐使用 Zookeeper 注册中心
二、进入 ZooKeeper 官网,下载zk
进入 ZooKeeper 官网
点击 in the archive.
下载需要的版本(一般最新的,属于公测版,我们不要下载)
三、解压并配置zk
下载并解压
解压zookeeper
解压运行 zkServer.cmd ,初次运行会报错,没有zoo.cfg配置文件
修改zoo.cfg配置文件
将 conf 下的 zoo_sample.cfg 复制一份改名为 zoo.cfg 即可。
注意几个重要位置:
dataDir=./ 临时数据存储的目录(可写相对路径)
clientPort=2181 zookeeper的端口号
修改完成后再次启动zookeeper
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=../data
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
四、使用zkCli.cmd测试
ls /:列出zookeeper根下保存的所有节点
create –e /atXXX 123:创建一个atXXX节点,值为123
get /atXXX:获取/atXXX节点的值
1、启动ZK
打开cmd命令界面,命令行启动zk
D:\soft_install_dir\zookeeper-3.4.11\bin>zkServer.cmd
2、连接ZK
再打开一个cmd命令界面,输入如下命令,进行zk连接:
D:\soft_install_dir\zookeeper-3.4.11\bin>zkCli.cmd
Connecting to localhost:2181
[zk: localhost:2181(CONNECTED) 0] get /
cZxid = 0x0
ctime = Thu Jan 01 08:00:00 CST 1970
mZxid = 0x0
mtime = Thu Jan 01 08:00:00 CST 1970
pZxid = 0x2
cversion = 0
dataVersion = 0
aclVersion = 0
ephemeralOwner = 0x0
dataLength = 0
numChildren = 2
[zk: localhost:2181(CONNECTED) 1] ls /
[dubbo, zookeeper]
[zk: localhost:2181(CONNECTED) 2] get /dubbo
192.168.1.101
[zk: localhost:2181(CONNECTED) 3] create -e /yyh 123456
Created /yyh
[zk: localhost:2181(CONNECTED) 4] ls /
[dubbo, yyh, zookeeper]
[zk: localhost:2181(CONNECTED) 5] get /yyh
123456