Ubuntu16.04安装配置ZooKeeper集群

本文参照http://www.zhangyitian.cn/blog/ubuntu16-04%E5%AE%89%E8%A3%85%E9%85%8D%E7%BD%AEzookeeper%E9%9B%86%E7%BE%A4/ 此篇文章而写。

集群环境:

计算机节点 IP地址
A 192.168.2.101
B 192.168.2.102
C 192.168.2.104

JDK版本:java version "1.8.0_144"

 

准备工作

关闭防火墙:

yitian@ubuntu:~/zookeeper/zookeeper-3.4.10/conf$ sudo ufw disable
Firewall stopped and disabled on system startup

1、下载ZooKeeper

下载地址:https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/

这里下载的版本为3.4.10(2017-10-04)

配置ZooKeeper(每个主机)

2、修改配置文件:

1). 在/zookeeper-3.4.10/conf/目录下,复制zoo_sample.cfg为zoo.cfg,并将zoo_sample.cfg删除

2). 编辑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=/home/xxx/zookeeper/data # zookeeper的DATA文件路径,在zookeeper集群环境下,需要在该路径下配置不同的myid文件
dataLogDir=/home/xxxx/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=heron01:2888:3888 # 这里使用三台主机的ip(这句注释不要粘贴过去,否则会报错)
server.2=heron03:2888:3888
server.3=heron02:2888:3888

3. 在dataDir目录下,配置myid文件

在之前设置的dataDir(/home/yitian/zookeeper/data # zookeeper)中新建myid文件, 写入一个数字, 该数字表示这是第几号server. 该数字必须和zoo.cfg文件中的server.X中的X一一对应.并且同一集群内每个节点的数字是不相同的。

heron02中myid文件内容:

han@heron02:~/zookeeper/data$ cat myid
1

heron01中myid文件内容:

wang@heron01:~/zookeeper/data$ cat myid
3

heron03中myid文件内容:

 

lin@heron03:~/zookeeper/data$ cat myid
2

启动并查看状态

1. 启动heron02

han@heron02:~/zookeeper/zookeeper-3.4.10/bin$ ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/yitian/zookeeper/zookeeper-3.4.10/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
 yitian@ubuntu:~/zookeeper/zookeeper-3.4.10/bin$ ./zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/yitian/zookeeper/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... already running as process 3467.
han@heron02:~/zookeeper/zookeeper-3.4.10/bin$ ./zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/yitian/zookeeper/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: leader

2. 启动heron01

wang@heron01:~/zookeeper/zookeeper-3.4.10/conf$ ../bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/yitian/zookeeper/zookeeper-3.4.10/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
wang@heron01:~/zookeeper/zookeeper-3.4.10/conf$ ../bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/yitian/zookeeper/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
wang@heron01:~/zookeeper/zookeeper-3.4.10/conf$ ../bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/yitian/zookeeper/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower

3. 启动heron03

 

lin@heron03:~$ ./zookeeper/zookeeper-3.4.10/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/yitian/zookeeper/zookeeper-3.4.10/bin/../conf/zoo.cfg
Error contacting service. It is probably not running.
lin@heron03:~$ ./zookeeper/zookeeper-3.4.10/bin/zkServer.sh start
ZooKeeper JMX enabled by default
Using config: /home/yitian/zookeeper/zookeeper-3.4.10/bin/../conf/zoo.cfg
Starting zookeeper ... STARTED
lin@heron03:~$ ./zookeeper/zookeeper-3.4.10/bin/zkServer.sh status
ZooKeeper JMX enabled by default
Using config: /home/yitian/zookeeper/zookeeper-3.4.10/bin/../conf/zoo.cfg
Mode: follower

 

 

一定要学会看zookeeper.out文件,也就是日志,其中3888后面不允许跟注释,就是在文件中发现的。

 

在root用户ssh时要修改配置文件和重置root用户密码,具体如下:

修改/etc/ssh/sshd_config及配置文件:

# Authentication:
LoginGraceTime 120
# PermitRootLogin prohibit-password
PermitRootLogin yes
StrictModes yes

重置root用户密码

sudo passwd root

 

你可能感兴趣的:(heron,zookeeper)