zooKeeper: Installation and configuration of high-availability clusters

http://wosyingjun.iteye.com/blog/2312960

Zookeeper serves as the registration and coordination center for many services (dubbo, jstom, etc.), so a high-availability cluster solution is also essential. When clustering Zookeeper, pay attention to the number of nodes in the ZK cluster It is more suitable to be an odd number (2n+1: such as 3, 5, 7 nodes).
Example project: http://wosyingjun.iteye.com/blog/2312553



1. Download and upload zookeeper-3.4.6.tar.gz to the /usr/local/ directory of each server
$ cd /usr/local/
$ wget http ://apache.fayea.com/zookeeper/zookeeper-3.4.6/zookeeper-3.4.6.tar.gz
2. Unzip the zookeeper installation package on each server, and rename the zookeeper directory according to the node number
$ tar -zxvf zookeeper-3.4.6.tar.gz
server 1:
$ mv zookeeper-3.4.6 zookeeper-3.4.6_(1)
server 2:
$ mv zookeeper-3.4.6 zookeeper-3.4.6_(2)
server 3:
$ mv zookeeper-3.4.6 zookeeper-3.4.6_(3)
3. Create the following directory under each zookeeper node directory:
$ cd /usr/local/zookeeper-3.4.6_(x) (x represents the node number)
$ mkdir data
$ mkdir logs
4. Copy the zoo_sample.cfg file in the zookeeper/zookeeper-3.4.6_(x)/conf directory and name it zoo.cfg:
$ cp zoo_sample.cfg zoo.cfg
5. Modify zoo .cfg configuration file
#zookeeper-3.4.6_(1) The configuration (/usr/local/zookeeper-3.4.6_(1)/conf/zoo.cfg) is as follows:
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/ usr/local/zookeeper-3.4.6_(1)/data
dataLogDir=/usr/local/zookeeper-3.4.6_(1)/logs
clientPort=2181
server.1=192.168.11.97:2881:3881
server.2=192.168 .11.98:2882:3882
server.3=192.168.11.99:2883:3883

#zookeeper-3.4.6_(2) configuration (/usr/local/zookeeper-3.4.6_(2)/conf/zoo.cfg) is as follows :
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper-3.4.6_(2)/data
dataLogDir=/usr/local/zookeeper-3.4.6_(2)/logs
clientPort=2182
server.1=192.168.11.97:2881:3881
server.2=192.168.11.98:2882:3882
server.3=192.168.11.99:2883:3883

#zookeeper-3.4.6_(3)的配置(/usr/local/zookeeper-3.4.6_(3)/conf/zoo.cfg)如下:
tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper-3.4.6_(3)/data
dataLogDir=/usr/local/zookeeper-3.4.6_(3)/logs
clientPort=2183
server.1=192.168.11.97:2881:3881
server.2=192.168.11.98:2882:3882
server.3=192.168.11.99:2883:3883
参数说明
tickTime=2000
The time tickTime is used as the time interval for maintaining heartbeats between Zookeeper servers or between the client and the server, that is, a heartbeat is sent every tickTime.

initLimit=10
This configuration item initLimit is used to configure Zookeeper to accept clients (the client mentioned here is not the client that the user connects to the Zookeeper server, but the Follower server connected to the Leader in the Zookeeper server cluster). How many heartbeat intervals to tolerate. When the Zookeeper server has not received the return information from the client after more than 10 heartbeats (that is, tickTime), it indicates that the client connection failed. The total time length is 10*2000=20 seconds.

syncLimit=5
syncLimit This configuration item identifies the length of the message, request and response time sent between the Leader and the Follower. The longest time length cannot exceed the length of several tickTimes, and the total time length is 5*2000=10 seconds.

dataDir=/usr/local/zookeeper-3.4.6_(x)/data
dataDir, as the name suggests, is the directory where Zookeeper saves data. By default, Zookeeper also saves log files for writing data in this directory.

clientPort=2181
clientPort This port is the port for the client (application) to connect to the Zookeeper server, and Zookeeper will listen to this port to accept client access requests.

server.A=B:C:D
server.1=192.168.11.97:2881:3881
server.2=192.168.11.98:2882:3882
server.3=192.168.11.99:2883:3883
A is a number, indicating which server number this is;
B is the IP address of this server (or is done with the IP address) Mapped host name);
C The first port is used for information exchange among cluster members, indicating the port for this server to exchange information with the leader server in the cluster;
D is the port used to elect the leader when the leader hangs up.

6. Create a myid file under dataDir=/usr/local/zookeeper-3.4.6_(x)/data
$ vi /usr/local/zookeeper-3.4.6(1) /data/myid set the value to 1
$ vi / usr/local/zookeeper-3.4.6(2) /data/myid set the value to 1
$ vi /usr/local/zookeeper-3.4.6_(3) /data/myid set the value to 3

7. Open in the firewall Ports to be used 218X, 288X, 388X
$ vi /etc/sysconfig/iptables
-A INPUT -m state --state NEW -m tcp -p tcp --dport 218X -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 288X -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 388X -j ACCEPT
$ service iptables restart

8. Start and view zookeeper:
$ /usr/local/zookeeper-3.4.6(x)/bin /zkServer.sh start
$ /usr/local/zookeeper-3.4.6(x)/bin/zkServer.sh status

9. Modify the client configuration for connecting to zookeeper:
zookeeper://192.168.11.97:2181?backup=192.168. 11.98:2182,192.168.11.99:2183

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326266939&siteId=291194637