dubbo默认端口
Ⅰ zookeeper端口是2181端口还是20882端口
ZooKeeper安装与配置
一. 单机安装、配置:
1. 下载zookeeper二进制安装包
2.解压zookeeper安装包
把-3.4.3.tar.gz文件存放在/home/hadoop目录下,进行解压:
hadoop@ubuntu:~$ sudo tar -zxvf zookeeper-3.4.3.tar.gz
hadoop@ubuntu:~$ chown -R hadoop:hadoop zookeeper-3.4.3
3.设置环境变量
在/etc/profile,/home/hadoop/.bashrc文件中添加如下红色信息
#set java environment
ZOOKEEPER_HOME=/home/hadoop/zookeeper-3.4.3
MAHOUT_HOME=/home/hadoop/mahout-distribution-0.7
PIG_HOME=/home/hadoop/pig-0.9.2
HBASE_HOME=/home/hadoop/hbase-0.94.3
HIVE_HOME=/home/hadoop/hive-0.9.0
HADOOP_HOME=/home/hadoop/hadoop-1.1.1
JAVA_HOME=/home/hadoop/jdk1.7.0
PATH=$JAVA_HOME/bin:$ZOOKEEPER_HOME/bin:$PIG_HOME/bin:$MAHOUT_HOME/bin:$HBASE_HOME/bin:$HIVE_HOME/bin:$HADOOP_HOME/bin:$HADOOP_HOME/conf:$PATH
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$ZOOKEEPER_HOME/lib:$HBASE_HOME/lib:$MAHOUT_HOME/lib:$PIG_HOME/lib:$HIVE_HOME/lib:$JAVA_HOME/lib/tools.jar
export ZOOKEEPER_HOME
export MAHOUT_HOME
export PIG_HOME
export HBASE_HOME
export HADOOP_HOME
export JAVA_HOME
export HIVE_HOME
export PATH
export CLASSPATH
4.配置
配置文件存放在$ZOOKEEPER_HOME/conf/目录下,将zoo_sample.cfd文件名称改为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.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/home/hadoop/zookeeper-3.4.3/data #这是我修改后的
# the port at which the clients will connect
clientPort=2181
#
# 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
配置说明:
tickTime:这个时间是作为 Zookeeper 服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。
dataDir:顾名思义就是 Zookeeper 保存数据的目录,默认情况下,Zookeeper 将写数据的日志文件也保存在这个目录里。
clientPort:这个端口就是客户端连接 Zookeeper 服务器的端口,Zookeeper 会监听这个端口,接受客户端的访问请求。
5.启动zookeeper
当这些配置项配置好后,你现在就可以启动zookeeper了:
hadoop@ubuntu:~/ netstat -at|grep 2181 #查看zookeeper端口
hadoop@ubuntu:~/ netstat -nat #查看端口信息
hadoop@ubuntu:~/zookeeper-3.4.3/bin$ ./zkServer.sh start #启动
hadoop@ubuntu:~/zookeeper-3.4.3/bin$ jps #查看启动的服务名称
hadoop@ubuntu:~/zookeeper-3.4.3/bin$ ./zkServer.sh stop #关闭
启动后要检查 Zookeeper 是否已经在服务,可以通过 netstat -at|grep 2181 命令查看是否有 clientPort 端口号在监听服务。
二. 集群安装、配置:
集群安装与配置暂时省略,下次在作补充。
Ⅱ 求bbox修改了默认端口,为什么始终会启动20880
IP是否是你本机IP,可能是因为找错IP了;
如果是这个原因的话将host绑定本机IP就OK
Ⅲ bbo是如何启动的
已知,在项目启动过程中,我们会将bbo的配置文件写到spring的配置文件里,如下xml文件:
<bbo:application name="anyname_provider" />
<!-- 使用zookeeper注册中心暴露服务地址 -->
<bbo:registry address="zookeeper://127.0.0.1:2181" />
<!-- 用bbo协议在20880端口暴露服务 -->
<bbo:protocol name="bbo" port="20880" />
<!-- 声明需要暴露的服务接口 -->
<bbo:service interface="com.shxz130.provider.Provider"
ref="demoService" />
从官方文档中,我们能看到如下:
启动过程.png
也就是说spring启动过程中,随着Spring在初始化过程中,碰到bbo命名的标签,如(<bbo:service>,<bbo:registry>)等标签,会由DubboNamespaceHandler类处理,具体原理见链接Spring自定义标签
DubboBeanDefinitionParser代码如下:
public class DubboNamespaceHandler extends NamespaceHandlerSupport { static {
Version.checkDuplicate(DubboNamespaceHandler.class);
} public void init() {
registerBeanDefinitionParser("application", new DubboBeanDefinitionParser(ApplicationConfig.class, true));
registerBeanDefinitionParser("mole", new DubboBeanDefinitionParser(MoleConfig.class, true));
registerBeanDefinitionParser("registry", new DubboBeanDefinitionParser(RegistryConfig.class, true));
registerBeanDefinitionParser("monitor", new DubboBeanDefinitionParser(MonitorConfig.class, true));
registerBeanDefinitionParser("provider", new DubboBeanDefinitionParser(ProviderConfig.class, true));
registerBeanDefinitionParser("consumer", new DubboBeanDefinitionParser(ConsumerConfig.class, true));
registerBeanDefinitionParser("protocol", new DubboBeanDefinitionParser(ProtocolConfig.class, true));
registerBeanDefinitionParser("service", new DubboBeanDefinitionParser(ServiceBean.class, true));
registerBeanDefinitionParser("reference", new DubboBeanDefinitionParser(ReferenceBean.class, false));
registerBeanDefinitionParser("annotation", new ());
}
}
遇到不同的标签,会由不同的Parser处理,这里重点看服务发布,这行代码:
registerBeanDefinitionParser("service", new DubboBeanDefinitionParser(ServiceBean.class, true));
也就是说,当Spring容器处理完<bbo:service>标签后,会在Spring容器中生成一个ServiceBean ,服务的发布也会在ServiceBean中完成。不妨看一下ServiceBean的定义:
public class ServiceBean<T> extends ServiceConfig<T> implements InitializingBean, DisposableBean, ApplicationContextAware, ApplicationListener<ContextRefreshedEvent>, BeanNameAware {
}
该Bean实现了很多接口,关于InitializingBean,DisposableBean,ApplicationContextAware,BeanNameAware,这些接口的使用介绍如下链接:
InitializingBean&DisposableBean
BeanNameAware& ApplicationContextAware
- public class ServiceBean<T> extends ServiceConfig<T> implements InitializingBean, DisposableBean, ApplicationContextAware, ApplicationListener<ContextRefreshedEvent>, BeanNameAware { //Spring容器初始化完成,调用
- public void onApplicationEvent(ContextRefreshedEvent event) { if (isDelay() && !isExported() && !isUnexported()) { if (logger.isInfoEnabled()) {
- logger.info("The service ready on spring started. service: " + getInterface());
- } //暴露服务
- export();
- }
- } //判断是否延迟发布
- private boolean isDelay() {
- Integer delay = getDelay();
- ProviderConfig provider = getProvider(); if (delay == null && provider != null) {
- delay = provider.getDelay();
- } return supportedApplicationListener && (delay == null || delay == -1);
- } //当bean初始化完成调用
- public void afterPropertiesSet() throws Exception { //......此处省略10000行代码
- if (!isDelay()) { //暴露服务
- export();
- }
- }
- }
- public synchronized void export() { //忽略若干行代码
- if (delay != null && delay > 0) { //当delay不为null,且大于0时,延迟delay时间,暴露服务
- delayExportExecutor.schele(new Runnable() { public void run() { //暴露服务
- doExport();
- }
- }, delay, TimeUnit.MILLISECONDS);
- } else { //直接暴露服务
- doExport();
- }
- }
- protected synchronized void doExport() { //忽略10000行代码
- doExportUrls(); //忽略10000行代码
- } private void doExportUrls() {
- List<URL> registryURLs = loadRegistries(true); for (ProtocolConfig protocolConfig : protocols) { //按照不同的Protocal暴露服务
- doExportUrlsFor1Protocol(protocolConfig, registryURLs);
- }
- }
而在Spring初始化完成Bean的组装,会调用InitializingBean的afterPropertiesSet方法,在Spring容器加载完成,会接收到事件ContextRefreshedEvent,调用ApplicationListener的onApplicationEvent方法。
在afterPropertiesSet中,和onApplicationEvent中,会调用export(),在export()中,会暴露bbo服务,具体区别在于是否配置了delay属性,是否延迟暴露,如果delay不为null,或者不为-1时,会在afterPropertiesSet中调用export()暴露bbo服务,如果为null,或者为-1时,会在Spring容器初始化完成,接收到ContextRefreshedEvent事件,调用onApplicationEvent,暴露bbo服务。
部分ServiceBean的代码如下:
在export(),暴露服务过程中,如果发现有delay属性,则延迟delay时间,暴露服务,如果没有,则直接暴露服务。
而在doExport()中,验证参数,按照不同的Protocol,比如(bbo,injvm)暴露服务,在不同的zookeeper集群节点上注册自己的服务。
作者:一滴水的坚持
链接:https://www.jianshu.com/p/7f3871492c71
来源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。
Ⅳ 求bbox修改了默认端口,为什么始终会启动20880
zookeeper是Dubbo服务的注册中心,provider提供服务后注册在zookeeper上, consumer可以接口和版本信息从zookeeper中获取内相应的服务,服务对于consumer来说完容全透明,根本感知不到该接口是来自本地和provider,就像引用本地的一个bean一样。
Ⅳ JAVA分布开发bbo问题
首先要搞清楚三者的概念
1、Dubbo是阿里开源的默认基于TCP协议RPC远程服务调度框架,简单理解就是服务A使用TCP协议调用服务B的Dubbo接口。
2、Zookeeper是注册中心,在这里主要用于管理bbo服务提供者和消费者的注册信息与服务调度时提供相关依据。
3、Tomcat是WEB应用服务器,可以对外暴露基于HTTP协议的服务接口。
由于用户访问你的应用首先是通过浏览器,也就是基于HTTP协议,所以必须对外暴露HTTP接口作为入口,那么就需要使用WEB应用服务器,比如Tomcat、Jetty、Undertow等等。
关于不启动tomcat,需要哪些配置的问题如下:
Dubbo支持HTTP协议,但原理任然是通过WEB应用服务器暴漏一个端口。从Dubbo本身专注的领域来说,不建议用HTTP协议,所以最终的结论是,服务与服务之间的接口调用使用Dubbo,而对外暴露HTTP接口任然使用WEB应用服务器。
Ⅵ 如何修改并获得bbo服务的端口号
如何修改并获得bbo服务的端口号
package com.github.doctor.bbo.config;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import com.alibaba.bbo.common.utils.NetUtils;
import com.alibaba.bbo.config.ProtocolConfig;
/**
* 这是一个进程启动多个bbo服务的DubboPortHandler另一种写法。以前的方案见DubboNamespaceHandlerEx
* 利用修改受spring管理bean的属性信息
*
* @author doctor
*
* @time 2014年12月31日 上午9:43:52
*/
@Component
public class DubboPortHandler2 {
@Autowired
private ApplicationContext applicationContext;
private int port = 20080;
@PostConstruct
public void init() {
Map<String, ProtocolConfig> beansOfType = applicationContext.getBeansOfType(ProtocolConfig.class);
for (Entry<String, ProtocolConfig> item : beansOfType.entrySet()) {
port = NetUtils.getAvailablePort();
item.getValue().setPort(port);
}
}
public int getPort() {
return port;
}
}
Ⅶ 如何修改并获得bbo服务的端口号
package com.github.doctor.bbo.config;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import com.alibaba.bbo.common.utils.NetUtils;
import com.alibaba.bbo.config.ProtocolConfig;
/**
* 这是一个进程启动多个bbo服务的DubboPortHandler另一种写法。以前的方案见DubboNamespaceHandlerEx
* 利用spring修改受spring管理bean的属性信息
*
* @author doctor
*
* @time 2014年12月31日 上午9:43:52
*/
@Component
public class DubboPortHandler2 {
@Autowired
private ApplicationContext applicationContext;
private int port = 20080;
@PostConstruct
public void init() {
Map<String, ProtocolConfig> beansOfType = applicationContext.getBeansOfType(ProtocolConfig.class);
for (Entry<String, ProtocolConfig> item : beansOfType.entrySet()) {
port = NetUtils.getAvailablePort();
item.getValue().setPort(port);
}
}
public int getPort() {
return port;
}
}
Ⅷ 怎么修改并获得bbo服务的端口号
如何修改并获得bbo服务的端口号
package com.github.doctor.bbo.config;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.PostConstruct;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Component;
import com.alibaba.bbo.common.utils.NetUtils;
import com.alibaba.bbo.config.ProtocolConfig;
/**
* 这是一个进程启动多个bbo服务的DubboPortHandler另一种写法。以前的方案见DubboNamespaceHandlerEx
* 利用spring修改受spring管理bean的属性信息
*
* @author doctor
*
* @time 2014年12月31日 上午9:43:52
*/
@Component
public class DubboPortHandler2 {
@Autowired
private ApplicationContext applicationContext;
private int port = 20080;
@PostConstruct
public void init() {
Map<String, ProtocolConfig> beansOfType = applicationContext.getBeansOfType(ProtocolConfig.class);
for (Entry<String, ProtocolConfig> item : beansOfType.entrySet()) {
port = NetUtils.getAvailablePort();
item.getValue().setPort(port);
}
}
public int getPort() {
return port;
}
}
Ⅸ <bbo:registry address="zookeeper://127.0.0.1:2181" />是zookeeper的地址吗
127.0.0.1:2181是本机地址
zookeeper的默认端口是218所以算是本地的zookeeper的地址
Ⅹ 在引用bbo服务时 不需要指定端口吗
1.透明化的远程方法调用,就像调用本地方法一样调用远程方法,只需简单配置,没有任何API侵入。
2.软负载均衡及容错机制,可在内网替代F5等硬件负载均衡器,降低成本,减少单点。
3. 服务自动注册与发现,不再需要写死服务提供方地址,注册中心基于接口名查询服务提供者的IP地址,并且能够平滑添加或删除服务提供者。