zookeeper 集群搭建
压缩包
链接 :https://pan.baidu.com/s/1ftS8orpWhXTqNeSu920O9w
提取码:Winn
1、解压 并安装到/home/zookeeper文件
tar -zxf zookeeper-3.4.5.tar.gz -C /home/zookeeper
2、创建文件夹,存放集群配置文件和相关集群运行后生成的文件
切换到安装目录下: cd /home/zookeeper
创建文件夹:mkdir zookeeper_cluster
切换路径:cd zookeeper_cluster
创建文件夹:mkdir zk-1
创建文件夹:mkdir zk-2
创建文件夹:mkdir zk-3
3、在上面创建的文件夹中,创建集群需要的文件myid
echo 1 > /zk-1/myid
echo 2 > /zk-2/myid
echo 3 > /zk-3/myid
4、复制conf文件中的zoo_sample.cfg文件,并创建zoo1.cfg、zoo2.cfg、zoo3.cfg配置文件到conf 目录中
创建集群配置文件:
cp zoo_sample.cfg zoo1.cfg
cp zoo_sample.cfg zoo2.cfg
cp zoo_sample.cfg zoo3.cfg
5、修改配置文件
修改三个配置文件,根据端口,和文件实际地址
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=5 --可能需要修改的参数
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=2 --可能需要修改的参数
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
#dataDir=/tmp/zookeeper
dataDir=/home/zookeeper/zookeeper_cluster/zk-1 ---修改地址
dataLogDir=/home/zookeeper/zookeeper_cluster/zk-1 ----修改地址
# the port at which the clients will connect
clientPort=2181 ----修改端口。
server.1=localhost:2885:3881
server.2=localhost:2886:3882
server.3=localhost:2887:3883
6、逐个启动
在bin目录下:
./zkServer.sh start /home/zookeeper/conf/zoo1.cfg
./zkServer.sh start /home/zookeeper/conf/zoo2.cfg
./zkServer.sh start /home/zookeeper/conf/zoo3.cfg
查询状态
./zkServer.sh status /home/zookeeper/conf/zoo1.cfg
./zkServer.sh status /home/zookeeper/conf/zoo2.cfg
./zkServer.sh status /home/zookeeper/conf/zoo3.cfg
主要事项:
1、启动之前需要查询是否端口占用
2、启动之前查看是否有已经在启动的zookeeper进程
查看后台运行:jps
查询是否运行进行:ps -ef | grep zookeeper
杀死进程:kill -9 进程pid