linux 安装zookeeper单节点

解压压缩包到 /usr/local/

tar -zxvf zookeeper-3.4.13.tar.gz

在安装目录下创建data和logs文件夹

mkdir data
mkdir logs

添加myid文件,内容为1,也就是本机zookeeper的id

vim /usr/local/zookeeper-3.4.13/data/myid

1

复制

cp conf/zoo_sample.cfg conf/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=/usr/local/zookeeper-3.4.13/data
dataLogDir=/usr/local/zookeeper-3.4.13/logs
# the port at which the clients will connect
clientPort=2181
server.1=119.23.237.241:2888:3888

2181端口是注册、获取服务的端口

1.2888 端口号是zookeeper服务之间通信的端口 
2.3888 是zookeeper 与其他应用程序通信的端口 
3.initLimit:这个配置项是用来配置 Zookeeper 接受客户端(这里所说的客户端不是用户连接 Zookeeper服务器的客户端,而是 Zookeeper 服务器集群中连接到 Leader 的 Follower 服务器)初始化连接时最长能忍受多少个心跳时间间隔数。当已经超过 10 个心跳的时间(也就是 tickTime)长度后 Zookeeper 服务器还没有收到客户端的返回信息,那么表明这个客户端连接失败。总的时间长度就是 5*2000=10 秒。 
4.syncLimit:这个配置项标识 Leader 与 Follower 之间发送消息,请求和应答时间长度,最长不能超过多少个 tickTime 的时间长度,总的时间长度就是 2*2000=4 秒 
5.server.A=B:C:D:其中 A 是一个数字,表示这个是第几号服务器;B 是这个服务器的IP地址或/etc/hosts文件中映射了IP的主机名;C 表示的是这个服务器与集群中的 Leader 服务器交换信息的端口;D 表示的是万一集群中的 Leader 服务器挂了,需要一个端口来重新进行选举,选出一个新的 Leader,而这个端口就是用来执行选举时服务器相互通信的端口。如果是伪集群的配置方式,由于 B 都是一样,所以不同的 Zookeeper 实例通信端口号不能一样,所以要给它们分配不同的端口号。

添加环境变量

export ZOOKEEPER_HOME=/usr/local/zookeeper-3.4.13
# 在尾部添加
export PATH=$ZOOKEEPER_HOME/bin:$PATH

保存

source /etc/profile

开启防火墙2181、2888、3888端口

添加开机启动

vim /etc/rc.local 

/usr/local/zookeeper-3.4.13/bin/zkServer.sh start

启动zookeeper,在bin目录下

./zkServer.sh start

其他命令

./zkServer.sh status
./zkServer.sh stop

猜你喜欢

转载自blog.csdn.net/qq_33683097/article/details/85006019