ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

CentOS 安装 Zookeeper 3.6.2

2020-12-17 15:03:36  阅读:48  来源: 互联网

标签:Mike zookeeper CentOS local Zookeeper 3.6 usr Node1 root


什么是ZooKeeper?


 ZooKeeper是用于维护配置信息,命名,提供分布式同步以及提供组服务的集中式服务。所有这些类型的服务都以某种形式被分布式应用程序使用。每次实施它们时,都会进行很多工作来修复不可避免的错误和竞争条件。由于难以实现这类服务,因此应用程序最初通常会跳过它们,这会使它们在存在更改的情况下变得脆弱并且难以管理。即使部署正确,这些服务的不同实现也会导致管理复杂。

 

Zookeeper环境版本

JDK Zookeeper
1.8 3.6.2

 

 

 

 

 

下载JDK1.8并且安装

[root@Mike-Node1 ~]# wget https://repo.huaweicloud.com/java/jdk/8u202-b08/jdk-8u202-linux-x64.tar.gz
[root@Mike-Node1 ~]# tar zxvf jdk-8u202-linux-x64.tar.gz -C /usr/local/ && rm -rf jdk-8u202-linux-x64.tar.gz
[root@Mike-Node1 ~]# mv /usr/local/jdk1.8.0_202/ /usr/local/jdk/
[root@Mike-Node1 ~]# vim /etc/profile

#set java environment
JAVA_HOME=/usr/local/jdk
CLASSPATH=.:$JAVA_HOME/lib.tools.jar
PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME CLASSPATH PATH


[root@Mike-Node1 ~]# source /etc/profile
[root@Mike-Node1 ~]# 
[root@Mike-Node1 ~]# java -version
java version "1.8.0_202"
Java(TM) SE Runtime Environment (build 1.8.0_202-b08)
Java HotSpot(TM) 64-Bit Server VM (build 25.202-b08, mixed mode)
[root@Mike-Node1 ~]# 

 

下载zookeeper安装

[root@Mike-Node1 ~]# wget https://mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.6.2/apache-zookeeper-3.6.2-bin.tar.gz
[root@Mike-Node1 ~]# tar zxvf apache-zookeeper-3.6.2-bin.tar.gz -C /usr/local/
[root@Mike-Node1 ~]# rm -rf apache-zookeeper-3.6.2-bin.tar.gz && mv /usr/local/apache-zookeeper-3.6.2-bin/ /usr/local/zookeeper
[root@Mike-Node1 ~]# cd /usr/local/zookeeper/
[root@Mike-Node1 /usr/local/zookeeper]# cp conf/zoo_sample.cfg conf/zoo.cfg
[root@Mike-Node1 /usr/local/zookeeper]# mkdir logs data
[root@Mike-Node1 /usr/local/zookeeper]# cd conf/
[root@Mike-Node1 /usr/local/zookeeper/conf]# vim zoo.cfg 

tickTime=2000
initLimit=10
syncLimit=5
dataDir=/usr/local/zookeeper/data
dataLogDir=/usr/local/zookeeper/logs
clientPort=2181

[root@Mike-Node1 /usr/local/zookeeper/conf]#

 

启动Zookeeper

[root@Mike-Node1 /usr/local/zookeeper/conf]# vim /etc/systemd/system/zookeeper.service

[Unit]
Description=zookeeper.service
After=network.target
[Service]
Type=forking
Environment=ZOO_LOG_DIR=/usr/local/zookeeper/logs/
Environment=PATH=/usr/local/jdk/bin:/usr/local/jdk/jre/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/bin
ExecStart=/usr/local/zookeeper/bin/zkServer.sh start
ExecStop=/usr/local/zookeeper/bin/zkServer.sh stop
ExecReload=/usr/local/zookeeper/bin/zkServer.sh restart
PIDFile=/usr/local/zookeeper/data/zookeeper_server.pid
User=root
[Install]
WantedBy=multi-user.target

[root@Mike-Node1 /usr/local/zookeeper/conf]# 
[root@Mike-Node1 /usr/local/zookeeper/conf]# systemctl daemon-reload
[root@Mike-Node1 /usr/local/zookeeper/conf]# systemctl start zookeeper
[root@Mike-Node1 /usr/local/zookeeper/conf]# systemctl enable zookeeper
Created symlink from /etc/systemd/system/multi-user.target.wants/zookeeper.service to /etc/systemd/system/zookeeper.service.
[root@Mike-Node1 /usr/local/zookeeper/conf]# 
[root@Mike-Node1 /usr/local/zookeeper/conf]# ss -ntl
State       Recv-Q Send-Q                                           Local Address:Port                                                          Peer Address:Port              
LISTEN      0      128                                                          *:22                                                                       *:*                  
LISTEN      0      100                                                  127.0.0.1:25                                                                       *:*                  
LISTEN      0      50                                                        [::]:38819                                                                 [::]:*                  
LISTEN      0      50                                                        [::]:2181                                                                  [::]:*                  
LISTEN      0      50                                                        [::]:8080                                                                  [::]:*                  
LISTEN      0      100                                                      [::1]:25                                                                    [::]:*                  
[root@Mike-Node1 /usr/local/zookeeper/conf]# 

你会突然发现多了端口,旧版本只有一个2181端口,现在突然多出 8080端口和38819端口

默认访问8080端口地址:

http://127.0.0.1:8080/commands

这是因为 zookeeper3.5 版本以上的新特性:

he AdminServer
New in 3.5.0: The AdminServer is an embedded Jetty server that provides an HTTP interface to the four letter word commands. By default, the server is started on port 8080, and commands are issued by going to the URL "/commands/[command name]", e.g., http://localhost:8080/commands/stat. The command response is returned as JSON. Unlike the original protocol, commands are not restricted to four-letter names, and commands can have multiple names; for instance, "stmk" can also be referred to as "set_trace_mask". To view a list of all available commands, point a browser to the URL /commands (e.g., http://localhost:8080/commands). See the AdminServer configuration options for how to change the port and URLs.
这是Zookeeper AdminServer,默认使用8080端口,它的配置属性如下:

New in 3.5.0: The following options are used to configure the AdminServer.

admin.enableServer : (Java system property: zookeeper.admin.enableServer) Set to "false" to disable the AdminServer. By default the AdminServer is enabled.

admin.serverAddress : (Java system property: zookeeper.admin.serverAddress) The address the embedded Jetty server listens on. Defaults to 0.0.0.0.

admin.serverPort : (Java system property: zookeeper.admin.serverPort) The port the embedded Jetty server listens on. Defaults to 8080.

admin.idleTimeout : (Java system property: zookeeper.admin.idleTimeout) Set the maximum idle time in milliseconds that a connection can wait before sending or receiving data. Defaults to 30000 ms.

admin.commandURL : (Java system property: zookeeper.admin.commandURL) The URL for listing and issuing commands relative to the root URL. Defaults to "/commands".

 

如果服务器上有8080端口可能还会报错,启动不了~

那么需要在配置文件中修改 AdminServer 默认8080端口,如下

[root@Mike-Node1 ~]# vim /usr/local/zookeeper/conf/zoo.cfg

admin.serverPort=8989

[root@Mike-Node1 ~]# systemctl restart zookeeper
[root@Mike-Node1 ~]# ss -ntl
State      Recv-Q Send-Q                      Local Address:Port                                     Peer Address:Port              
LISTEN     0      128                                     *:22                                                  *:*                  
LISTEN     0      100                             127.0.0.1:25                                                  *:*                  
LISTEN     0      50                                   [::]:2181                                             [::]:*                  
LISTEN     0      50                                   [::]:36046                                            [::]:*                  
LISTEN     0      100                                 [::1]:25                                               [::]:*                  
LISTEN     0      50                                   [::]:8989                                             [::]:*                  
[root@Mike-Node1 ~]# 

 

开放防火墙

[root@Mike-node1 ~]# firewall-cmd --zone=public --add-port=2181/tcp --permanent
[root@Mike-node1 ~]# firewall-cmd --zone=public --add-port=8989/tcp --permanent
[root@Mike-node1 ~]# firewall-cmd –reload

或者关闭防火墙

[root@Mike-node1 ~]# systemctl stop firewalld
[root@Mike-node1 ~]# systemctl stop iptables

如果对防火墙有疑惑可以看我之前的博客      https://www.cnblogs.com/mike666/p/13932326.html

 

服务操作命令

systemctl start zookeeper     #启动服务

systemctl stop zookeeper      #停止服务

systemctl restart zookeeper   #重新启动服务

systemctl status zookeeper   #查看服务当前状态

systemctl enable zookeeper   #设置开机自启动

systemctl disable zookeeper   #停止开机自启动

 

本文分享完毕,感谢支持点赞~~

标签:Mike,zookeeper,CentOS,local,Zookeeper,3.6,usr,Node1,root
来源: https://www.cnblogs.com/mike666/p/14149676.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有