zookeeper 集群搭建

1.环境

操作系统:centOS 7
zookeeper 版本: zookeeper-3.4.10
jdk 版本:jdk-8u141-linux-x64
机器三台:172.16.99.106,172.16.99.107,172.16.99.108

2.配置远程登录和 host

Ssh 远程登录不再赘述了,具体方式参考:https://blog.csdn.net/jeikerxiao/article/details/84105529

修改三台节机器的 /etc/hosts

127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.99.106  sh03
172.16.99.107  sh02
172.16.99.108  sh01

修改完后,要能 ping 通。

3.安装 zookeeper(三台机器都要安装)

tar -zxf zookeeper-3.4.10.tar.gz
sudo mv zookeeper-3.4.10 /usr/local/bin/zookeeper

配置 zoo.cfg 文件

cd  /usr/local/bin/zookeeper/conf
cp zoo_sample.cfg zoo.cfg

创建 zookeeper 数据保存目录

sudo mkdir -p /opt/zookeeper/data
sudo mkdir -p /opt/zookeeper/logs

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=/opt/zookeeper/data
dataLogDir=/opt/zookeeper/logs
# the port at which the clients will connect
clientPort=2181
# 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

server.1=sh01:2888:3888
server.2=sh02:2888:3888
server.3=sh03:2888:3888                       

配置 myid

dataDir=/opt/zookeeper/data 目录下,创建 myid 文件。并将本机的 id 写进去,

cd /opt/zookeeper
echo 0 > myid

配置 zookeeper 环境变量

vi /etc/profile 
# 写入
export ZK_HOME=/usr/local/bin/zookeeper
export PATH=$ZK_HOME/bin:$PATH
source /etc/profile

3.启动 zookeeper

cd /usr/local/bin/zookeeper/bin/
sudo ./zkServer.sh start

4.查看集群连接状态

sudo ./zkServer.sh status

zookeeper 会自动选举出 leader 和 follower,如下:

ZooKeeper JMX enabled by default
Using config: /usr/local/bin/zookeeper/bin/../conf/zoo.cfg
Mode: follower

5.停止 zookeeper

sudo ./zkServer.sh stop

你可能感兴趣的:(大数据,zookeeper,分布式,云原生,集群搭建)