dubbo微服务架构
https://cn.dubbo.apache.org/zh-cn/overview/home/
https://help.aliyun.com/zh/edas/developer-reference/dubbo-overview
1. 安装zookeeper注册中心
官网:https://zookeeper.apache.org/
安装说明:https://zookeeper.apache.org/doc/r3.7.1/zookeeperAdmin.html
1.1 安装java
zookeeper依赖jdk环境
# 安装jdk 1.8
apt update
apt install -y openjdk-8-jdk
1.2 下载zookeeper并解压
wget https://dlcdn.apache.org/zookeeper/zookeeper-3.7.1/apache-zookeeper-3.7.1-bin.tar.gz
mkdir -p /apps
tar xvf apache-zookeeper-3.7.1-bin.tar.gz -C /apps
ln -s /apps/apache-zookeeper-3.7.1-bin /apps/zookeeper
1.3 修改配置
cd /apps/zookeeper/conf/
cp zoo_sample.cfg zoo.cfg
# cat zoo.cfg
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/data/zookeeper/
clientPort=2181
server.1=10.0.0.76:2888:3888
server.2=10.0.0.77:2888:3888
server.3=10.0.0.78:2888:3888
# 分别在不同服务器上创建myid,分别为1、2、3
mkdir -p /data/zookeeper
echo '1' > /data/zookeeper/myid
1.4 启动服务
zookeeper集群需要在20s内完成启动
/apps/zookeeper/bin/zkServer.sh start
1.5 验证集群
节点2为leader,其余节点为follower,集群状态正常
# zk1
[root@zk1 conf]#/apps/zookeeper/bin/zkServer.sh status
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /apps/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
[root@zk2 conf]#/apps/zookeeper/bin/zkServer.sh status
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /apps/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: leader
[root@zk3 conf]#/apps/zookeeper/bin/zkServer.sh status
/usr/bin/java
ZooKeeper JMX enabled by default
Using config: /apps/zookeeper/bin/../conf/zoo.cfg
Client port found: 2181. Client address: localhost. Client SSL: false.
Mode: follower
2. 部署provider生产者
部署两台provider,IP:10.0.0.92-93
2.1 安装java环境
依赖java环境
# 安装jdk 1.8
apt update
apt install -y openjdk-8-jdk
2.2 安装skywalking java agent
- 下载并解压
mkdir /data && cd /data
wget https://archive.apache.org/dist/skywalking/java-agent/9.0.0/apache-skywalking-java-agent-9.0.0.tgz
tar xvf apache-skywalking-java-agent-9.0.0.tgz
- 配置skywalking agent连接server
vim /data/skywalking-agent/config/agent.config
...
agent.service_name=${SW_AGENT_NAME:dubbo-provider-1}
# provider2
# agent.service_name=${SW_AGENT_NAME:dubbo-provider-2}
agent.namespace=${SW_AGENT_NAMESPACE:dubbo}
# Backend service addresses. # 后端服务即skywalking-oap平台地址,11800为grpc端口,12800为http端口
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:10.0.0.91:11800}
2.3 准备dubbo-server.jar
- 用WinRAR打开,查看config.properties配置内容,再上传至服务器
dubbo.registry=zookeeper://zookeeper1:2181?backup=zookeeper2:2181,zookeeper3:2181
查看
[root@dubbo-server1 ~]#ls /data/dubbo-server.jar
/data/dubbo-server.jar
- 配置hosts
cat /etc/hosts
...
# 添加zookeeper集群
10.0.0.76 zookeeper1
10.0.0.77 zookeeper2
10.0.0.78 zookeeper3
2.4 启动服务
java -javaagent:/data/skywalking-agent/skywalking-agent.jar -jar /data/dubbo-server.jar
服务启动日志
2.5 skywalking验证
3. 部署consumer消费者
IP:10.0.0.94
3.1 安装java环境
依赖java环境
# 安装jdk 1.8
apt update
apt install -y openjdk-8-jdk
3.2 安装skywalking java agent
- 下载并解压
mkdir /data && cd /data
wget https://archive.apache.org/dist/skywalking/java-agent/9.0.0/apache-skywalking-java-agent-9.0.0.tgz
tar xvf apache-skywalking-java-agent-9.0.0.tgz
- 配置skywalking agent连接server
vim /data/skywalking-agent/config/agent.config
...
agent.service_name=${SW_AGENT_NAME:dubbo-consumer}
agent.namespace=${SW_AGENT_NAMESPACE:dubbo}
# Backend service addresses. # 后端服务即skywalking-oap平台地址,11800为grpc端口,12800为http端口
collector.backend_service=${SW_AGENT_COLLECTOR_BACKEND_SERVICES:10.0.0.91:11800}
3.3 准备dubbo-client.jar
- 用WinRAR打开,查看config.properties配置内容,再上传至服务器
dubbo.registry=zookeeper://zookeeper1:2181?backup=zookeeper2:2181,zookeeper3:2181
查看
[root@dubbo-client ~]#ls /data/dubbo-server.jar
/data/dubbo-client.jar
- 配置hosts
cat /etc/hosts
...
# 添加zookeeper集群
10.0.0.76 zookeeper1
10.0.0.77 zookeeper2
10.0.0.78 zookeeper3
3.4 启动服务
java -javaagent:/data/skywalking-agent/skywalking-agent.jar -jar /data/dubbo-client.jar
3.5 skywalking验证
3.6 zookeeper验证
使用ZooInspector图形工具,验证provider、consumer注册
4. skywalking验证
4.1 浏览器访问测试页面
测试页面:http://10.0.0.94:8080/hello?name=jack
- consumer服务器日志
- provider服务器日志
服务器1日志
服务器2日志
4.2 验证skywalking
- skywalking追踪全部服务状态
- skywalking 拓扑
- dubbo-consumer服务状态
- dubbo-provider2服务状态
- dubbo-consumer实例状态
- dubbo-consumer 端点状态