alibaba dubbo基本上已经停止更新了,新用户请使用当当维护的 dubbox, dubbox 在 dubbo 的基础上添加了对 restfull 的支持,升级了 spring。
安装Git, JDK 和 Maven
-
安装jdk, git
yum install java-1.8.0-openjdk java-1.8.0-openjdk-devel git
-
安装maven
cd /usr/local/src/ wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz tar -zxf apache-maven-3.3.9-bin.tar.gz mv apache-maven-3.3.9 /usr/local/ ln -s /usr/local/apache-maven-3.3.9 /usr/local/apache-maven
-
添加环境变量
echo >> /root/.bash_profile <<eof export JAVA_HOME=/usr/lib/jvm/jre-1.8.0-openjdk.x86_64 export PATH=$JAVA_HOME/bin:$PATH export M2_HOME=/usr/local/apache-maven/ export PATH=$PATH:$M2_HOME/bin eof
-
生效环境变量
. /root/.bash_profile
-
测试java
[root@openstack_test ~]# java -version openjdk version "1.8.0_101" OpenJDK Runtime Environment (build 1.8.0_101-b13) OpenJDK 64-Bit Server VM (build 25.101-b13, mixed mode)
-
测试maven
[root@openstack_test ~]# mvn -version Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-11T00:41:47+08:00) Maven home: /usr/local/apache-maven Java version: 1.8.0_101, vendor: Oracle Corporation Java home: /usr/lib/jvm/java-1.8.0-openjdk-1.8.0.101-3.b13.el6_8.x86_64/jre Default locale: en_US, platform encoding: UTF-8 OS name: "linux", version: "2.6.32-573.18.1.el6.x86_64", arch: "amd64", family: "unix"
编译dubbo
-
安装opensesame
cd /usr/local/src/ git clone https://github.com/alibaba/opensesame.git cd opensesame/ mvn clean install -Dmaven.test.skip
-
获取dubbo源码
cd /usr/local/src/ git clone https://github.com/alibaba/dubbo.git dubbo cd /usr/local/src/dubbo cp -r hessian-lite/ ../ git checkout dubbo-2.5.3 cp -r ../hessian-lite/ ./
-
修改pom.xml
<modules> <module>hessian-lite</module> <!-- 添加hessian-lite --> <module>dubbo-common</module> <module>dubbo-container</module> <module>dubbo-remoting</module> ......... </modules> <properties> ......... <fastjson_version>1.1.39</fastjson_version> <!-- 修改版本为 1.1.39 --> ......... </properties>
-
修改 hessian-lite/pom.xml
<parent> <groupId>com.alibaba</groupId> <artifactId>dubbo-parent</artifactId> <version>2.5.3</version> <!-- 修改版本为2.5.3 --> </parent>
-
修改 dubbo-admin/pom.xml
webx的依赖改为3.1.6版;
<dependency> <groupId>com.alibaba.citrus</groupId> <artifactId>citrus-webx-all</artifactId> <version>3.1.6</version> </dependency>
添加velocity的依赖
<dependency> <groupId>org.apache.velocity</groupId> <artifactId>velocity</artifactId> <version>1.7</version> </dependency>
对依赖项dubbo添加exclusion,避免引入旧spring
<dependency> <groupId>com.alibaba</groupId> <artifactId>dubbo</artifactId> <version>${project.parent.version}</version> <exclusions> <exclusion> <groupId>org.springframework</groupId> <artifactId>spring</artifactId> </exclusion> </exclusions> </dependency>
webx已有spring 3以上的依赖,因此注释掉dubbo-admin里面的spring依赖
<!--<dependency>--> <!--<groupId>org.springframework</groupId>--> <!--<artifactId>spring</artifactId>--> <!--</dependency>-->
-
编译
mvn clean install -Dmaven.test.skip
安装ZooKeeper
-
安装zookeeper
cd /usr/local/src wget http://apache.fayea.com/zookeeper/zookeeper-3.4.8/zookeeper-3.4.8.tar.gz tar -zxf zookeeper-3.4.8.tar.gz cp -r zookeeper-3.4.8 /usr/local/ ln -s /usr/local/zookeeper-3.4.8/ /usr/local/zookeeper
-
修改配置
cd /usr/local/zookeeper/ cp conf/zoo_sample.cfg conf/zoo.cfg echo > conf/zoo.cfg <<eof tickTime=2000 initLimit=10 syncLimit=5 dataDir=/var/lib/zookeeper # 修改ZooKeeper快照存储路径 clientPort=2181 eof
-
启动&测试
启动 server 端
bin/zkServer.sh start
启动客户端,尝试创建、查询节点
bin/zkCli.sh -server localhost:2181 [zk: localhost:2181(CONNECTED) 3] create /test 1111 Created /test [zk: localhost:2181(CONNECTED) 4] get /test 1111 cZxid = 0x2 ctime = Thu Sep 01 08:59:24 CST 2016 mZxid = 0x2 mtime = Thu Sep 01 08:59:24 CST 2016 pZxid = 0x2 cversion = 0 dataVersion = 0 aclVersion = 0 ephemeralOwner = 0x0 dataLength = 4 numChildren = 0
安装dubbo-admin
-
安装tomcat
yum install tomcat6
-
部署 dubbo-admin 代码
mkdir /var/lib/tomcat6/webapps/ROOT/ unzip dubbo-admin/target/dubbo-admin-2.5.3.war -d /var/lib/tomcat6/webapps/ROOT/
确认/var/lib/tomcat6/webapps/ROOT/WEB-INF/dubbo.properties 中ZooKeeper的地址是否正确。本例中,该配置无需修改。 然后就可以启动tomcat了。
/etc/init.d/tomcat6 restart
可以通过浏览器访问 dubbo-admin。
启动demon
provider
cd /usr/local/src/dubbo/dubbo-demo/dubbo-demo-provider/target/
tar -zxf dubbo-demo-provider-2.5.3-assembly.tar.gz
cd dubbo-demo-provider-2.5.3
修改 conf/dubbo.properties
#dubbo.registry.address=multicast://224.5.6.7:1234
dubbo.registry.address=zookeeper://127.0.0.1:2181
启动provider
bin/start.sh
consumer
cd /usr/local/src/dubbo/dubbo-demo/dubbo-demo-consumer/target/
tar -zxf dubbo-demo-consumer-2.5.3-assembly.tar.gz
cd dubbo-demo-consumer-2.5.3
修改 conf/dubbo.properties
#dubbo.registry.address=multicast://224.5.6.7:1234
dubbo.registry.address=zookeeper://127.0.0.1:2181
启动consumer
bin/start.sh
确认
在consumer的日志中可以看到provider的正常回应。
在dubbo-admin的 服务治理>>服务 页面也可以看到consumer和provider注册的服务,说明服务正常启动。