zookeeper三种配置
环境变量(集群配置或者单机配置)
#JAVA
JAVA_HOME=/usr/local/java/jdk1.8.0_251
JRE_HOME=/usr/local/java/jdk1.8.0_251/jre
CLASSPATH=.:$JAVA_HOME/lib:$JAVA_HOME/lib
PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
export JAVA_HOME JRE_HOME CLASSPATH PATH
#Zookeeper
export ZK_HOME=/usr/local/zookeeper
export PATH=$PATH:$ZK_HOME/bin
单机配置
# vim ../conf/zoo.cfg
#Start Port
admin.serverPort=10080
# 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=/data/zookeeper/data
dataLogDir=/data/zookeeper/log
# the port at which the clients will connect
clientPort=2181
集群配置(slave1为例,slave2,slave3配置同理)
①配置hosts
# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.2.201 slave1
192.168.2.202 slave2
192.168.2.203 slave3
②配置zookeeper配置文件
# vim ../conf/zoo.cfg
#Start Port
admin.serverPort=10080
# 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=/data/zookeeper/data
dataLogDir=/data/zookeeper/log
# the port at which the clients will connect
clientPort=2181
server.1=slave1:2888:3888
server.2=slave2:2888:3888
server.3=slave3:2888:3888
2888: zookeeper内部通讯端口;
3888: Leader选举通讯端口;
在zookeeper数据文件目录中创建myid文件
# mkdir -pv /data/zookeeper/data
# mkdir -pv /data/zookeeper/log
# echo "1" > /data/zookeeper/data/myid
③启动zookeeper
# zkServer.sh start
伪集群配置
需要启动三个zookeeper实例,也就是说需要把zookeeper目录copy三份,分别为zookeeper_1,zookeeper_2,zookeeper_3;
以zookeeper_3配置为例,其余同理
# vim zoo.cfg
#Start Port
admin.serverPort=10083 ##修改启动端口
# 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=/data/zookeeper_3/data ##修改data目录
dataLogDir=/data/zookeeper_3/log
# the port at which the clients will connect
clientPort=2183 ##修改监听端口
server.1=slave1:2888:3888
server.2=slave1:2889:3889
server.3=slave1:2890:3890
在zookeeper数据文件目录中创建myid文件
# mkdir -pv /data/zookeeper_3/data
# mkdir -pv /data/zookeeper_3/log
# echo "3" > /data/zookeeper_3/data/myid
启动zookeeper(单机版和集群版的环境变量此处不适用,最好不要配置环境变量,以免弄混)
# /usr/local/zookeeper_1/bin/zkServer.sh start
# /usr/local/zookeeper_2/bin/zkServer.sh start
# /usr/local/zookeeper_3/bin/zkServer.sh start