您的位置:首页 > 运维架构 > Linux

zookeeper注册中心安装(linux)

2016-07-22 15:21 459 查看
1.下载zookeeper-3.4.6

2.解压zookeeper安装包

$tar -zxvf zookeeper-3.4.6.tar.gz

3.在/home/admin/zookeeper-3.4.6目录下创建目录

$cd /home/admin/zookeeper-3.4.6

$mkdir data

$mkdir logs

4.将zookeeper-3.4.6/conf目录下的zoo_sample.cfg文件拷贝一份,命名为zoo.cfg

$cp zoo_sample.cfg zoo.cfg

5.修改zoo.cfg配置文件

$vim zoo.cfg

# The number of milliseconds of each tick

tickTime=2000

# The number of ticks that the initial

# synchronization phase can take

initLimit=10

# The number of ticks that can pass between

# sending a request and getting an acknowledgement

syncLimit=5

# the directory where the snapshot is stored.

# do not use /tmp for storage, /tmp here is just

# example sakes.

dataDir=/tmp/zookeeper

# the port at which the clients will connect

clientPort=2181

# The number of ticks that the initial

# synchronization phase can take

initLimit=10

# The number of ticks that can pass between

# sending a request and getting an acknowledgement

syncLimit=5

# The number of ticks that can pass between

# sending a request and getting an acknowledgement

syncLimit=5

# the directory where the snapshot is stored.

# do not use /tmp for storage, /tmp here is just

# example sakes.

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

dataLogDir=/home/admin/zookeeper-3.4.6/logs

# the port at which the clients will connect

clientPort=2181

#2888,3888 are election port

server.1=192.168.141.101:2888:3888

# the maximum number of client connections.

# increase this if you need to handle more clients

#maxClientCnxns=60

#

# Be sure to read the maintenance section of the

# administrator guide before turning on autopurge.

#

# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#

# The number of snapshots to retain in dataDir

#autopurge.snapRetainCount=3

# Purge task interval in hours

# Set to "0" to disable auto purge feature

#autopurge.purgeInterval=1

其中,

2888端口号是zookeeper服务之间通信的端口,3888是zookeeper与其他应用程序通信的端口。

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

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

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

6.在dataDir=/home/admin/zookeeper-3.4.6/data下创建myid文件

编辑myid文件,并在对应的IP的机器上输入对应的编号。如在server.1上,myid文件内容就是1。

7.admin用户下修改vim /home/admin/.bash_profile,增加zookeeper配置

# zookeeper env

export ZOOKEEPER_HOME=/home/admin/zookeeper-3.4.6

export PATH=$ZOOKEEPER_HOME/bin:$PATH

使配置文件生效

$source /home/admin/.bash_profile

8.在防火墙中打开要用到的端口2181/2888/3888,切换到root用户,执行以下命令

#chkconfig iptables on

#service iptables start

#vim /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

表格: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:80

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

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

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

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

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

11   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     

9.启动并测试zookeeper(要用admin用户启动,不要用root)

1)进入/home/admin/zookeeper-3.4.6/bin目录

$zkServer.sh start

2)输入jps命令查看进程

$jps

1456 QuorumPeerMain

1475 Jps

其中,QuorumPeerMain是zookeeper进程,启动正常

3)查看状态

$zkServer.sh status

4)查看zookeeper服务输出信息

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

$tail -500f zookeeper.out

10.停止zookeeper进程

$zkServer.sh stop

11.配置zookeeper开机使用admin用户启动

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

su - admin -c '/home/admin/zookeeper-3.4.6/bin/zkServer.sh start'
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: