少雪 發表於 2020-12-17 14:59:00

CentOS安装Zookeeper 3.6.2

<h2><span>什么是ZooKeeper?</span></h2>
<hr>
<p>&nbsp;ZooKeeper是用于维护配置信息,命名,提供分布式同步以及提供组服务的集中式服务。所有这些类型的服务都以某种形式被分布式应用程序使用。每次实施它们时,都会进行很多工作来修复不可避免的错误和竞争条件。由于难以实现这类服务,因此应用程序最初通常会跳过它们,这会使它们在存在更改的情况下变得脆弱并且难以管理。即使部署正确,这些服务的不同实现也会导致管理复杂。</p>
<p>&nbsp;</p>
<p><span style="font-size: 18px"><strong><span style="color: rgba(0, 0, 0, 1)">Zookeeper环境版本</span></strong></span></p>
<table style="float: left; height: 93px; width: 315px" border="0">
<tbody>
<tr>
<td style="background-color: rgba(0, 128, 128, 1); text-align: center"><span style="color: rgba(0, 0, 0, 1)"><strong>CentOS</strong></span></td>
<td style="background-color: rgba(0, 128, 128, 1); text-align: center"><span style="color: rgba(0, 0, 0, 1)"><strong>&nbsp; &nbsp;JDK</strong></span></td>
<td style="background-color: rgba(0, 128, 128, 1); text-align: center"><span style="color: rgba(0, 0, 0, 1)"><strong>zookeeper</strong></span></td>
</tr>
<tr>
<td style="text-align: center"><strong>7.8</strong></td>
<td style="text-align: center"><strong>1.8.202</strong></td>
<td style="text-align: center"><strong>3.6.2</strong></td>
</tr>
</tbody>
</table>
<p style="text-align: left">&nbsp;</p>
<p style="text-align: left">&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p><span style="color: rgba(0, 0, 0, 1); font-size: 18px"><strong>下载JDK1.8并且安装</strong></span></p>
<div class="cnblogs_code">
<pre># <span style="color: rgba(0, 0, 255, 1)">wget</span> https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">repo.huaweicloud.com/java/jdk/8u202-b08/jdk-8u202-linux-x64.tar.gz</span>
# <span style="color: rgba(0, 0, 255, 1)">tar</span> zxvf jdk-8u202-linux-x64.<span style="color: rgba(0, 0, 255, 1)">tar</span>.gz -C /usr/local/ &amp;&amp; <span style="color: rgba(0, 0, 255, 1)">rm</span> -rf jdk-8u202-linux-x64.<span style="color: rgba(0, 0, 255, 1)">tar</span><span style="color: rgba(0, 0, 0, 1)">.gz
# <span style="color: rgba(0, 0, 255, 1)">mv</span> /usr/local/jdk1.<span style="color: rgba(128, 0, 128, 1)">8</span>.0_202/ /usr/local/jdk/<span style="color: rgba(0, 0, 0, 1)">
# vim /etc/<span style="color: rgba(0, 0, 0, 1)">profile

#set java environment
JAVA_HOME</span>=/usr/local/<span style="color: rgba(0, 0, 0, 1)">jdk
CLASSPATH</span>=.:$JAVA_HOME/<span style="color: rgba(0, 0, 0, 1)">lib.tools.jar
PATH</span>=$JAVA_HOME/<span style="color: rgba(0, 0, 0, 1)">bin:$PATH
export JAVA_HOME CLASSPATH PATH


# source /etc/<span style="color: rgba(0, 0, 0, 1)">profile
#
# java -<span style="color: rgba(0, 0, 0, 1)">version
java version </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">1.8.0_202</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)">
Java(TM) SE Runtime Environment (build </span><span style="color: rgba(128, 0, 128, 1)">1.8</span>.0_202-<span style="color: rgba(0, 0, 0, 1)">b08)
Java HotSpot(TM) </span><span style="color: rgba(128, 0, 128, 1)">64</span>-Bit Server VM (build <span style="color: rgba(128, 0, 128, 1)">25.202</span>-<span style="color: rgba(0, 0, 0, 1)">b08, mixed mode)
# </pre>
</div>
<p>&nbsp;</p>
<p><span style="color: rgba(0, 0, 0, 1); font-size: 18px"><strong>下载zookeeper安装</strong></span></p>
<div class="cnblogs_code">
<pre># <span style="color: rgba(0, 0, 255, 1)">wget</span> https:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.6.2/apache-zookeeper-3.6.2-bin.tar.gz</span>
# <span style="color: rgba(0, 0, 255, 1)">tar</span> zxvf apache-zookeeper-<span style="color: rgba(128, 0, 128, 1)">3.6</span>.<span style="color: rgba(128, 0, 128, 1)">2</span>-bin.<span style="color: rgba(0, 0, 255, 1)">tar</span>.gz -C /usr/local/<span style="color: rgba(0, 0, 0, 1)">
# <span style="color: rgba(0, 0, 255, 1)">rm</span> -rf apache-zookeeper-<span style="color: rgba(128, 0, 128, 1)">3.6</span>.<span style="color: rgba(128, 0, 128, 1)">2</span>-bin.<span style="color: rgba(0, 0, 255, 1)">tar</span>.gz &amp;&amp; <span style="color: rgba(0, 0, 255, 1)">mv</span> /usr/local/apache-zookeeper-<span style="color: rgba(128, 0, 128, 1)">3.6</span>.<span style="color: rgba(128, 0, 128, 1)">2</span>-bin/ /usr/local/<span style="color: rgba(0, 0, 0, 1)">zookeeper
# cd /usr/local/zookeeper/<span style="color: rgba(0, 0, 0, 1)">
# <span style="color: rgba(0, 0, 255, 1)">cp</span> conf/zoo_sample.cfg conf/<span style="color: rgba(0, 0, 0, 1)">zoo.cfg
# <span style="color: rgba(0, 0, 255, 1)">mkdir</span><span style="color: rgba(0, 0, 0, 1)"> logs data
# cd conf/<span style="color: rgba(0, 0, 0, 1)">
# vim zoo.cfg

tickTime</span>=<span style="color: rgba(128, 0, 128, 1)">2000</span><span style="color: rgba(0, 0, 0, 1)">
initLimit</span>=<span style="color: rgba(128, 0, 128, 1)">10</span><span style="color: rgba(0, 0, 0, 1)">
syncLimit</span>=<span style="color: rgba(128, 0, 128, 1)">5</span><span style="color: rgba(0, 0, 0, 1)">
dataDir</span>=/usr/local/zookeeper/<span style="color: rgba(0, 0, 0, 1)">data
dataLogDir</span>=/usr/local/zookeeper/<span style="color: rgba(0, 0, 0, 1)">logs
clientPort</span>=<span style="color: rgba(128, 0, 128, 1)">2181</span><span style="color: rgba(0, 0, 0, 1)">

#</pre>
</div>
<p>&nbsp;</p>
<p><span style="font-size: 18px"><strong><span style="color: rgba(0, 0, 0, 1)">启动Zookeeper</span></strong></span></p>
<div class="cnblogs_code">
<pre># vim /etc/systemd/system/<span style="color: rgba(0, 0, 0, 1)">zookeeper.service


Description</span>=<span style="color: rgba(0, 0, 0, 1)">zookeeper.service
After</span>=<span style="color: rgba(0, 0, 0, 1)">network.target

Type</span>=<span style="color: rgba(0, 0, 0, 1)">forking
Environment</span>=ZOO_LOG_DIR=/usr/local/zookeeper/logs/<span style="color: rgba(0, 0, 0, 1)">
Environment</span>=PATH=/usr/local/jdk/bin:/usr/local/jdk/jre/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin:/root/<span style="color: rgba(0, 0, 0, 1)">bin
ExecStart</span>=/usr/local/zookeeper/bin/zkServer.<span style="color: rgba(0, 0, 255, 1)">sh</span><span style="color: rgba(0, 0, 0, 1)"> start
ExecStop</span>=/usr/local/zookeeper/bin/zkServer.<span style="color: rgba(0, 0, 255, 1)">sh</span><span style="color: rgba(0, 0, 0, 1)"> stop
ExecReload</span>=/usr/local/zookeeper/bin/zkServer.<span style="color: rgba(0, 0, 255, 1)">sh</span><span style="color: rgba(0, 0, 0, 1)"> restart
PIDFile</span>=/usr/local/zookeeper/data/<span style="color: rgba(0, 0, 0, 1)">zookeeper_server.pid
User</span>=<span style="color: rgba(0, 0, 0, 1)">root

WantedBy</span>=multi-<span style="color: rgba(0, 0, 0, 1)">user.target

#
# systemctl daemon-<span style="color: rgba(0, 0, 0, 1)">reload
# systemctl start zookeeper
# systemctl enable zookeeper
Created symlink from </span>/etc/systemd/system/multi-user.target.wants/zookeeper.service to /etc/systemd/system/<span style="color: rgba(0, 0, 0, 1)">zookeeper.service.
#
# ss -<span style="color: rgba(0, 0, 0, 1)">ntl
State       Recv</span>-Q Send-<span style="color: rgba(0, 0, 0, 1)">Q                                           Local Address:Port                                                          Peer Address:Port            
LISTEN      </span><span style="color: rgba(128, 0, 128, 1)">0</span>      <span style="color: rgba(128, 0, 128, 1)">128</span>                                                          *:<span style="color: rgba(128, 0, 128, 1)">22</span>                                                                     *:*<span style="color: rgba(0, 0, 0, 1)">                  
LISTEN      </span><span style="color: rgba(128, 0, 128, 1)">0</span>      <span style="color: rgba(128, 0, 128, 1)">100</span>                                                <span style="color: rgba(128, 0, 128, 1)">127.0</span>.<span style="color: rgba(128, 0, 128, 1)">0.1</span>:<span style="color: rgba(128, 0, 128, 1)">25</span>                                                                     *:*<span style="color: rgba(0, 0, 0, 1)">                  
LISTEN      </span><span style="color: rgba(128, 0, 128, 1)">0</span>      <span style="color: rgba(128, 0, 128, 1)">50</span>                                                      [::]:<span style="color: rgba(128, 0, 128, 1)">38819</span>                                                               [::]:*<span style="color: rgba(0, 0, 0, 1)">                  
LISTEN      </span><span style="color: rgba(128, 0, 128, 1)">0</span>      <span style="color: rgba(128, 0, 128, 1)">50</span>                                                      [::]:<span style="color: rgba(128, 0, 128, 1)">2181</span>                                                                  [::]:*<span style="color: rgba(0, 0, 0, 1)">                  
LISTEN      </span><span style="color: rgba(128, 0, 128, 1)">0</span>      <span style="color: rgba(128, 0, 128, 1)">50</span>                                                      [::]:<span style="color: rgba(128, 0, 128, 1)">8080</span>                                                                  [::]:*<span style="color: rgba(0, 0, 0, 1)">                  
LISTEN      </span><span style="color: rgba(128, 0, 128, 1)">0</span>      <span style="color: rgba(128, 0, 128, 1)">100</span>                                                      [::<span style="color: rgba(128, 0, 128, 1)">1</span>]:<span style="color: rgba(128, 0, 128, 1)">25</span>                                                                  [::]:*<span style="color: rgba(0, 0, 0, 1)">                  
# </pre>
</div>
<p>你会突然发现多了端口,旧版本只有一个2181端口,现在突然多出 8080端口和38819端口</p>
<p>默认访问8080端口地址:</p>
<div class="cnblogs_code">
<pre>http:<span style="color: rgba(0, 128, 0, 1)">//127.0.0.1</span><span style="color: rgba(0, 128, 0, 1)">:8080/commands</span></pre>
</div>
<p>这是因为 zookeeper3.5 版本以上的新特性:</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">he AdminServer
New </span><span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">3.5</span>.<span style="color: rgba(128, 0, 128, 1)">0</span>: 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 <span style="color: rgba(128, 0, 128, 1)">8080</span>, and commands are issued by going to the URL <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">/commands/</span><span style="color: rgba(128, 0, 0, 1)">"</span>, e.g., http:<span style="color: rgba(0, 128, 0, 1)">//</span><span style="color: rgba(0, 128, 0, 1)">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., </span><span style="color: rgba(0, 128, 0, 1); text-decoration: underline">http://localhost</span><span style="color: rgba(0, 128, 0, 1)">:8080/commands). See the AdminServer configuration options for how to change the port and URLs.</span>
<span style="color: rgba(0, 0, 0, 1)">这是Zookeeper AdminServer,默认使用8080端口,它的配置属性如下:

New </span><span style="color: rgba(0, 0, 255, 1)">in</span> <span style="color: rgba(128, 0, 128, 1)">3.5</span>.<span style="color: rgba(128, 0, 128, 1)">0</span><span style="color: rgba(0, 0, 0, 1)">: The following options are used to configure the AdminServer.

admin.enableServer : (Java system property: zookeeper.admin.enableServer) Set to </span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">false</span><span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(0, 0, 0, 1)"> 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 </span><span style="color: rgba(128, 0, 128, 1)">0.0</span>.<span style="color: rgba(128, 0, 128, 1)">0.0</span><span style="color: rgba(0, 0, 0, 1)">.

admin.serverPort : (Java system property: zookeeper.admin.serverPort) The port the embedded Jetty server listens on. Defaults to </span><span style="color: rgba(128, 0, 128, 1)">8080</span><span style="color: rgba(0, 0, 0, 1)">.

admin.idleTimeout : (Java system property: zookeeper.admin.idleTimeout) Set the maximum idle </span><span style="color: rgba(0, 0, 255, 1)">time</span> <span style="color: rgba(0, 0, 255, 1)">in</span> milliseconds that a connection can <span style="color: rgba(0, 0, 255, 1)">wait</span> before sending or receiving data. Defaults to <span style="color: rgba(128, 0, 128, 1)">30000</span><span style="color: rgba(0, 0, 0, 1)"> ms.

