从零开始搭建一套微服务框架(二)搭建微服务调度中心Zookeeper

因考虑集成fescar分布式事务管理,注册中心将改为nacos,请移步

从零开始搭建一套微服务框架(五)集成nacos

微服务架构最核心的肯定是微服务调度中心,没有这个就没有微服务,那么我们开始吧

一、搭建zookeeper集群

1、官网下载zookeeper安装包

http://zookeeper.apache.org/releases.html

2、解压安装包到服务器上,我这里是linux

3、在安装目录下创建data和datalog文件夹

4、在data文件夹下创建myid文件,写入服务id,第一台服务器就写1,第二胎写2,以此类推

5、将zookeeper目录的conf/zoo_sample.cfg文件复制为zoo.cfg文件

6、按照下面的说明,编辑zoo.cfg文件,并保存。

# 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.
dataDir=/usr/zookeeper/data
dataLogDir=/usr/zookeeper/datalog
# the port at which the clients will connect
clientPort=2181    (建议默认端口)
server.1=192.168.1.1:2888:3888
server.2=192.168.1.2:2888:3888
server.3=192.168.1.3:2888:3888

 dataDir目录为本zookeeper实例的data目录

dataLogDir目录为本zookeeper实例的dataLogDir目录

clientPort为客户端连接端口,保持为2181不改变。

server.1中的1为实例顺序,根据zookeeper实例序号,ip、port保持为     实例主机IP:2888:3888

7、输入下面命令,执行zookeeper目录bin/zkServer.sh,启动zookeeper。

./bin/zkServer.sh start

多台服务器均按照上述1-7设置

单机伪集群搭建

1、2两步同上

3、创建一个servers文件夹,文件夹下创建server1,server2,server3

4、每个server文件下创建data和datalog文件夹,并在data文件夹中创建myid文件,写入server的id,规则同上

5、将zookeeper目录的conf/zoo_sample.cfg文件复制到每个server文件夹,并改名为zoo.cfg

# 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.
dataDir=/usr/zookeeper/servers/server1/data
dataLogDir=/usr/zookeeper/servers/server1/datalog
# the port at which the clients will connect
clientPort=2181    (为每个服务配置不同的端口)
server.1=localhost:2287:3387
server.2=localhost:2288:3388
server.3=localhost:2289:3389

dataDir目录为本zookeeper实例的data目录

dataLogDir目录为本zookeeper实例的dataLogDir目录

clientPort为客户端连接端口,三个实例要分别设置不同的,如:2181、2182、2183

因为三个服务都在一台机器上,为了避免端口冲突,主从通信端口设置为

server.1=localhost:2287:3387
server.2=localhost:2288:3388
server.3=localhost:2289:3389

6. 输入下面命令,执行zookeeper目录bin/zkServer.sh,启动zookeeper。

./bin/zkServer.sh start ./servers/server1/zoo.cfg

./bin/zkServer.sh start ./servers/server2/zoo.cfg

./bin/zkServer.sh start ./servers/server3/zoo.cfg

至此,zookeeper集群搭建完毕,执行下面的命令可以查看服务器状态

./bin/zkServer.sh status ./servers/server1/zoo.cfg

./bin/zkServer.sh status ./servers/server2/zoo.cfg

./bin/zkServer.sh status ./servers/server3/zoo.cfg

 连接zookeeper测试命令为

./bin/zkCli.sh -server 127.0.0.1:2181 

二、Dubbo Admin搭建

参考

https://blog.csdn.net/u012627861/article/details/82945068 

猜你喜欢

转载自blog.csdn.net/kris1122/article/details/88290122