Dubbo+zookeeper Cluster

Source: Internet
Author: User
Tags zookeeper download

Install Dubbo and use zookeeper as the registration center


Environment Preparation:

Learn about Dubbo Http://dubbo.io/Home-zh.htm

Dubbo Installation:

Zookeeper download Download


Zookeeper Install Pseudo-distributed 1. Unzip the downloaded zookeeper, go to the server, unzip and rename


wget Http://www.apache.org/dist/zookeeper/stable/zookeeper-3.4.6.tar.gztar ZXVF ZOOKEEPER-3.4.6.TAR.GZMV zookeeper-3.4.6 zookeeper-3.4.6-server-1

2. Enter the Conf directory, copy the configuration file, and modify the parameters

CP zoo_sample.cfg Zoo.cfgvi zoo.cfgticktime=2000  initlimit=5  synclimit=2  datadir=/zk/ zookeeper-3.4.6-server-1/zookeeper-3.4.6/datadatalogdir=/zk/zookeeper-3.4.6-server-1/zookeeper-3.4.6/ logsclientport=2182server.1=127.0.0.1:8880:7770  server.2=127.0.0.1:8881:7771  server.3= 127.0.0.1:8882:7772



One needs to modify the DataDir Datalogdir ClientPort, the port cannot be duplicated! Generally I like to create a new data and Logs folder in the Conf sibling directory

Reference http://coolxing.iteye.com/blog/1871009

  • initlimit: The zookeeper cluster contains multiple servers, one of which is leader, and the rest of the servers in the cluster are follower. The Initlimit parameter configures the maximum heartbeat time between follower and leader when the connection is initialized. At this point the parameter is set to 5, stating that the time limit is 5 times times ticktime, or 5*2000=10000ms=10s.

  • synclimit: This parameter configures the maximum length of time to send messages, requests, and responses between leader and follower. At this point the parameter is set to 2, stating that the time limit is twice times ticktime, or 4000ms.

  • server. X=a:b:c where x is a number that indicates which is the first server. A is the IP address where the server resides. b Configure the port used by the server and the leader in the cluster to exchange messages. C Configure the port to use when electing leader. Because the pseudo-cluster mode is configured, the B and C parameters of each server must be different.

3. Enter the data folder specified in the Conf/zoo.cfg and create a new myID file that identifies which of the ZK instances is in the cluster, and the number must be zoo.cfg in the file server. X corresponds to the x in.


Cd/home/web/xiaolong.yuanxl/zookeeper-3.4.6-server-1/dataecho "1" > myID

4. Similarly cp out Zookerper-3.4.6-server-2 and zookerper-3.4.6-server-3, pay attention to modify data, Logs, ClientPort, myID 4 places, then start ZK (turn off the stop restart Restart State status) and watch the boot situation

The port numbers for my server1,server2,server3 are: 2182,2183,2184;myid

start these three zookeeper

CD /zk/zookeeper-3.4.6-server-1/zookeeper-3.4.6/bin   less ./zookeeper.out
5. See if the ZK process is the expected 3, as well as the status (2 Foller, 1 leader)


Web        553     1  0 10:22?        00:00:01/usr/java/jdk1.6.0_20/bin/java-dzookeepe
Web        778     1  0 10:26?        00:00:01/usr/java/jdk1.6.0_20/bin/
Web       1167     1  0 10:37?        00:00:01/usr/java/jdk1.6.0_20/bin/

Leader Information

[Email protected]_dev1 bin]# pwd
/zk/zookeeper-3.4.6-server-3/zookeeper-3.4.6/bin
[Email protected]_dev1 bin]# sh zkserver.sh status
JMX enabled by default
Using config:/zk/zookeeper-3.4.6-server-3/zookeeper-3.4.6/bin/. /conf/zoo.cfg
Mode:follower
[Email protected]_dev1 bin]# Cd/zk/zookeeper-3.4.6-server-2/zookeeper-3.4.6/bin
[Email protected]_dev1 bin]# sh zkserver.sh status
JMX enabled by default
Using config:/zk/zookeeper-3.4.6-server-2/zookeeper-3.4.6/bin/. /conf/zoo.cfg
Mode:leader
[Email protected]_dev1 bin]# Cd/zk/zookeeper-3.4.6-server-1/zookeeper-3.4.6/bin
[Email protected]_dev1 bin]# sh zkserver.sh status
JMX enabled by default
Using config:/zk/zookeeper-3.4.6-server-1/zookeeper-3.4.6/bin/. /conf/zoo.cfg
Mode:follower


Dubbo Admin installation (Web management tool)


Since the Dubbo official website has not opened, here is my cloud disk sharing

Http://pan.baidu.com/s/1pJ7o9PT

ZK installation given by the official website

dubbo-admin installation given by the official website

1. Download the Dubbo-admin-2.5.4.war package and put it under Tomcat/webapps

Change the dubbo.properties file

vi. /webapps/dubbo-admin-2.5.4/web-inf/dubbo.propertiesdubbo.registry.aaaddress=zookeeper://127.0.0.1:2183  dubbo.admin.guest.password=guest  

arbitrarily change the previously configured port number;



Start Tomcat, Access http://ip:8080/dubbo-admin-2.5.4/, enter the default user name root password: root