admin.commandURL : (Java system property: zookeeper.admin.commandURL) The URL </span><span style="color: rgba(0, 0, 255, 1)">for</span> listing and issuing commands relative to the root URL. Defaults to <span style="color: rgba(128, 0, 0, 1)">"</span><span style="color: rgba(128, 0, 0, 1)">/commands</span><span style="color: rgba(128, 0, 0, 1)">"</span>.</pre>
</div>
<p>&nbsp;</p>
<p>如果服务器上有8080端口可能还会报错,启动不了~</p>
<p>那么需要在配置文件中修改 AdminServer 默认8080端口,如下</p>
<div class="cnblogs_code">
<pre># vim /usr/local/zookeeper/conf/<span style="color: rgba(0, 0, 0, 1)">zoo.cfg

admin.serverPort</span>=<span style="color: rgba(128, 0, 128, 1)">8989</span><span style="color: rgba(0, 0, 0, 1)">

# systemctl restart zookeeper
# ss -<span style="color: rgba(0, 0, 0, 1)">ntl
State      Recv</span>-Q Send-<span style="color: rgba(0, 0, 0, 1)">Q                      Local Address:Port                                     Peer Address:Port            
LISTEN   </span><span style="color: rgba(128, 0, 128, 1)">0</span>      <span style="color: rgba(128, 0, 128, 1)">128</span>                                     *:<span style="color: rgba(128, 0, 128, 1)">22</span>                                                *:*<span style="color: rgba(0, 0, 0, 1)">                  
LISTEN   </span><span style="color: rgba(128, 0, 128, 1)">0</span>      <span style="color: rgba(128, 0, 128, 1)">100</span>                           <span style="color: rgba(128, 0, 128, 1)">127.0</span>.<span style="color: rgba(128, 0, 128, 1)">0.1</span>:<span style="color: rgba(128, 0, 128, 1)">25</span>                                                *:*<span style="color: rgba(0, 0, 0, 1)">                  
LISTEN   </span><span style="color: rgba(128, 0, 128, 1)">0</span>      <span style="color: rgba(128, 0, 128, 1)">50</span>                                 [::]:<span style="color: rgba(128, 0, 128, 1)">2181</span>                                             [::]:*<span style="color: rgba(0, 0, 0, 1)">                  
LISTEN   </span><span style="color: rgba(128, 0, 128, 1)">0</span>      <span style="color: rgba(128, 0, 128, 1)">50</span>                                 [::]:<span style="color: rgba(128, 0, 128, 1)">36046</span>                                          [::]:*<span style="color: rgba(0, 0, 0, 1)">                  
LISTEN   </span><span style="color: rgba(128, 0, 128, 1)">0</span>      <span style="color: rgba(128, 0, 128, 1)">100</span>                                 [::<span style="color: rgba(128, 0, 128, 1)">1</span>]:<span style="color: rgba(128, 0, 128, 1)">25</span>                                             [::]:*<span style="color: rgba(0, 0, 0, 1)">                  
LISTEN   </span><span style="color: rgba(128, 0, 128, 1)">0</span>      <span style="color: rgba(128, 0, 128, 1)">50</span>                                 [::]:<span style="color: rgba(128, 0, 128, 1)">8989</span>                                             [::]:*<span style="color: rgba(0, 0, 0, 1)">                  
# </pre>
</div>
<p>&nbsp;</p>
<p><span style="font-size: 18px"><strong>开放防火墙</strong></span></p>
<div class="cnblogs_code">
<pre># firewall-cmd --zone=public --add-port=<span style="color: rgba(128, 0, 128, 1)">2181</span>/tcp --<span style="color: rgba(0, 0, 0, 1)">permanent
# firewall-cmd --zone=public --add-port=<span style="color: rgba(128, 0, 128, 1)">8989</span>/tcp --<span style="color: rgba(0, 0, 0, 1)">permanent
# firewall-cmd –reload</pre>
</div>
<p>或者关闭防火墙</p>
<div class="cnblogs_code">
<pre># systemctl stop firewalld
# systemctl stop iptables</pre>
</div>
<p>如果对防火墙有疑惑可以看我之前的博客&nbsp; &nbsp; &nbsp;&nbsp;https://www.cnblogs.com/mike666/p/13932326.html</p>
<p>&nbsp;</p>
<p>服务操作命令</p>
<div class="cnblogs_code">
<pre><span style="color: rgba(0, 0, 0, 1)">systemctl start zookeeper   #启动服务

systemctl stop zookeeper      #停止服务

systemctl restart zookeeper   #重新启动服务

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

systemctl enable zookeeper   #设置开机自启动

systemctl disable zookeeper   #停止开机自启动</span></pre>
</div>
<p>&nbsp;</p>
<p>本文分享完毕,感谢支持点赞~~</p><br><br>
来源:https://www.cnblogs.com/mike666/p/14149676.html
頁: [1]
查看完整版本: CentOS安装Zookeeper 3.6.2