hsf(ali-tomcat)安装使用
官网: https://help.aliyun.com/document_detail/90754.html?spm=a2c4g.11186623.6.599.771f41d9MaMUqFali-tomcat概述:注意:第二步需要将下载的Pandora容器taobao-hsf.tgz放到/data/ilucky/hsf/taobao-tomcat-7.0.59/deploy目录下,同...
官网: https://help.aliyun.com/document_detail/90754.html?spm=a2c4g.11186623.6.599.771f41d9MaMUqF
ali-tomcat概述:
注意:
第二步需要将下载的Pandora容器taobao-hsf.tgz放到/data/ilucky/hsf/taobao-tomcat-7.0.59/deploy目录下,
同时解压缩,最终生成taobao-hsf.sar目录。
/data/ilucky/hsf/taobao-tomcat-7.0.59
root@5942:/data/ilucky/hsf/taobao-tomcat-7.0.59# cd deploy/
root@5942:/data/ilucky/hsf/taobao-tomcat-7.0.59/deploy# ls
itemcenter itemcenter.war taobao-hsf.sar taobao-hsf.tgz
root@5942:/data/ilucky/hsf/taobao-tomcat-7.0.59/deploy#
配置开发环境:
配置开发环境,暂时忽略,因为没有开发的需求~
轻量配置中心:
注意: 无论是在需要访问轻量配置中心的机器上,还是consumer & provider所在的机器上都需要配置: 192.168.1.100 jmenv.tbsite.net
如果通过访问http://jmenv.tbsite.net:8080出现如下页面,说明轻量配置中心安装成功。
EDSA SDK开发:
https://help.aliyun.com/document_detail/99912.html?spm=a2c4g.11186623.6.602.769f5e31yOvDRS
原始demo 代码内容很简单,如果使用过dubbo,极为类似,一目了然~) 需要注意: carshop下三个项目的角色。
通过查看detail(Consumer服务)代码 ,可以知道这是一个war项目,只包含一个Servlet (测试)和一个Listener。
Listener内容也能很简单: 一个while(true), 即周期性的去访问Provider服务。
package com.alibaba.edas.carshop.detail;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import com.alibaba.edas.carshop.itemcenter.ItemService;
/**
* Alibaba Group EDAS. http://www.aliyun.com/product/edas
*/
public class StartListener implements ServletContextListener{
@Override
public void contextInitialized( ServletContextEvent sce ) {
ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext( sce.getServletContext() );
final ItemService itemService = ( ItemService ) ctx.getBean( "item" );
Thread thread = new Thread( new Runnable() {
@Override
public void run() {
while ( true ) {
try {
Thread.sleep( 500l );
System.out.println( itemService.getItemById( 1111 ) );
System.out.println( itemService.getItemByName( "myname is le" ) );
} catch ( Throwable e ) {
e.printStackTrace();
}
}
}
} );
thread.start();
}
@Override
public void contextDestroyed( ServletContextEvent sce ) {
// TODO Auto-generated method stub
}
}
通过maven将detail打包, 连同上面的taobao-hsf.sar放到${taobao_ali_tomcat_home}/depoly目录下,启动tomcat服务,则Consuemr部署成功。
注意: Consuemr服务器上需要配置hosts: 10.0.1.224 jmenv.tbsite.net(轻量配置中心所在服务器)
接着看itemcenter (Provider) 服务, Provider服务同样是一个war项目,只包含一个Servlet(用来测试)和Hsf服务的实现类,如下:
package com.alibaba.edas.carshop.itemcenter;
import java.util.Random;
/**
* Alibaba Group EDAS. http://www.aliyun.com/product/edas
*/
public class ItemServiceImpl implements ItemService {
@Override
public Item getItemById( long id ) {
Item car = new Item();
car.setItemId( 1l );
car.setItemName( "Mercedes Benz" );
return car;
}
@Override
public Item getItemByName( String name ) {
Item car = new Item();
car.setItemId( 1l );
car.setItemName( "Mercedes Benz" );
return car;
}
}
通过maven将itemcenter打包, 连同上面的taobao-hsf.sar放到${taobao_ali_tomcat_home}/depoly目录下,启动tomcat服务,则Provider部署成功。
注意:Provider服务器上需要配置hosts: 10.0.1.224 jmenv.tbsite.net(轻量配置中心所在服务器)
最后观察轻量配置中心的界面上的服务列表(提供者列表和调用者列表)是否准确。同时结合Consumer和Provider日志,看是否有异常信息。
安装使用时遇到的问题:
- 如果启动consumer对应的ali-tomcat服务时,报如下错误,说明没有配置hosts: 10.0.1.224 jmenv.tbsite.net
Sat Mar 09 03:34:10 CST 2019 diamond-client's ModuleClassLoader JM.Log:INFO Set diamond-client log path: /root/logs/diamond-client
java.lang.RuntimeException: fail to get diamond-server serverlist! env:default, not connnect url:http://jmenv.tbsite.net:8080/diamond-server/diamond
at com.taobao.diamond.client.impl.ServerListManager.start(ServerListManager.java:79)
at com.taobao.diamond.client.impl.DiamondEnv.initServerManager(DiamondEnv.java:1499)
at com.taobao.diamond.client.impl.DiamondEnv.<init>(DiamondEnv.java:1531)
at com.taobao.diamond.client.impl.DiamondEnvRepo.getDefaultEnv(DiamondEnvRepo.java:96)
at com.taobao.diamond.client.impl.DiamondEnvRepo.<clinit>(DiamondEnvRepo.java:127)
at com.taobao.diamond.client.Diamond.getConfig(Diamond.java:74)
at com.taobao.hsf.diamond.manager.DiamondGovernanceServiceImpl.getConfigSync(DiamondGovernanceServiceImpl.java:65)
at com.taobao.hsf.plugins.globalrule.GlobalRuleComponent.init(GlobalRuleComponent.java:63)
at com.taobao.hsf.model.ApplicationModel.init(ApplicationModel.java:102)
at com.taobao.hsf.model.ApplicationModelFactory.getMainApplicationModel(ApplicationModelFactory.java:230)
at com.taobao.hsf.model.ApplicationModelFactory.getCurrentApplication(ApplicationModelFactory.java:158)
at com.taobao.hsf.util.HSFServiceContainer.getAppServiceContainer(HSFServiceContainer.java:143)
at com.taobao.hsf.util.HSFServiceContainer.getInstance(HSFServiceContainer.java:41)
at com.taobao.hsf.common.impl.EnvImpl.<init>(EnvImpl.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.lang.Class.newInstance(Class.java:442)
at com.taobao.hsf.util.ServiceLoaderUtils.newSpiInstance(ServiceLoaderUtils.java:130)
at com.taobao.hsf.util.AppServiceContainer.getPrototype(AppServiceContainer.java:480)
at com.taobao.hsf.util.AppServiceContainer.getSingleton(AppServiceContainer.java:521)
at com.taobao.hsf.util.AppServiceContainer.createInstance(AppServiceContainer.java:433)
at com.taobao.hsf.util.AppServiceContainer.findInstances(AppServiceContainer.java:366)
at com.taobao.hsf.util.AppServiceContainer.getInstance(AppServiceContainer.java:291)
at com.taobao.hsf.util.AppServiceContainer.getInstance(AppServiceContainer.java:182)
at com.taobao.hsf.route.component.MachineGroupServiceImpl.<init>(MachineGroupServiceImpl.java:19)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.lang.Class.newInstance(Class.java:442)
Caused by: java.lang.NoClassDefFoundError: Could not initialize class com.taobao.diamond.client.impl.DiamondEnvRepo
参考: https://help.aliyun.com/knowledge_detail/43931.html?spm=a2c4g.11186631.2.3.666260acELCUyK
2. Proivder服务启动后,一直注册不到轻量配置中心,即在服务列表的提供者列表中看不到。
后来发现,没有将taobao-hsf.sar放到${taobao_ali_tomcat_home}/depoly目录下,所以服务启动后没有去注册。这是一个疏忽,正确的启动日志如下:
Sat Mar 09 08:17:21 UTC 2019 hsf's ModuleClassLoader JM.Log:INFO Set hsf log path: /root/logs/hsf
Sat Mar 09 08:17:22 UTC 2019 diamond-client's ModuleClassLoader JM.Log:INFO Init JM logger with Slf4jLoggerFactory success, diamond-client's ModuleClassLoader
Sat Mar 09 08:17:22 UTC 2019 diamond-client's ModuleClassLoader JM.Log:INFO Log root path: /root/logs/
Sat Mar 09 08:17:22 UTC 2019 diamond-client's ModuleClassLoader JM.Log:INFO Set diamond-client log path: /root/logs/diamond-client
08:17:22.969 [localhost-startStop-1] INFO c.t.d.identify.CredentialWatcher - [] [] [] No credential found
*******************HSF PORT:12202 **************
*************Pandora QOS PORT:12203 **************
*************Tomcat Monitor Port:8006 **************
*******************Sentinel PORT:8719 **************
log4j:WARN No appenders could be found for logger (io.netty.util.internal.logging.InternalLoggerFactory).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
****************************************************************************************
** **
** Pandora Container **
** **
** Pandora Host: 0.0.23.54 **
** Pandora Version: 2.1.4 **
** SAR Version: edas.sar.V3.4.6.dev **
** Package Time: 2018-07-06 08:16:55 **
** **
** Plug-in Modules: 16 **
** **
** metrics .......................................... 1.7.0 **
** edas-assist ...................................... 2.0 **
** pandora-qos-service .............................. edas215 **
** pandolet ......................................... 1.0.0 **
** spas-sdk-client .................................. 1.2.7 **
** eagleeye-core .................................... 1.7.4.1-SNAPSHOT **
** tddl-driver ...................................... 1.0.5-SNAPSHOT **
** vipserver-client ................................. 4.6.8-SNAPSHOT **
** diamond-client ................................... 3.8.10 **
** spas-sdk-service ................................. 1.2.7 **
** config-client .................................... 1.9.6 **
** unitrouter ....................................... 1.0.11 **
** sentinel-plugin .................................. 2.12.12-edas **
** ons-client ....................................... 1.7.1-EagleEye-SNAPSHOT **
** hsf .............................................. 2.2.6.1-EDAS **
** pandora-framework ................................ 2.0.8 **
** **
** [WARNING] All these plug-in modules will override maven pom.xml dependencies. **
** More: http://gitlab.alibaba-inc.com/middleware-container/pandora/wikis/home **
** **
****************************************************************************************
INFO: spas-client-initializer start
JM.Log:INFO Init JM logger with Log4jLoggerFactory
JM.Log:INFO Log root path: /root/logs/
JM.Log:INFO Set pandora log path: /root/logs/pandora
2019-03-09 08:17:24,061 com.taobao.tomcat.container.context.pandora.PandoraManager startInternal
INFO: Pandora container started.
2019-03-09 08:17:25,062 org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization started
2019-03-09 08:17:25,165 org.springframework.context.support.AbstractApplicationContext prepareRefresh
INFO: Refreshing org.springframework.web.context.support.XmlWebApplicationContext@33f5229c: display name [Root WebApplicationContext]; startup date [Sat Mar 09 08:17:25 UTC 2019]; root of context hierarchy
2019-03-09 08:17:25,318 org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [hsf-provider-beans.xml]
2019-03-09 08:17:25,716 org.springframework.context.support.AbstractApplicationContext obtainFreshBeanFactory
INFO: Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@33f5229c]: org.springframework.beans.factory.support.DefaultListableBeanFactory@13fcb98a
2019-03-09 08:17:26,168 org.springframework.beans.factory.support.DefaultListableBeanFactory preInstantiateSingletons
INFO: Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@13fcb98a: defining beans [itemService,itemServiceProvider]; root of factory hierarchy
Sat Mar 09 08:17:27 UTC 2019 config-client's ModuleClassLoader JM.Log:INFO Init JM logger with Slf4jLoggerFactory success, config-client's ModuleClassLoader
Sat Mar 09 08:17:27 UTC 2019 config-client's ModuleClassLoader JM.Log:INFO Log root path: /root/logs/
08:17:27.644 [HSF-Framework-ExportRefer-6-thread-1] INFO ConfigClientLogger - [] [] [] JM_CC_LOG_RETAIN_COUNT:6, JM_LOG_FILE_SIZE:200MB
Sat Mar 09 08:17:27 UTC 2019 config-client's ModuleClassLoader JM.Log:INFO Set configclient log path: /root/logs/configclient
2019-03-09 08:17:28,032 org.springframework.web.context.ContextLoader initWebApplicationContext
INFO: Root WebApplicationContext: initialization completed in 2969 ms
2019-03-09 08:17:28,092 org.apache.catalina.startup.HostConfig deployWAR
INFO: Deployment of web application archive /data/ilucky/hsf/taobao-tomcat-7.0.59/deploy/itemcenter.war has finished in 17,338 ms
2019-03-09 08:17:28,100 org.apache.coyote.AbstractProtocol start
INFO: Starting ProtocolHandler ["http-bio-8080"]
2019-03-09 08:17:28,131 org.apache.catalina.startup.Catalina start
INFO: Server startup in 17579 ms
- 解决了上面的问题,轻量配置中的服务列表-提供者列表有了提供者内容,但是Consumer调用Provider服务时报如下错误信息:
HTTP Status 500 - HSFServiceAddressNotFoundException-
type Exception report
message HSFServiceAddressNotFoundException-
description The server encountered an internal error that prevented it from fulfilling this request.
exception
com.taobao.hsf.exception.HSFServiceAddressNotFoundException: HSFServiceAddressNotFoundException-
error message : [HSF-Consumer] can't find target service addresses, target serviceName:com.alibaba.edas.carshop.itemcenter.ItemService:1.0.0 Group:HSF ERR-CODE: [HSF-0001], Type: [BIZ], More: [http://edas.console.aliyun.com/code?faq=HSF-0001]
com.taobao.hsf.registry.RegistryInvocationHandler.invoke(RegistryInvocationHandler.java:173)
com.taobao.hsf.invocation.DelegateInvocationHandler.invoke(DelegateInvocationHandler.java:12)
com.taobao.hsf.remoting.service.LocalInvocationHandler.invoke(LocalInvocationHandler.java:99)
com.taobao.hsf.invocation.filter.RPCFilterBuilder$TailNode.invoke(RPCFilterBuilder.java:280)
com.taobao.hsf2dubbo.context.DubboRPCContextClientFilter.invoke(DubboRPCContextClientFilter.java:43)
com.taobao.hsf.invocation.filter.RPCFilterNode.invoke(RPCFilterNode.java:71)
com.taobao.hsf.context.RPCContextClientFilter.invoke(RPCContextClientFilter.java:31)
错误的意思是: Consumer不可以消费到正确的Provider服务。参考: https://blog.csdn.net/shengqianfeng/article/details/84373515
检查Provider的详情: 发现Provider对外提供的服务是0.0.23.54,并不是10.0.3.42.
同时查看Provider日志,发现地址也是错误的:
如何去修改这个地址呢? 发现官网上的解决办法:
即在jvm参数中添加-Dhsf.server.ip=10.0.3.42。
再次启动服务,查看提供者详情,发现地址调整过来了。Consumer日志也不报错误了,可以正常调用了。
注意: 这里还有一个hsf的小bug,即提供者详情改过来了,但是日志打印却没有改过来。
更多推荐
所有评论(0)