Dubbo Provider Consumer Example


Official Homepage Example

Provider: interface
Package Com.fpx.dubbo;public interface Demoservice {public void SayHello ();


Provider: Implementing




Package Com.fpx.dubbo;public class Demoserviceimpl implements Demoservice {public void SayHello () {System.out.println (" Hello 00! ");}}



P rovider configuration file


<?xml version= "1.0" encoding= "UTF-8"? ><beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo= "Http://code.alibabatech.com/schema/dubbo" xsi: schemalocation= "Http://www.springframework.org/schema/beans          http://www.springframework.org/schema/beans/ Spring-beans.xsd          Http://code.alibabatech.com/schema/dubbo          http://code.alibabatech.com/schema/dubbo/ Dubbo.xsd "><dubbo:application name=" Hello-world-app "/><dubbo:registry protocol=" zookeeper "address=" zookeeper://172.16.30.206:2183?backup=172.16.30.206:2182,172.16.30.206:2184 "/><dubbo:protocol name=" Dubbo "Port=" 20880 "/><dubbo:service interface=" Com.fpx.dubbo.DemoService "ref=" Demoservice "/>       <!-- Implement services like local beans--><bean id= "Demoservice" class= "Com.fpx.dubbo.DemoServiceImpl"/></beans>



P RoviderStart class


Package Com.fpx.dubbo;import Org.springframework.context.support.classpathxmlapplicationcontext;public Class Dubboproviderdemo {public static void main (string[] args) throws Interruptedexception {    new Classpathxmlapplicationcontext (New string[]{"Provider.xml"}); while (true) {}}}



Consumer configuration file

<?xml version= "1.0" encoding= "UTF-8"?> <beans xmlns= "Http://www.springframework.org/schema/beans" xmlns: Xsi= "Http://www.w3.org/2001/XMLSchema-instance" xmlns:dubbo= "Http://code.alibabatech.com/schema/dubbo" xsi : schemalocation= "Http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/ Spring-beans.xsd Http://code.alibabatech.com/schema/dubbo Http://code.alibabatech.com/schema/dubbo/dubbo . xsd > <!--consumer app name, used to calculate dependencies, not match criteria, not as providers--<dubbo:application name= "Consumer-of-hello World-app "/> <!--using multicast broadcast registry to expose the Discovery service address--<dubbo:registry protocol=" zookeeper "address=" zoo keeper://172.16.30.206:2183?backup=172.16.30.206:2182,172.16.30.206:2184 "/> <!--generate a remote service proxy that uses the same dem as a local bean Oservice--<dubbo:reference id= "Demoservice" interface= "Com.fpx.dubbo.DemoService"/> </beans>





Consumer Startup class


Package Com.fpx.dubbo;import Org.springframework.context.applicationcontext;import Org.springframework.context.support.classpathxmlapplicationcontext;public class Dubbocomsumedemo {public      static void Main (string[] args) throws Interruptedexception {          ApplicationContext factory = new Classpathxmlapplicationcontext (                  new string[] {"Comsumer.xml"});          Demoservice Demoservice = (demoservice) factory.getbean ("Demoservice");        Demoservice.sayhello ();      }  }



start provider first, then start consumer


The console also outputs "Hello 00!";


the problem encountered:

[INFO] 11:48:16 (clientcnxn.java:975)-Opening socket connection to server 172.16.30.206/172.16.30.206:2182. Won't attempt to authenticate using SASL (unknown error) [INFO] 11:48:26 (clientcnxn.java:1096)-Client session timed Out, with not heard from server in 10001ms for SessionID 0x0, closing socket connection and attempting reconnect[debug] 11 : 48:26 (clientcnxnsocketnio.java:203)-ignoring exception during shutdown Inputjava.net.SocketException:Socket is not C Onnectedat sun.nio.ch.Net.translateToSocketException (net.java:149) at Sun.nio.ch.Net.translateException (Net.java : 183) at Sun.nio.ch.Net.translateException (net.java:189) at Sun.nio.ch.SocketAdaptor.shutdownInput ( socketadaptor.java:428) at Org.apache.zookeeper.ClientCnxnSocketNIO.cleanup (clientcnxnsocketnio.java:200) at Org.apache.zookeeper.clientcnxn$sendthread.cleanup (clientcnxn.java:1185) at org.apache.zookeeper.clientcnxn$ Sendthread.run (clientcnxn.java:1110) caused By:java.nio.channels.NotYetConnectedExceptionat sun.nio.ch. Socketchannelimpl.shutdowninput (socketchannelimpl.java:800) at Sun.nio.ch.SocketAdaptor.shutdownInput ( socketadaptor.java:426) ... 3 More[debug] 11:48:26 (clientcnxnsocketnio.java:210)-ignoring exception during shutdown output


start the service Times connection failed, check after the original is my Ubuntu firewall problem;

Workaround:

Vi/etc/sysconfig/iptables

Add Port information:


-A input-m state--state new-m tcp-p TCP--dport 2182-j accept-a input-m State--state new-m tcp-p TCP--dport 2183 -j accept-a input-m State--state new-m tcp-p TCP--dport 2184-j ACCEPT



Restarting the firewall


Service Iptables Restart

Restart the provider, and then start the consumer just fine!








Dubbo+zookeeper Cluster

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.