美文网首页程序员
《架构之路zookeeper系列》zookeeper安装与配置

《架构之路zookeeper系列》zookeeper安装与配置

作者: 一起浪一夏 | 来源:发表于2018-03-13 22:03 被阅读0次

一.导读

今天跟大家分享下单机环境下zookeeper安装与配置,希望能给初学者带来帮助。

二.实验环境

1.操作系统:CentOS7

IP:192.168.1.106

2.zookeeper-3.4.11

下载地址:https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz

三.实战演练

1.下载

备注:如果没有特殊说明,我这里都安装在opt目录下

$ wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.11/zookeeper-3.4.11.tar.gz

2.解压

$ chmod -R 755 ./zookeeper-3.4.11.tar.gz 

$ tar -zxvf ./zookeeper-3.4.11.tar.gz

3.创建数据目录data和日志目录logs

$ cd/opt/zookeeper-3.4.11/

$ mkdir data

$ mkdir logs

4.修改配置文件

(1).我们拷贝一份zookeeper的示例文件进行修改

$ cp ./conf/zoo_sample.cfg ./conf/zoo.cfg

(2).修改刚才拷贝的文件zoo.cfg

$ vi ./conf/zoo.cfg

我们主要先修改dataDir,添加dataLogDir和server.1,其他的配置属性暂时保持默认即可,修改好后保存并退出。

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=/tmp/zookeeper

dataDir=/opt/zookeeper-3.4.11/data

dataLogDir=/opt/zookeeper-3.4.11/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=192.168.1.106:2888:3888

备注:2888端口是zookeeper服务之间通信的端口,3888端口是zookeeper与其他应用程序通信的端口。

5.配当前用户环境变量

(1).修改好后,保存并退出

$ vi /root/.bash_profile

$ export ZOOKEEPER_HOME=/opt/zookeeper-3.4.11

$ export PATH=$ZOOKEEPER_HOME/bin:$PATH

(2).刷新生效

$ source /root/.bash_profile

6.修改防火墙配置

1).查看防火墙状态

$ firewall-cmd --state

2).添加2181、2888、3888端口号到防火墙中,并重启防火墙。

$ firewall-cmd --zone=public --add-port=2181/tcp --permanent

$ firewall-cmd --zone=public --add-port=2888/tcp --permanent

$ firewall-cmd --zone=public --add-port=3888/tcp --permanent

3).重启防火墙

$ firewall-cmd --reload

备注:centOS7默认使用的是,firewall作为防火墙。如果您使用的是iptables,请按照下面操作添加规则

1).修改

$ vi /etc/sysconfig/iptables

2).增加以下面3行内容:

-A INPUT -m state --state NEW -m tcp -p tcp --dport 2181 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 2888 -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 3888 -j ACCEPT

3).重启防火墙

$ service iptables restart

7.启动zookeeper

进到/opt/zookeeper-3.4.11/bin/目录下

$ ./zkServer.sh start

看到下面,启动成功

[root@localhost bin]# ./zkServer.sh start

ZooKeeper JMX enabled by default

Using config: /opt/zookeeper-3.4.11/bin/../conf/zoo.cfg

Starting zookeeper ... STARTED

8.配置开机启动

编辑vi /etc/rc.local文件并添加下面内容

$ su - root -c '/opt/zookeeper-3.4.11/bin/zkServer.sh start'

四.总结

经过以上的简单步骤,我们的单机版的zookeeper运行环境就搭建好了,接下来就可以进行zookeeper学习之旅了。

本文摘自:https://www.xiangquba.cn/2018/03/10/zookeeper-stand-alone-install-guide/

相关文章

网友评论

    本文标题:《架构之路zookeeper系列》zookeeper安装与配置

    本文链接:https://www.haomeiwen.com/subject/bbgtqftx.html