{"id":52,"date":"2023-07-20T10:38:52","date_gmt":"2023-07-20T02:38:52","guid":{"rendered":"https:\/\/guoyingxu.cn\/?p=52"},"modified":"2023-07-20T16:22:10","modified_gmt":"2023-07-20T08:22:10","slug":"install_zookeeper_kafka","status":"publish","type":"post","link":"https:\/\/guoyingxu.cn\/?p=52","title":{"rendered":"install_zookeeper_kafka"},"content":{"rendered":"\n<!doctype html>\n<html>\n<head>\n<meta charset='UTF-8'><meta name='viewport' content='width=device-width initial-scale=1'>\n<title><\/title>\n<\/head>\n<body>\n<pre><code class='language-shell' lang='shell'>#!\/usr\/bin\/bash\n#1\u3001\u914d\u7f6e\u811a\u672c\u4e2d\u7684myid\u6587\u4ef6\u4e00\u5b9a\u8981\u5728\u8bbe\u7f6e\u7684dataDir=\/tmp\/zookeeper\u76ee\u5f55\u4e0b\uff0c\u5426\u5219\u9879\u76ee\u65e0\u6cd5\u542f\u52a8\n#2\u3001zookeeper\u8981\u8bbe\u7f6eserver.1-3.\u5176\u4e2dzookeeper\u670d\u52a1\u7aef\u53e3\u4e3a2181 \u9009\u4e3e\u7aef\u53e3\u4e3a2888:3888\n#kafaka\u521b\u5efatopic\n#bin\/kafka-topics.sh --create --topic quickstart-events --bootstrap-server localhost:9092\n#kafaka\u663e\u793atopic\n#bin\/kafka-topics.sh --describe --topic quickstart-events --bootstrap-server localhost:9092\n#kafaka\u4f7f\u7528\u751f\u4ea7\u8005\u751f\u4ea7\u6570\u636e\n#bin\/kafka-console-producer.sh --topic quickstart-events --bootstrap-server localhost:9092\n#kafaka\u4f7f\u7528\u6d88\u8d39\u7740\u6d88\u8d39\u6570\u636e\n#bin\/kafka-console-consumer.sh --topic quickstart-events --from-beginning --bootstrap-server localhost:9092\n#####################################################################################\n#\u9700\u8981\u81ea\u884c\u914d\u7f6ehostname\u548chosts################*************************************###\n############################################*************\u6ce8\u610f*******************###\n############################################***********************************###\n#firewalled\u9700\u8981\u7981\u7528\u6216\u8005\u653e\u884c#\n############################\n#systemctl stop firewall \n#systemctl stop firewalld \n#systemctl disable firewalld \n#systemctl status firewalld \n##############################\u6d4b\u8bd5\u5361\u592b\u5361##########################################\n#kafaka\u521b\u5efatopic\n#bin\/kafka-topics.sh --create --topic quickstart-events --bootstrap-server localhost:9092\n#kafaka\u663e\u793atopic\n#bin\/kafka-topics.sh --describe --topic quickstart-events --bootstrap-server localhost:9092\n#kafaka\u4f7f\u7528\u751f\u4ea7\u8005\u751f\u4ea7\u6570\u636e\n#bin\/kafka-console-producer.sh --topic quickstart-events --bootstrap-server localhost:9092\n#kafaka\u4f7f\u7528\u6d88\u8d39\u7740\u6d88\u8d39\u6570\u636e\n#bin\/kafka-console-consumer.sh --topic quickstart-events --from-beginning --bootstrap-server localhost:9092\n\n\n\nip=&quot;\n192.168.98.170\n192.168.98.171\n192.168.98.172\n&quot;\n#myid\u589e\u957f\u8d77\u59cb\u503c\ng=1\np=0\n#\u670d\u52a1\u5668\u5bc6\u7801\npasswd=123456\n#sed\u66ff\u6362kafka\u914d\u7f6e\u6587\u4ef6\u4e2d\u7684zookeeper\u5730\u5740\nconfig=&quot;zookeeper.connect\\=192.168.98.170:2181,192.168.98.171:2181,192.168.98.172:2181&quot;\n#\u8ffd\u52a0\u914d\u7f6ezookeeper\u914d\u7f6e\u6587\u4ef6\ncat &lt;&lt;EOF &gt;tmp.txt\ntickTime=2000\ninitLimit=10\nsyncLimit=5\nserver.1=192.168.98.170:2888:3888\nserver.2=192.168.98.171:2888:3888\nserver.3=192.168.98.172:2888:3888\nEOF\n#\u5faa\u73af\u540e\u53f0\u542f\u52a8zookeeper\u4efb\u52a1\u8fdb\u7a0b\ncat &lt;&lt;EOF &gt;jc.txt\nnohup \/usr\/local\/kafka\/bin\/zookeeper-server-start.sh \/usr\/local\/kafka\/config\/zookeeper.properties &amp;&gt;\/tmp\/zookeeper.log\nEOF\n\nexp1=&quot;export JAVA_HOME=\\\/usr\\\/lib\\\/jvm\\\/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64&quot;\nexp2=&quot;export CLASSPATH=.:\\$JAVA_HOME\\\/jre\\\/lib\\\/rt.jar:\\$JAVA_HOME\\\/lib\\\/dt.jar:\\$JAVA_HOME\\\/lib\\\/tools.jar&quot;\nexp3=&quot;export PATH=\\$PATH:\\$JAVA_HOME\\\/bin&quot;\nl1=&quot;unset i&quot;\necho &quot;############################1\u3001\u914d\u7f6e\u670d\u52a1\u5668\u5bc6\u94a5############################&quot;\nfor a in $ip\ndo\n\/usr\/bin\/expect &lt;&lt;EOF\nspawn  ssh-copy-id $a\nexpect {\n&quot;yes\/no&quot; { send &quot;yes\\r&quot;; exp_continue }\n&quot;*password&quot; { send &quot;$passwd\\n&quot;; exp_continue }\n{ send &quot;\\n&quot;}\n}\nEOF\ndone\n\n\necho &quot;############################2\u3001\u62f7\u8d1dkafka\u5b89\u88c5\u5305############################&quot;\nfor i  in $ip\ndo\n\tscp kafka_2.12-2.8.0.tgz tmp.txt  root@$i:\/tmp\/\ndone\nwait;\necho &quot;sed \u66ff\u6362\u7684zookeeper.connect \u672a\u8bbe\u7f6e\u4e3a\u53d8\u91cf\u8bf7\u81ea\u884c\u8bbe\u7f6eczookeeper.connect\\=192.168.98.170:2181,192.168.98.171:2181,192.168.98.172:2181&quot;\necho &quot;############################3\u3001\u914d\u7f6ejdk\u3001\u53ca\u670d\u52a1\u53d8\u91cf############################&quot;\nfor j in $ip\ndo  \n\tssh root@$j &quot;cd \/tmp\/\n\ttar -zvxf kafka_2.12-2.8.0.tgz\n\trm -rf \/usr\/local\/kafka\/\n\tcp -rp kafka_2.12-2.8.0 \/usr\/local\/kafka\/\n\tmkdir -p \/usr\/local\/kafka\/zookeeper\n\tmkdir -p \/tmp\/zookeeper\/\n\tmkdir -p \/tmp\/zookeeper\/log\ncat &lt;&lt;EOF &gt;\/tmp\/zookeeper\/myid\n$g\nEOF\ncat \/tmp\/tmp.txt &gt;&gt; \/usr\/local\/kafka\/config\/zookeeper.properties\nsed -ir &quot;\/^broker.id\\=0\/cbroker.id\\=$g&quot; \/usr\/local\/kafka\/config\/server.properties\nsed -ir &quot;\/^zookeeper.connect\\=\/c$config&quot; \/usr\/local\/kafka\/config\/server.properties\nyum install -y java-1.8.0-openjdk.x86_64\nyum install -y java-1.8.0-openjdk-devel.x86_64\nsed -ri &#39;\/unset i\/i$exp1&#39; \/etc\/profile\nsed -ri &#39;\/unset i\/i$exp2&#39; \/etc\/profile\nsed -ri &#39;\/unset i\/i$exp3&#39; \/etc\/profile\nsource \/etc\/profile\n&quot;\nlet ++p\nlet ++g\ndone\nwait\necho &quot;\u542f\u52a8\u4efb\u52a1\u5e76\u8bbe\u7f6e\u4e3a\u540e\u53f0\u8fdb\u7a0b&quot;\necho &quot;############################4\u3001\u914d\u7f6e\u670d\u52a1\u5f00\u673a\u81ea\u542f############################&quot;\nfor kk in $ip\ndo\n        {\n        ssh root@$kk &quot; \ncat &lt;&lt;EOF &gt;\/etc\/systemd\/system\/zookeeper.service\n[Unit]\nDescription=Zookeeper\nAfter=network.target remote-fs.target nss-lookup.target\n \n[Service]\nExecStart=\/usr\/local\/kafka\/bin\/zookeeper-server-start.sh \/usr\/local\/kafka\/config\/zookeeper.properties\nExecReload=\/bin\/kill -s HUP $MAINPID\nExecStop=\/usr\/local\/kafka\/bin\/zookeeper-server-stop.sh\n \n[Install]\nWantedBy=multi-user.target\nEOF\n\ncat &lt;&lt;EOF &gt;\/etc\/systemd\/system\/kafka.service\n[Unit]\nDescription=kafka\nAfter=network.target remote-fs.target nss-lookup.target zookeeper.service\n \n[Service]\nExecStart=\/usr\/local\/kafka\/bin\/kafka-server-start.sh \/usr\/local\/kafka\/config\/server.properties\nExecReload=\/bin\/kill -s HUP $MAINPID\nExecStop=\/usr\/local\/kafka\/bin\/kafka-server-stop.sh\n#PrivateTmp=true\n \n[Install]\nWantedBy=multi-user.target\nEOF\n\nsystemctl daemon-reload\nsystemctl enable zookeeper.service\nsystemctl start zookeeper\nsystemctl enable kafka.service\nsystemctl start kafka\n&quot;\n        }&amp;\ndone\n\necho &quot;\u670d\u52a1\u542f\u52a8\u5b8c\u6bd5\uff0c\u8bf7\u81ea\u68c0 systemctl status zookeeper&quot;\necho &quot;\u670d\u52a1\u542f\u52a8\u5b8c\u6bd5\uff0c\u8bf7\u81ea\u68c0 systemctl status kafka&quot;\necho &quot;\u521b\u5efatopic\uff0c\u67e5\u770b\u662f\u5426\u53ef\u4ee5\u521b\u5efa\u6210\u529f&quot;\necho &quot;\/usr\/local\/kafka\/bin\/kafka-topics.sh --create --topic quickstart-events --bootstrap-server localhost:9092&quot;\necho &quot;\u663e\u793atopic\uff0c\u663e\u793aLeader,\u663e\u793aReplicas,\u663e\u793aIsr&quot;\necho &quot;\/usr\/local\/kafka\/bin\/kafka-topics.sh --describe --topic quickstart-events --bootstrap-server localhost:9092&quot;\necho &quot;\u521b\u5efa\u751f\u4ea7\u8005,\u751f\u4ea7\u6570\u636e&quot;\necho &quot;\/usr\/local\/kafka\/bin\/kafka-console-producer.sh --topic quickstart-events --bootstrap-server localhost:9092&quot;\necho &quot;\u521b\u5efa\u6d88\u8d39\u8005\uff0c\u8bfb\u53d6\u751f\u4ea7\u8005\u6570\u636e&quot;\necho &quot;\/usr\/local\/kafka\/bin\/kafka-console-consumer.sh --topic quickstart-events --from-beginning --bootstrap-server localhost:9092&quot;\n<\/code><\/pre>\n<\/body>\n<\/html>\n","protected":false},"excerpt":{"rendered":"<p>#!\/usr\/bin\/bash #1\u3001\u914d\u7f6e\u811a\u672c\u4e2d\u7684myid\u6587\u4ef6\u4e00\u5b9a\u8981\u5728\u8bbe\u7f6e\u7684dataDir=\/tmp\/zook [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-52","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=\/wp\/v2\/posts\/52","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=52"}],"version-history":[{"count":0,"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=\/wp\/v2\/posts\/52\/revisions"}],"wp:attachment":[{"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}