現在の会社は、Ali独自のEDASサービスを使用するEDASであるAliの内部ダボを使用しています。ダボを使用した古いアイアンの場合、動物園の飼育係、飼育係はビッグデータとRPC通信の適用にもっと関心があることを知っておく必要があります。Zookeeperを使用したことがあるかどうかに関係なく、今回は主にZookeeperとクラスターのデプロイメントを紹介します。これは、実際の操作でのみ深く理解することができます。
ソースコード:https://github.com/limingios/netFuture/ [zookeeper]
(1)飼育係の紹介
-
歴史
Zookeeperは、Yahoo ResearchInstituteの研究グループから生まれました。当時、研究者たちは、Yahoo内の多くの大規模システムが基本的に分散調整のために同様のシステムに依存していることを発見しましたが、これらのシステムはしばしば分散シングルポイントの問題を抱えています。そのため、Yahooの開発者は、開発者がビジネスロジックの処理に集中できるように、単一の問題点のない一般的な分散調整フレームワークを開発しようとしました。
「ZooKeeper」プロジェクトの名前については、実際には興味深い逸話があります。プロジェクトの初期段階では、多くの内部プロジェクトが動物にちなんで名付けられていることを考慮して(有名なPigプロジェクトなど)、Yahooのエンジニアはこのプロジェクトに動物の名前を付けることを望んでいました。当時の研究所の主任研究員であるラグ・ラマクリシュナンは冗談めかして言った。「これが続けば、私たちは動物園になります!」これが言われるとすぐに、誰もが配布のために飼育係を一人ずつ呼ぶと言いました。コンポーネントをまとめると、Yahooの分散システム全体が大きな動物園のように見え、Zookeeperを使用して分散環境を1つずつ調整するため、Zookeeperという名前が生まれました。 -
Zookeeperが暑い理由
1960年代に、メインフレームが発明され、そのスーパーコンピューティングとI / O処理機能、および安定性とセキュリティのおかげで、世界の主流になりました。しかし、メインフレームには、高価な構造、複雑な操作、シングルポイントの問題など、いくつかの致命的な問題もあります。特に、メインフレームの人材をトレーニングするコストは非常に高くなります。これらの問題の出現により、メインフレームの開発に影響を及ぼし続けています。一方、PCのパフォーマンスの継続的な改善とネットワークの普及により、誰もがミニコンピューターと通常のPCサーバーを使用して分散コンピューターシステムを構築し、コストを削減するようになりました。その後、分散システムはますます普及しました。
- 動物園の飼育係の公式ウェブサイト
ダウンロードリンク:https://www-eu.apache.org/dist/zookeeper/
ソースアドレス:https://github.com/apache/zookeeper
(2)クラスターの展開
クラスターには2つのタイプがあり、1つは分散クラスターで、もう1つは疑似分散クラスターです。
分散:各アプリケーションは個別の独立したホスト上にあり、ポートは一貫しています。
疑似分散:複数のアプリケーションが1つのホスト上にあり、ポートが区別されます。実際の実稼働環境では、疑似配布はまれです。
疑似分散クラスターは、操作がより困難です。mac install vgarant:https://idig8.com/2018/07/29/docker-zhongji-07/
window install vgarant https://idig8.com/2018/07/29/docker-zhongji-08/
システムタイプ | IPアドレス | ノードの役割 | CPU | 記憶 | ホスト名 |
---|---|---|---|---|---|
Centos7 | 192.168.69.100 | 疑似配布 | 2 | 2G | zookeeper-virtua |
Centos7 | 192.168.69.101 | 真の分散型リーダー | 2 | 2G | zookeeper-リーダー |
Centos7 | 192.168.69.102 | 真の分散-従属1 | 2 | 2G | zookeeper-Follower1 |
Centos7 | 192.168.69.103 | 真の分散-従属2 | 2 | 2G | zookeeper-Follower2 |
srcのちょっとしたコツで色があるので、以前は無視していたのですが、見ると目が痛くなり、色が格段に良くなりました。
- (2.1)疑似環境構成
私は今でもvagrantを使用していますが、vagrantに精通しているため、手動で仮想マシンを作成することはほとんどありません。
(2.1.1)基本設定
su #密码 vagrant cd ~ vi /etc/ssh/sshd_config sudo systemctl restart sshd
vi /etc/resolv.conf
8.8.8.8に設定
サービスネットワークの再起動
![](https://upload-images.jianshu.io/upload_images/11223715-78a8109c41a094e6.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/11223715-2aab7202b523bc3f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/11223715-1916bbc2f18c3145.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
>(2.1.2)jdk安装
>脚本在我的源码里面
``` bash
vi pro.sh
sh pro.sh
(2.1.3)Zookeeperのダウンロードおよび
ダウンロードツールは、最新バージョンが3.5.4にリリースされていることを忘れないでください、私はまだ3.4.10を使用しています
wget https://www-eu.apache.org/dist/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz
(2.1.4)動物園の飼育係を解凍する
tar zxvf zookeeper-3.4.10.tar.gz
(2.1.5)zkにconfディレクトリを入力し、3つのファイルをコピーします
cd /root/zookeeper-3.4.10/conf cp zoo_sample.cfg zoo1.cfg cp zoo_sample.cfg zoo2.cfg cp zoo_sample.cfg zoo3.cfg
(2.1.6)これらの3つのファイルzoo1.cfg、zoo2.cfg、zoo3.cfgを編集します
(2.1.6.1)zoo1.cfgを編集します
vi zoo1.cfg
dataDir = / apps / servers / data / d_1
dataLogDir = / apps / servers / logs / logs_1
clientPort = 2181# 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=/apps/servers/data/d_1 dataLogDir=/apps/servers/logs/logs_1 # 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=localhost:2187:2887 server.2=localhost:2188:2888 server.3=localhost:2189:2889
(2.1.6.2)zoo2.cfgを編集する
vi zoo2.cfg
dataDir = / apps / servers / data / d_2
dataLogDir = / apps / servers / logs / logs_2
clientPort = 2182# 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=/apps/servers/data/d_2 dataLogDir=/apps/servers/logs/logs_2 # the port at which the clients will connect clientPort=2182 # 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=localhost:2187:2887 server.2=localhost:2188:2888 server.3=localhost:2189:2889
(2.1.6.3)zoo3.cfgを編集します
vi zoo3.cfg
dataDir = / apps / servers / data / d_3
dataLogDir = / apps / servers / logs / logs_3
clientPort = 2183# 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=/apps/servers/data/d_3 dataLogDir=/apps/servers/logs/logs_3 # the port at which the clients will connect clientPort=2183 # 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=localhost:2187:2887 server.2=localhost:2188:2888 server.3=localhost:2189:2889
(2.1.7)データディレクトリとログディレクトリを作成します
mkdir -p /apps/servers/data/d_1 mkdir -p /apps/servers/data/d_2 mkdir -p /apps/servers/data/d_3
mkdir -p / apps / servers / logs / logs_1
mkdir -p / apps / servers / logs / logs_2
mkdir -p / apps / servers / logs / logs_3
echo "1"> / apps / servers / data / d_1 / myid
echo "2"> / apps / servers / data / d_2 / myid
echo "3"> / apps / servers / data / d_3 / myid
![](https://upload-images.jianshu.io/upload_images/11223715-29358fa9e009905c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
> (2.1.8)进入bin目录下输入命令 分别进行启动
``` bash
cd /root/zookeeper-3.4.10/bin
sh zkServer.sh start ../conf/zoo1.cfg
sh zkServer.sh start ../conf/zoo2.cfg
sh zkServer.sh start ../conf/zoo3.cfg
(2.1.9)それぞれを入力して効果を確認します
source /etc/profile sh zkCli.sh -server localhost:2181 sh zkCli.sh -server localhost:2182 sh zkCli.sh -server localhost:2183
疑似配布は実際にはこのようにして完了します。焦点はまだ分散されており、見下ろしています。
- (1.2)分散環境構成
(1.2.1)基本設定(3台すべての設定が必要)
su #密码 vagrant cd ~ vi /etc/ssh/sshd_config sudo systemctl restart sshd
vi /etc/resolv.conf
8.8.8.8に設定
サービスネットワークの再起動
![](https://upload-images.jianshu.io/upload_images/11223715-af39780dc5b88a2c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/11223715-1006580435e435f3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/11223715-514cba97d35d79e3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/11223715-42238d619aa86169.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/11223715-099a2ba509e81d91.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/11223715-008debaab296be6f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/11223715-fc58d43a8ce53bf2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/11223715-faa0c439160805be.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
![](https://upload-images.jianshu.io/upload_images/11223715-d036b005acb8483f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
>(1.2.2)jdk安装(三台机器都需要设置)
>脚本在我的源码里面
``` bash
vi pro.sh
sh pro.sh
(1.2.3)Zookeeperのダウンロード(3台すべてのマシンをセットアップする必要があります)
ダウンロードツールは、3.5.4にリリースされた最新のものを使用することを忘れないでください。まだ3.4.10を使用しています。
なぜ3台あるのですか?奇数が好きで、偶数は好きではありません。
wget https://www-eu.apache.org/dist/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz
(1.2.4)動物園の飼育係を解凍する
tar zxvf zookeeper-3.4.10.tar.gz
(1.2.4)cfgファイルを構成します(3台すべてのマシンを設定する必要があります)
cd ~
cd zookeeper-3.4.10/
cd conf
cp zoo_sample.cfg zoo.cfg
(1.2.5)cfgファイルを構成します。実際、これら3台のマシンの構成ファイルは同じです。cfgの記述を繰り返すのではなく、スクリーンショットを撮るだけです。
vi zoo.cfg
# 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=/tmp/zookeeper
dataLogDir=/tmp/zookeeper/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.0=192.168.69.101:2888:3888
server.1=192.168.69.102:2888:3888
server.2=192.168.69.103:2888:3888
(1.2.6)myidの構成は、
dataDir = / tmp / zookeeperの上のディレクトリに構成する必要があります。cd / cd tmp mkdir zookeeper cd zookeeper
(1.2.6.1)192.168.69.101 configure myid
echo '0'>myid cat myid
(1.2.6.2)192.168.69.102 configure myid
echo '1'>myid cat myid
(1.2.6.3)192.168.69.103 configure myid
echo '2'>myid cat myid
コマンドを開始して、3つの仮想マシンでzookeeperを実行します
cd ~/zookeeper-3.4.10/bin
sh zkServer.sh start
####(3)概念的なコーミング
- (3.1)Zoo.cfgの構成
パラメータ | 意義 |
---|---|
tickTime | 2000年 |
syncLimit | リーダーとフォロワー間の最長の通信時間は、initLimt * ticktimeを超えることはできません。 |
initLimt | クライアントリンクzkによって初期化された最長待機ハートビート時間initLimt * ticktimeを受け入れる |
dataDir | データディレクトリ |
dataLogDir | ログファイル |
clientPort | クライアントリンクサーバーのポート番号Server.A = B:C:DA:番号サーバーBサービスIP Cは、リーダーとフォロワーの通信ポートDの代替リーダーポートを表します |
- (3.2)役割
盟主:
リーダーは、ZooKeeperクラスター全体のマスターノードとして、ZooKeeperの状態変更に対するすべてのリクエストに応答する責任があります。クラスター全体の内部メッセージ処理のFIFOおよび書き込み操作がリーダーに確実に行われるように、各ステータス更新要求を並べ替えて番号を付けます。
フォロワー:
フォロワーのロジックは比較的単純です。フォロワーは、このサーバーで読み取り要求に応答するだけでなく、リーダーの提案を処理し、リーダーが提案を送信するときにローカルに送信します。もう1つの注意点は、リーダーとフォロワーがZooKeeperクラスターのクォーラムを構成していることです。つまり、新しいリーダーの選出に参加し、リーダーの提案に応答するのは彼らだけです。
観察者 :
ZooKeeperクラスターの読み取り負荷が高い場合、またはコンピュータールーム全体に多数のクライアントがある場合は、いくつかのオブザーバーサーバーをセットアップして、読み取りスループットを向上させることができます。オブザーバーとフォロワーは似ていますが、いくつかの小さな違いがあります。まず、オブザーバーはクォーラムではありません。つまり、オブザーバーは選挙に参加せず、提案に応答しません。次に、オブザーバーはトランザクションをディスクに保持する必要がありません。オブザーバーが再起動された場合、名前全体をリーダースペースから再同期する必要があります。
- (3.3)Zookeeperの機能
Zookeeperは複数のサーバーで構成されてい
ます1.1つのリーダー、複数のフォロワーをクラスター化します
2.各サーバーはデータのコピーを保存します
3.グローバルデータは一貫性があり、読み取りフォロワーに配布され、書き込み更新はリーダーによって転送され、リーダーによって更新されます順番に作成され、同じクライアントからの更新要求がアトミック性の送信順に実行されます
。4。データ更新が成功または失敗します。グローバルに一意のデータビュー
。5。データビューは、どのサーバーに関係なく常に同じです。クライアントは接続されています。一定のリアルタイムで、特定の範囲のイベント内で、クライアントは最新のデータを読み取ることができます。
PS:今回は、主にZookeeperとクラスターのデプロイの原則について説明しますが、詳細についてはあまり詳しく説明しませんでした。次回は、Zookeeperの使用について説明します。