linux安装zookeeper(集群)

原创
2017/02/24 10:47
阅读数 106

 

保证电脑中已经存在JDK,没有请先安装jdk

 1、创建 /usr/local/services/zookeeper 文件夹:
    mkdir -p /usr/local/services/zookeeper
 
2、进入到 /usr/local/services/zookeeper 目录中:
    cd /usr/local/services/zookeeper
 
3、下载 zookeeper-3.4.9.tar.gz:
    wget https://mirrors.tuna.tsinghua.edu.cn/apache/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz
 
4、解压缩 zookeeper-3.4.9.tar.gz:
    tar -zxvf zookeeper-3.4.9.tar.gz
 
5、进入到 /usr/local/services/zookeeper/zookeeper-3.4.9/conf 目录中:
    cd zookeeper-3.4.9/conf/
 
6、复制 zoo_sample.cfg 文件的并命名为为 zoo.cfg:
    cp zoo_sample.cfg zoo.cfg
 
7、用 vi命令(vi zoo.cfg) 打开 zoo.cfg 文件并修改其内容为如下:
    # The number of milliseconds of each tick
 
    # zookeeper 定义的基准时间间隔,单位:毫秒
    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=/tmp/zookeeper
 
    # 数据文件夹
    dataDir=/usr/local/services/zookeeper/zookeeper-3.4.9/data
 
    # 日志文件夹
    dataLogDir=/usr/local/services/zookeeper/zookeeper-3.4.9/logs
 
    # the port at which the clients will connect
    # 客户端访问 zookeeper 的端口号
    clientPort=2181
 
    # the maximum number of client connections.
    # increase this if you need to handle more clients
    #maxClientCnxns=60

   #此处集群配置三台机器的配置 都要一样

    server.1=192.168.40.139:2881:3881
    server.2=192.168.40.140:2882:3882
    server.3=192.168.40.141:2883:3883
    #
    # 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
 
8、保存并关闭 zoo.cfg 文件:
   
9、进入到 /usr/local/services/zookeeper/zookeeper-3.4.9/bin 目录中:
    cd  /usr/local/services/zookeeper/zookeeper-3.4.9/bin
 
10、配置环境变量:用 vi 打开 /etc/ 目录下的配置文件 profile:
    vi /etc/profile
    并在其尾部追加如下内容:
 
    # idea - zookeeper-3.4.9 config start - 2016-09-08
 
    export ZOOKEEPER_HOME=/usr/local/services/zookeeper/zookeeper-3.4.9/
    export PATH=$ZOOKEEPER_HOME/bin:$PATH
    export PATH
 
    # idea - zookeeper-3.4.9 config start - 2016-09-08
 
11、使 /etc/ 目录下的 profile 文件即可生效:
    source /etc/profile
 设置myid

# cd /usr/local/services/zookeeper/zookeeper-3.4.9/data

# vi myid

设置为 1 保存 退出

注意:因为此处有三台集群机器,所以针对三台机器分别要设置myid,其值也分别为1 2 3


12、启动 zookeeper 服务(在/usr/local/services/zookeeper/zookeeper-3.4.9/bin目录下):
    zkServer.sh start
    如打印如下信息则表明启动成功:
    ZooKeeper JMX enabled by default
    Using config: /usr/local/services/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED
 
13、查询 zookeeper 状态(在安装目录的bin之下运行命令):
    zkServer.sh status(可以看到当前节点是leader还是follower)

     查询zookeeper打印日志: zookeeper.out

    带运行日志输出的启动: zkServer.sh start-foreground
 
14、关闭 zookeeper 服务:
    zkServer.sh stop
    如打印如下信息则表明成功关闭:
    ZooKeeper JMX enabled by default
    Using config: /usr/local/services/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfg
    Stopping zookeeper ... STOPPED
 
15、重启 zookeeper 服务:
    zkServer.sh restart
    如打印如下信息则表明重启成功:
    ZooKeeper JMX enabled by default
    Using config: /usr/local/services/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfg
    ZooKeeper JMX enabled by default
    Using config: /usr/local/services/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfg
    Stopping zookeeper ... STOPPED
    ZooKeeper JMX enabled by default
    Using config: /usr/local/services/zookeeper/zookeeper-3.4.9/bin/../conf/zoo.cfg
    Starting zookeeper ... STARTED

在防火墙打开配置的端口:

编辑防火墙:vi /etc/sysconfig/iptables

增加端口:

-A INPUT -p tcp -mstate --state NEW -m tcp --dport 2183 -j ACCEPT
-A INPUT -p tcp -mstate --state NEW -m tcp --dport 2883 -j ACCEPT
-A INPUT -p tcp -mstate --state NEW -m tcp --dport 3883 -j ACCEPT

重启防火墙:# service iptables restart

 

位zookeeper添加开机启动:

# vi /etc/rc.local

su - root -c /usr/local/services/zookeeper/zookeeper-3.4.9/bin/zkServer.sh start

利用dubbo管控台来测试zookeeper集群是否成功:

dubbo.properties配置 (注意主从配置)

然后运行管理控制台:

注意:1、三台机器都要在防火墙打开对应的端口:并重启防火墙才能生效

          2、 增加了zookeeper的环境变量后,要 # source /etc/profile 方能生效

          3、centos7的防火墙不是iptables,如果你的机器找不到iptables请百度 或查看我相关文章,卸载自带的防火墙,下载iptables。

          4.集群安装成功,连接管控台测试的时候,dubbo管控台启动会去注册,如果zookeeper集群的机器存活数过半,则能成功启动,否则不能启动。(如果在dubbo管控台启动后,把zookeeper全部关闭,ubbo管控台也能正常使用,不会报错,因为只有启动的时候才回去检查)

 

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
0 收藏
0
分享
返回顶部
顶部