Detailed steps to install the ZooKeeper registry (single node)

Install Dubbo registry (Zookeeper-3.4.6)

 

Dubbo recommends using Zookeeper as a registry for services.

 

Registry server (192.168.1.128) configuration, install Zookeeper:

1.  Modify the /etc/hosts file of the operating system

Add to:

#zookeeper servers

  1. 192.168.1.128   localhost                                      

In this way, the machine whose IP is 192.168.1.128 can be mapped to the corresponding domain name

 

2. Go to http://apache.fayea.com/zookeeper/ to download zookeeper-3.4.6:

yum install http://apache.fayea.com/zookeeper/zookeeper-3.4.6/

 

3. Unzip the zookeeper installation package:

$ tar -zxvf zookeeper-3.4.6.tar.gz

 

4. Create the following directories in the /home/zhaoxing/zookeeper-3.4.6 directory:

cd /home/zhaoxing/zookeeper-3.4.6

mkdir data

mkdir logs

 

5. Copy the zoo_sample.cfg file in the zookeeper-3.4.6/conf directory and name it zoo.cfg

cp zoo_sample.cfg zoo.cfg

 

6.   Modify the zoo.cfg configuration file:

vi zoo.cfg

# The number of milliseconds of each tick

tickTime=2000

# The number of ticks thatthe initial

# synchronization phase cantake

initLimit = 10

# The number of ticks thatcan pass between

# sending a request andgetting an acknowledgement

syncLimit=5

# the directory where thesnapshot is stored.

# do not use /tmp forstorage, /tmp here is just

# example sakes.

dataDir=/home/zhaoxing/zookeeper-3.4.6/data

# dataLogDir=/home/zhaoxing/zookeeper-3.4.6/logs

# the port at which theclients will connect

clientPort=2181

#2888,3888 are election port

server.1=localhost:2888:3888

 

in,

The 2888 port number is the port for communication between zookeeper services.

3888 is the port through which zookeeper communicates with other applications.

localhost是在hosts中已映射了IP的主机名。

 

initLimit:这个配置项是用来配置 Zookeeper 接受客户端(这里所说的客户端不是用户连接 Zookeeper服务器的客户端,而是 Zookeeper 服务器集群中连接到 Leader 的 Follower 服务器)初始化连接时最长能忍受多少个心跳时间间隔数。当已经超过 10个心跳的时间(也就是 tickTime)长度后Zookeeper 服务器还没有收到客户端的返回信息,那么表明这个客户端连接失败。总的时间长度就是5*2000=10 秒。

syncLimit:这个配置项标识 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是 2*2000=4 秒。

server.A=B:C:D:其中 A 是一个数字,表示这个是第几号服务器;B 是这个服务器的IP地址或/etc/hosts文件中映射了IP的主机名;C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;D 表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口。如果是伪集群的配置方式,由于 B 都是一样,所以不同的 Zookeeper 实例通信端口号不能一样,所以要给它们分配不同的端口号。

 

7、在dataDir=/home/zhaoxing/zookeeper-3.4.6/data下创建myid文件

编辑myid文件,并在对应的IP的机器上输入对应的编号。如在zookeeper上,myid文件内容就是1。如果只在单点上进行安装配置,那么只有一个server.1。

vi myid

1

 

8、zhaoxing用户下修改vi /home/zhaoxing/.bash_profile,增加zookeeper配置:

# zookeeper env

export ZOOKEEPER_HOME=/home/zhaoxing/software/zookeeper-3.4.6

export PATH=$ZOOKEEPER_HOME/bin:$PATH

 

使配置文件生效

source /home/zhaoxing/.bash_profile

 

9、在防火墙中打开要用到的端口2181、2888、3888

切换到root用户权限,执行以下命令:

chkconfig iptables on

service iptables start

编辑/etc/sysconfig/iptables

vi/etc/sysconfig/iptables

增加以下3行:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 2181 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 2888 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3888 -j ACCEPT

 

重启防火墙:

service iptables restart

 

查看防火墙端口状态:

service iptables status

Table: filter

Chain INPUT (policy ACCEPT)

num  target    prot opt source              destination        

1    ACCEPT    all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED

2    ACCEPT    icmp --  0.0.0.0/0            0.0.0.0/0          

3    ACCEPT    all  --  0.0.0.0/0            0.0.0.0/0          

4    ACCEPT    tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:22

5    ACCEPT    tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:2181

6    ACCEPT    tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:2888

7    ACCEPT    tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:3888

8    REJECT    all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

 

Chain FORWARD (policy ACCEPT)

num  target    prot opt source              destination        

1    REJECT    all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

 

Chain OUTPUT (policy ACCEPT)

num  target    prot opt source              destination     

 

10、     启动并测试zookeeper(要用zhaoxing用户启动,不要用root):

(1)使用wusc用户到/home/wusc/zookeeper-3.4.6/bin目录中执行:

zkServer.sh start

 

(2)输入jps命令查看进程:

jps

1456 QuorumPeerMain

1475 Jps

 

其中,QuorumPeerMainzookeeper进程,启动正常

 

(3)查看状态:

zkServer.sh status

 

 

(4)查看zookeeper服务输出信息:

由于服务信息输出文件在/home/wusc/zookeeper-3.4.6/bin/zookeeper.out

tail -500f zookeeper.out

 

11、     停止zookeeper进程:

$ zkServer.sh stop

 

12、     配置zookeeper开机使用wusc用户启动:

编辑/etc/rc.local文件,加入:

su - zhaoxing -c '/home/zhaoxing/sofeware/zookeeper-3.4.6/bin/zkServer.shstart'

Guess you like

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