zookeeper個人理解

瓜瓜東西發表於2014-10-10

1

2

2 安裝

單機模式

解壓,bin/zkserver.sh

配置檔案更改 conf/zoo_sample.cfg conf/zoo.cfg

Ticktime 心跳

Dtatdir 資料和日誌路徑

Clientprot

3 叢集模式

除了改上面三個還有

initLimit:follower伺服器返回給主節點的時間心跳個數,例如

ticktime=2000,initlimit=5,如果2000*5=10000=10s沒返回結果就是連線失敗

synclimit:請求應答心跳個數,和initlimit計算類似

server.a=b:c:d

a 機器號

b ip

c lead和機器互動埠

d 選舉 lead掛了後的 lead通訊用

然後:

Myid 檔案儲存a(服務名),啟動時讀取從而判斷到底是哪個server,路徑是datadir

Myid哪個機器就存哪個名字

 

4 偽叢集模式

同一個機器通過配置不同的埠達到目的

 

3

package com.zookeeper.example; 

import java.util.ArrayList;
import java.util.List;

import com.sun.org.apache.bcel.internal.generic.NEW;

import sun.security.krb5.internal.NetClient;

public class ZookeeperSam {

	int num=20;
}
class Zookeeper{
	int num;
	int searchNum;
	int indexNum;
	String leadState;
	CGI cgi;
	LeadServiceMechine leadServiceMechine;
	BakLeadServiceMechine bakLeadServiceMechine;
	public void changeLeadService(){
		if(leadState=="down"){
			startLeadService(bakLeadServiceMechine);
			changeCGINetAndAdd(cgi);
		}
	}
	public void startLeadService(Service service){
		
	}
	public void changeCGINetAndAdd(CGI cgi){
		
	}
	
	public void run(){
		buildZNode("a");
		getChildren("a");
		getChildrenList();
		if(judgeChange()!=null){
			
		}
	}
	
	public void buildZNode(String str){
		ZNode zNode = new ZNode(str);
		nodes.add(zNode);
	}
	List<ZNode> nodes = new ArrayList<ZNode>();
	public void getChildren(String name){
		
	}
	public void getChildrenList(){
		
	}
	
	public ZNode judgeChange(){
		return null;
	}
}
class ZNode{
	public ZNode(){
		
	}
	public ZNode(String s){
		
	}
	
}
class CGI{
	
}
class Service{
	Net net;
	Address address;
}
class Net{
	
}
class Address{
	
}
class LeadServiceMechine extends Service{
	
}
class BakLeadServiceMechine extends Service{
	
}
class ServiceMechine{
	String state;//5/15//狀態可以切換
	Zookeeper zookeeper;
	public void deal(){
		if(state=="index"){
			
		}
		if("search"==state){
			
		}
	}
}
class NameService{
	
}
class StateSyncService{
	
}
class ClusterManager{
	
}
class ConfigureManager{
	
}


 

相關文章