{"id":41,"date":"2023-07-20T10:07:27","date_gmt":"2023-07-20T02:07:27","guid":{"rendered":"https:\/\/guoyingxu.cn\/?p=41"},"modified":"2023-07-20T10:11:53","modified_gmt":"2023-07-20T02:11:53","slug":"shell-install","status":"publish","type":"post","link":"https:\/\/guoyingxu.cn\/?p=41","title":{"rendered":"shell-install"},"content":{"rendered":"<p><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width initial-scale=1\"><br \/>\n<title>shell\u811a\u672c-install<\/title><\/p>\n<h1 id=\"shell\u811a\u672c-install\">shell\u811a\u672c-install<\/h1>\n<h2 id=\"installelasticsearch\">install_elasticsearch<\/h2>\n<pre><code class=\"language-shell\" lang=\"shell\">#!\/usr\/bin\/bash\n#\u642d\u5efaelastic\u96c6\u7fa4\n#elastic\u670d\u52a1\u5fc5\u987b\u8981\u91cd\u542f\u624d\u53ef\u4ee5\u8fdb\u884c\u5b89\u88c5\u5b8c\u6210\uff0c\u8981\u4e0d\u7136\u7cfb\u7edf\u53e5\u67c4\u65e0\u6cd5\u8bbe\u7f6e\u3002\n#--------------------------------------------------------------------------------------#\n#--------------------------------------------------------------------------------------#\n#\u5b9a\u4e49\u9700\u8981\u642d\u5efa\u7684\u96c6\u7fa4\u548c\u5bc6\u7801\nip_addr=\"\n192.168.98.173 123456\n192.168.98.174 123456\n192.168.98.175 123456\n\"\n#\u5b9a\u4e49hosts\u540d\u79f0\nname=\"elastic\"\n#\u5b9a\u4e49\u5b89\u88c5\u5305\u540d\u79f0\nelasticsearch_package_name=\"elasticsearch-7.14.0-linux-x86_64.tar.gz\"\n#\u521b\u5efa\u7684elastic\u7528\u6237\nuser=\"elastic\"\n#\u521b\u5efa\u7684elastic\u7528\u6237\u5bc6\u7801\npass=\"1234567\"\n#\u5b9a\u4e49elastic\u7684\u65e5\u5fd7\u548c\u6570\u636e\u5b58\u50a8\u8def\u5f84\npath_data=\"\/opt\/data\"\npath_log=\"\/opt\/log\"\n#\u6743\u9650\u95ee\u9898\u5fc5\u987b\u5b9a\u4e49data\u548clog\u7684\u4e0a\u5c42\u76ee\u5f55\u8981\u4e0d\u7136\u7a0b\u5e8f\u65e0\u6cd5\u542f\u52a8\npath_ll=\"\/opt\"\n#--------------------------------------------------------------------------------------#\n#--------------------------------------------------------------------------------------#\nnode_id=\"1\"\n\nIFS='\n'\n#\u63a8\u9001\u4e3b\u673a\u516c\u94a5\n\nif [ ! -e $elasticsearch_package_name ];then\n\texit\nfi\n\nfor line in $ip_addr\ndo\n\tip=`echo \"$line\" |awk '{print $1}'`\n\tpasswd=`echo \"$line\" |awk '{print $2}'`\n\tping -c1 -W1 $ip &amp;&gt;\/dev\/null\n\tif [ $? -eq 0 ];then\n\/usr\/bin\/expect &lt;&lt;EOF\nspawn ssh-copy-id $ip\nexpect {\n\"yes\/no\" { send \"yes\\r\" ; exp_continue }\n\"password\" { send \"$passwd\\r\" ; exp_continue }\n\"*#\" { send \"\\r\"}\n}\nEOF\n\telse\n\t echo \"$ip\"| tee -a fail_ip.txt\n\tfi\ndone\nwait\necho \"1\u3001ssh-copy-id  is ok!\"\n\nIFS='\n'\n#\u4fee\u6539\u4e3b\u673ahosts\u548chostname\nfor e_host in $ip_addr\ndo\n\tip=`echo \"$e_host\" |awk '{print $1}'`\n\tnet_addr=`ssh root@$ip \" ip addr |egrep '\\&lt;inet\\&gt;'|grep -v '127.0.0.1'|awk '{print \\\\$2}'|awk -F'\/' '{print \\\\$1}' \"`\n\tssh root@$ip \" echo \"$name-$net_addr\" &gt; \/etc\/hostname \"\n\tgg=`ssh root@$ip \" cat \/etc\/hostname \"`\n\tssh root@$ip \" echo \"$net_addr $gg\" &gt;&gt; \/etc\/hosts \"\n\ndone\nwait\n#\u62f7\u8d1d\u5b89\u88c5\u5305\nIFS='\n'\nfor a_copy in $ip_addr\ndo\n\tip=`echo \"$a_copy\" |awk '{print $1}'`\n\tel_ip[++j]=`echo \"$a_copy\"|awk '{print $1}'`\n\tscp $elasticsearch_package_name  root@$ip:\/tmp\/\n\tssh root@$ip \" if [ -e \"\/tmp\/$elasticsearch_package_name\" ];then echo \"$ip File copy complete\" ; else echo \"$ip File copy failed\" exit ; fi \"\ndone\nwait\n#\u83b7\u53d6ip\u4f20\u9012\u7ed9\u6570\u7ec4\nfor hq_ip in ${!el_ip[@]}\ndo\n\t#echo \"${el_ip[hq_ip]}\"\n\techo \"ipaddr\"\ndone\n\n#\u914d\u7f6eelastic\nIFS='\n'\nfor c_con in $ip_addr\ndo\n\tip=`echo \"$c_con\" |awk '{print $1}'`\n\t\n\tssh root@$ip \" cd \/tmp\ntar -zxvf $elasticsearch_package_name \nmv elasticsearch-7.14.0 \/usr\/local\/elasticsearch\nuseradd $user ; echo \"$pass\" |passwd --stdin $user &amp;&gt;\/dev\/null\nchown -R $user:$user \/usr\/local\/elasticsearch\nmkdir $path_data\nmkdir $path_log\nchown -R $user:$user $path_ll\nchown -R $user:$user $path_data\nchown -R $user:$user $path_log\n \ncat &lt;&lt;EOF &gt;&gt;\/etc\/security\/limits.conf\n$user soft nofile 65536\n$user hard nofile 65536\n* soft nproc 65536\n* hard nproc 65536\nEOF\n\ncat &lt;&lt;EOF &gt;&gt;\/etc\/security\/limits.d\/20-nproc.conf\n$user soft nofile 65536\n$user hard nofile 65536\nEOF\n\ncat &lt;&lt;EOF &gt;&gt;\/etc\/sysctl.conf\nvm.max_map_count=655360\nEOF\n\ncat &lt;&lt;EOF &gt;&gt;\/usr\/local\/elasticsearch\/config\/elasticsearch.yml\ncluster.name: elastic-application\nnode.name: node-$node_id\nnode.master: true\nnode.data: true\nnode.max_local_storage_nodes: 3\nnetwork.host: 0.0.0.0\nhttp.port: 9200\ntransport.tcp.port: 9700\ndiscovery.seed_hosts: [\"${el_ip[1]}\", \"${el_ip[2]}\",\"${el_ip[3]}\"]\ncluster.initial_master_nodes: [\"node-1\", \"node-2\",\"node-3\"]\npath.data: $path_data\npath.logs: $path_log\nEOF\n\nsysctl -p\nsystemctl stop firewalld\nsystemctl disable firewalld\n\ncat &lt;&lt;EOF &gt;&gt;\/usr\/lib\/systemd\/system\/elasticsearch.service\n[Unit]\nDescription=elasticsearch\nAfter=network.target\n\n[Service]\nType=forking\nUser=elastic\nExecStart=\/usr\/local\/elasticsearch\/bin\/elasticsearch -d\nPrivateTmp=true\n# \u6307\u5b9a\u6b64\u8fdb\u7a0b\u53ef\u4ee5\u6253\u5f00\u7684\u6700\u5927\u6587\u4ef6\u6570\nLimitNOFILE=65535\n# \u6307\u5b9a\u6b64\u8fdb\u7a0b\u53ef\u4ee5\u6253\u5f00\u7684\u6700\u5927\u8fdb\u7a0b\u6570\nLimitNPROC=65535\n# \u6700\u5927\u865a\u62df\u5185\u5b58\nLimitAS=infinity\n# \u6700\u5927\u6587\u4ef6\u5927\u5c0f\nLimitFSIZE=infinity\n# \u8d85\u65f6\u8bbe\u7f6e 0-\u6c38\u4e0d\u8d85\u65f6\nTimeoutStopSec=0\n# SIGTERM\u662f\u505c\u6b62java\u8fdb\u7a0b\u7684\u4fe1\u53f7\nKillSignal=SIGTERM\n# \u4fe1\u53f7\u53ea\u53d1\u9001\u7ed9\u7ed9JVM\nKillMode=process\n# java\u8fdb\u7a0b\u4e0d\u4f1a\u88ab\u6740\u6389\nSendSIGKILL=no\n# \u6b63\u5e38\u9000\u51fa\u72b6\u6001\nSuccessExitStatus=143\n\n[Install]\nWantedBy=multi-user.target\nEOF\n\nsystemctl daemon-reload\nsystemctl enable elasticsearch.service\nsystemctl start elasticsearch.service\nreboot\n\"\nlet ++node_id\ndone\n\nsleep 1m\n#\u91cd\u542f\u670d\u52a1\u5668\u662flimit\u914d\u7f6e\u53e5\u67c4\u751f\u6548\nIFS='\n'\nfor d_res in $ip_addr\ndo\n\techo -n \"$ip \u7cfb\u7edf\u53e5\u67c4\u4e3a\"\n\tip=`echo \"$d_res\" |awk '{print $1}'`\n\tssh root@$ip \"ulimit -Hu\"\n\techo -n \"$i \u72b6\u6001\u4e3a\"\n        ssh root@$ip \" systemctl status elasticsearch.service|grep Active\"\n\n\ndone\nwait\necho \"\u8bf7\u901a\u8fc7\u4ee5\u4e0b\u94fe\u63a5\u67e5\u770b\u670d\u52a1\u96c6\u7fa4\u662f\u5426\u642d\u5efa\u5b8c\u6210\" \necho \"http:\/\/${el_ip[1]}:9200\/_cat\/health?v\"\n<\/code><\/pre>\n<h2 id=\"installgrafana\">install_grafana<\/h2>\n<pre><code class=\"language-shell\" lang=\"shell\">#!\/usr\/bin\/bash\ndownload_url=\nservice_status=`systemctl status grafana-server |grep Active |awk '{print $3}'`\nip=`ip addr |grep inet |grep brd |awk '{print $2}' |awk -F '\/' '{print $1}'`\nif [ -e \"grafana-8.0.6-1.x86_64.rpm\" ];then\n\tyum install -y grafana-8.0.6-1.x86_64.rpm\n\t\/sbin\/chkconfig --add grafana-server\n\tsystemctl enable grafana-server.service\n\tsystemctl start grafana-server\n\tsystemctl status grafana-server &amp;&gt;\/dev\/null\n\tif [[ $service_status == \"(running)\" ]];then\n\t\techo \"\u670d\u52a1\u8fd0\u884c\u6210\u529f,\u8bf7\u901a\u8fc7 http:\/\/$ip:3000 \u8fdb\u884c\u8bbf\u95ee\uff0c\u8d26\u53f7\uff1aadmin \u5bc6\u7801 admin\"\n\t\techo \"grafana \u65e5\u5fd7\u6587\u4ef6\u4f4d\u7f6e\uff1a\/var\/log\/grafana\"\n\t\techo \"grafana \u73af\u5883\u6587\u4ef6\u4f4d\u7f6e\uff1a \/etc\/sysconfig\/grafana-server\"\n\t\techo \"grafana \u914d\u7f6e\u6587\u4ef6\u4f4d\u7f6e\uff1a \/etc\/grafana\/grafana.ini\"\n\t\techo \"grafana \u7684\u56fe\u8868\u901a\u8fc7\u4ee5\u4e0b\u5730\u5740\u8fdb\u884c\u4e0b\u8f7dhttps:\/\/grafana.com\/grafana\/dashboards\"\n\tfi\nelse\n\twget $download_url\n\tyum install -y grafana-8.0.6-1.x86_64.rpm\n\t\/sbin\/chkconfig --add grafana-server\n\tsystemctl enable grafana-server.service\n\tsystemctl start grafana-server\n\tsystemctl status grafana-server &amp;&gt;\/dev\/null\n\tif [[ $service_status == \"(running)\" ]];then\n\t\techo \"\u670d\u52a1\u8fd0\u884c\u6210\u529f,\u8bf7\u901a\u8fc7 http:\/\/$ip:3000 \u8fdb\u884c\u8bbf\u95ee\uff0c\u8d26\u53f7\uff1aadmin \u5bc6\u7801 admin\"\n\t\techo \"grafana \u65e5\u5fd7\u6587\u4ef6\u4f4d\u7f6e\uff1a\/var\/log\/grafana\"\n\t\techo \"grafana \u73af\u5883\u6587\u4ef6\u4f4d\u7f6e\uff1a \/etc\/sysconfig\/grafana-server\"\n\t\techo \"grafana \u914d\u7f6e\u6587\u4ef6\u4f4d\u7f6e\uff1a \/etc\/grafana\/grafana.ini\"\n\t\techo \"grafana \u7684\u56fe\u8868\u901a\u8fc7\u4ee5\u4e0b\u5730\u5740\u8fdb\u884c\u4e0b\u8f7dhttps:\/\/grafana.com\/grafana\/dashboards\"\n\tfi\nfi\n<\/code><\/pre>\n<h2 id=\"installnodeexporter\">install_node_exporter<\/h2>\n<pre><code class=\"language-shell\" lang=\"shell\">#!\/usr\/bin\/bash\ndownload_url=\nip=`ip addr |grep inet |grep brd |awk '{print $2}' |awk -F '\/' '{print $1}'`\nnode_exporter_status=`systemctl status node_exporter |grep Active |awk  '{print $3}'`\nif [ -e \"node_exporter-1.2.0.linux-amd64.tar.gz\" ];then\n\ttar -zvxf node_exporter-1.2.0.linux-amd64.tar.gz\n\tmv node_exporter-1.2.0.linux-amd64 \/usr\/local\/node_exporter\ncat &gt; \/etc\/systemd\/system\/node_exporter.service &lt;&lt; EOF\n[Unit]\nDescription=node_exporter\nDocumentation=https:\/\/prometheus.io\/\nAfter=network.target\n[Service]\nType=simple\nUser=root\nExecStart=\/usr\/local\/node_exporter\/node_exporter\nRestart=on-failure\n[Install]\nWantedBy=multi-user.target\nEOF\n\tsystemctl enable node_exporter\n\tsystemctl daemon-reload\n\tsystemctl start node_exporter\n\tsystemctl status node_exporter &amp;&gt;\/dev\/null\n\tif [[ $node_exporter_status == \"(running)\" ]];then\n\t\techo \"\u670d\u52a1\u5b89\u88c5\u6210\u529f\uff0c\u8bf7\u901a\u8fc7 http:\/\/$ip:9100 \u8fdb\u884c\u8bbf\u95ee\"\n\telse\n\t\techo \"\u670d\u52a1\u5b89\u88c5\u5931\u8d25\"\n\tfi\n\nelse\n\twget $download_url \n\ttar -zvxf node_exporter-1.2.0.linux-amd64.tar.gz\n\tmv node_exporter-1.2.0.linux-amd64 \/usr\/local\/node_exporter\ncat &gt; \/etc\/systemd\/system\/node_exporter.service &lt;&lt; EOF\n[Unit]\nDescription=node_exporter\nDocumentation=https:\/\/prometheus.io\/\nAfter=network.target\n[Service]\nType=simple\nUser=root\nExecStart=\/usr\/local\/node_exporter\/node_exporter\nRestart=on-failure\n[Install]\nWantedBy=multi-user.target\nEOF\n\tsystemctl enable node_exporter\n\tsystemctl daemon-reload\n\tsystemctl start node_exporter\n\tsystemctl status node_exporter &amp;&gt;\/dev\/null\n\tif [[ $node_exporter_status == \"(running)\" ]];then\n\t\techo \"\u670d\u52a1\u5b89\u88c5\u6210\u529f\uff0c\u8bf7\u901a\u8fc7 http:\/\/$ip:9100 \u8fdb\u884c\u8bbf\u95ee\"\n\telse\n\t\techo \"\u670d\u52a1\u5b89\u88c5\u5931\u8d25\"\n\tfi\n\nfi\n<\/code><\/pre>\n<h2 id=\"installprometheus\">install_prometheus<\/h2>\n<pre><code class=\"language-shell\" lang=\"shell\">#!\/usr\/bin\/bash\nurl=\"\"\nip=`ip addr |grep inet |grep brd |awk '{print $2}' |awk -F '\/' '{print $1}'`\nprometheus_status=`systemctl status prometheus |grep Active |awk  '{print $3}' `\nold_status=\"(running)\"\nif [ -e prometheus-2.28.1.linux-amd64.tar.gz ];then\n\ttar -zxvf prometheus-2.28.1.linux-amd64.tar.gz\n\tif [ ! -d \/usr\/local\/prometheus ];then\n\t\techo \"\u79fb\u52a8\u6587\u4ef6\"\n\t\tmv prometheus-2.28.1.linux-amd64 \/usr\/local\/prometheus\n\t\techo \"\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u7684localhost\u4e3a\u672c\u673a$ip\"\n\t\tsed -ir \"s\/localhost\/$ip\/\" \/usr\/local\/prometheus\/prometheus.yml\ncat &lt;&lt;EOF &gt;\/usr\/lib\/systemd\/system\/prometheus.service\n[Unit]\nDescription=prometheus\nDocumentation=https:\/\/prometheus.io\/\nAfter=network-online.target\n\n[Service]\nUser=root\nRestart=on-failure\nExecStart=\/usr\/local\/prometheus\/prometheus  \\\n  --config.file=\/usr\/local\/prometheus\/prometheus.yml\nExecReload=\/bin\/kill -HUP $MAINPID\n[Install]\nWantedBy=multi-user.target\nEOF\n\t\techo \"\u521b\u5efa\u7cfb\u7edf\u670d\u52a1\"\n\t\tsystemctl enable prometheus \n\t\techo \"\u8bbe\u7f6e\u6210\u5f00\u673a\u81ea\u542f\"\n\t\tsystemctl daemon-reload \n\t\techo \"\u6bcf\u6b21\u66f4\u6539prometheus.service\u90fd\u9700\u8981\u6267\u884c\u4e00\u6b21\uff0c\u91cd\u65b0\u52a0\u8f7d\u4e00\u4e0b\"\n\t\tsystemctl start prometheus\n\t\techo \"\u542f\u52a8prometheus\u670d\u52a1\"\n\t\tsystemctl status prometheus &amp;&gt;\/dev\/null\n\t\tif [[ $prometheus_status -eq $old_status ]];then\n\t\t\techo \"\u670d\u52a1install\u6210\u529f,\u8bf7\u901a\u8fc7http:\/\/$ip:9090\u8fdb\u884c\u8bbf\u95ee\uff0c\u7a0b\u5e8f\u9000\u51fa\u3002\u3002\u3002\"\n\t\t\texit\n\t\telse\n\t\t\techo \"\u670d\u52a1\u5b89\u88c5\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u3002\u3002\"\n\t\t\texit\n\t\tfi\n\telse\n\t\techo \"\u76ee\u5f55\u5df2\u5b58\u5728\uff0c\u7a0b\u5e8f\u9000\u51fa\"\n\t\texit\n\tfi\n\nelse\n\techo \"\u5f53\u524d\u76ee\u5f55\u4e0d\u5b58\u5728\u5b89\u88c5\u5305\uff0c\u5c06\u8981\u5f00\u59cb\u4e0b\u8f7d\u5b89\u88c5\u5305\"\n\twget $url\n        tar -zxvf prometheus-2.28.1.linux-amd64.tar.gz\n        if [ ! -d \/usr\/local\/prometheus ];then\n                echo \"\u79fb\u52a8\u6587\u4ef6\"\n                mv prometheus-2.28.1.linux-amd64 \/usr\/local\/prometheus\n                echo \"\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u7684localhost\u4e3a\u672c\u673a$ip\"\n                sed -ir \"s\/localhost\/$ip\/\" \/usr\/local\/prometheus\/prometheus.yml\ncat &lt;&lt;EOF &gt;\/usr\/lib\/systemd\/system\/prometheus.service\n[Unit]\nDescription=prometheus\nDocumentation=https:\/\/prometheus.io\/\nAfter=network-online.target\n\n[Service]\nUser=root\nRestart=on-failure\nExecStart=\/usr\/local\/prometheus\/prometheus  \\\n  --config.file=\/usr\/local\/prometheus\/prometheus.yml\nExecReload=\/bin\/kill -HUP $MAINPID\n[Install]\nWantedBy=multi-user.target\nEOF\n                echo \"\u521b\u5efa\u7cfb\u7edf\u670d\u52a1\"\n                systemctl enable prometheus\n                echo \"\u8bbe\u7f6e\u6210\u5f00\u673a\u81ea\u542f\"\n                systemctl daemon-reload\n                echo \"\u6bcf\u6b21\u66f4\u6539prometheus.service\u90fd\u9700\u8981\u6267\u884c\u4e00\u6b21\uff0c\u91cd\u65b0\u52a0\u8f7d\u4e00\u4e0b\"\n                systemctl start prometheus\n                echo \"\u542f\u52a8prometheus\u670d\u52a1\"\n                systemctl status prometheus &amp;&gt;\/dev\/null\n\t\tif [[ $prometheus_status -eq $old_status ]];then\n                        echo \"\u670d\u52a1install\u6210\u529f,\u8bf7\u901a\u8fc7http:\/\/$ip:9090\u8fdb\u884c\u8bbf\u95ee\uff0c\u7a0b\u5e8f\u9000\u51fa\u3002\u3002\u3002\"\n                        exit\n                else\n                        echo \"\u670d\u52a1\u5b89\u88c5\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u3002\u3002\"\n                        exit\n                fi\n        else\n                echo \"\u76ee\u5f55\u5df2\u5b58\u5728\uff0c\u7a0b\u5e8f\u9000\u51fa\"\n\t\texit\n\tfi\n\t\nfi\n<\/code><\/pre>\n<h2 id=\"installkibana\">install_kibana<\/h2>\n<pre><code class=\"language-shell\" lang=\"shell\">#!\/usr\/bin\/bash\npackage_name=\"kibana-7.14.0-linux-x86_64.tar.gz\"\nelastic_path=\"http:\/\/192.168.98.173:9200\\\",\\\"http:\/\/192.168.98.174:9200\\\",\\\"http:\/\/192.168.98.175:9200\"\nip_addr=`ip addr |grep inet |grep brd |awk '{print $2}' |awk -F '\/' '{print $1}'`\nif [ -e $package_name ];then\n\ttar -zxvf $package_name\n\tmv ${package_name:0:26} \/usr\/local\/kibana\ncat &lt;&lt;EOF &gt;&gt;\/usr\/local\/kibana\/config\/kibana.yml\nserver.port: 5601\nserver.host: \"0.0.0.0\"\nserver.name: \"kibana-elastic\"\nelasticsearch.hosts:\n    [\"$elastic_path\"]\nelasticsearch.requestTimeout: 30000\nEOF\n\ncat &lt;&lt;EOF &gt;&gt;\/usr\/lib\/systemd\/system\/kibana.service\n[Unit]\nDescription=kibana\nAfter=network.target\n\n[Service]\nType=simple\nUser=root\nExecStart=\/usr\/local\/kibana\/bin\/kibana --allow-root\nPrivateTmp=true\n\n[Install]\nWantedBy=multi-user.target\nEOF\nsystemctl daemon-reload\nsystemctl enable kibana.service\nsystemctl restart kibana.service\n\n\n\necho \"\u8bbf\u95ee\u5730\u5740http\/\/$ip_addr:5601\"\necho \"\u8bf7\u901a\u8fc7\u9875\u9762\u4e2d\u7684Stack Monitoring\u67e5\u770b\u96c6\u7fa4\u72b6\u6001\"\nelse\n\techo \"file is not existence\"\nfi\n\n\n\n\n\n\n<\/code><\/pre>\n<h2 id=\"installmongodb\">install_MongoDB<\/h2>\n<pre><code class=\"language-shell\" lang=\"shell\">#!\/usr\/bin\/bash\nrm -rf \/root\/mongodb-linux-x86_64-3.0.0 mongodb-linux-x86_64-3.0.0.tgz \nrm -rf \/usr\/local\/mongodb\ncd $home;\necho \"\u5f00\u59cb\u4e0b\u8f7d\u5b89\u88c5\u5305\"\nwget https:\/\/fastdl.mongodb.org\/linux\/mongodb-linux-x86_64-3.0.0.tgz\ntar tf mongodb-linux-x86_64-3.0.0.tgz\nif [ $? -eq 0  ];then\n\ttar -zxvf mongodb-linux-x86_64-3.0.0.tgz;\n\tif [ ! -d \"\/usr\/local\/mongodb\/\" ];then\n\t\techo \"\u79fb\u52a8\u6587\u4ef6\";\n\t\tmv \/root\/mongodb-linux-x86_64-3.0.0 \/usr\/local\/mongodb;\n\t\tmkdir -p \/usr\/local\/mongodb\/data \/usr\/local\/mongodb\/log;\n\t\t\tif [ $? -eq 0 ];then\n\t\t\t\t\/usr\/local\/mongodb\/bin\/mongod --dbpath=\/usr\/local\/mongodb\/data --logpath=\/usr\/local\/mongodb\/log\/mongodb.log --logappend --port=27017 --fork\n\t\t\t\techo \"\u670d\u52a1\u5df2\u521b\u5efa\"\n\t\t\t\techo \"\u8bf7\u901a\u8fc7\/usr\/local\/mongodb\/bin\/mongo \u8fdb\u884c\u8bbf\u95ee\"\n\t\t\tfi\n\telse\n\t\t\techo \"\u6587\u4ef6\u5df2\u5b58\u5728\"\n\t\t\texit\n\tfi\nelse\n\techo \"\u6587\u4ef6\u635f\u574f\"\n\texit\nfi\n<\/code><\/pre>\n<pre><code class=\"language-shell\" lang=\"shell\">#!\/usr\/bin\/bash\n#\u4e3b\u8981\u5b9e\u73b0\u4ee5\u4e0b\u51e0\u4e2a\u529f\u80fd\u3002\n#1\u3001\u8fdc\u7a0b\u4e3b\u673a\u63a8\u9001\u516c\u94a5\u3002\n#2\u3001\u62f7\u8d1d\u6587\u4ef6\u914d\u7f6emongo.conf\uff0c\u5b8c\u6210\u526f\u672c\u96c6\u7fa4\u7684\u521b\u5efa\n#3\u3001\u914d\u7f6e\u8fdc\u7a0b\u4e3b\u673a\u521d\u59cb\u5316\u526f\u672c\u96c6\u7fa4\u529f\u80fd\u3002\n#\u6ce8\u610f\uff0c\u9700\u8981\u914d\u7f6emongo\u4ece\u8282\u70b9\u53ef\u5199\u72b6\u6001\u9700\u8981\u5728\u4ece\u8282\u70b9\u6267\u884crs.slaveOk()\u547d\u4ee4\u3002\n#\u914d\u7f6e\u7684mongo.conf\u6587\u4ef6\u4e2d\u7f29\u8fdb\u5e94\u4ee5\u56db\u4e2a\u7a7a\u683c\u4e3a\u524d\u63d0\uff0c\u4e8c\u7ea7\u7f29\u8fdb\u516b\u4e2a\u7a7a\u683c\uff0c\u4e0d\u7136\u4f1a\u51fa\u73b0\u914d\u7f6e\u65e0\u6cd5\u542f\u52a8\u670d\u52a1\u62a5yml\u9519\u8bef\u95ee\u9898\n#\u914d\u7f6e\u7684\u6bcf\u4e2a\u4e3b\u673a\u7684\u7aef\u53e3\u4e0d\u4e00\uff0c\u811a\u672c\u6682\u65f6\u4e3a\u8bbe\u7f6eport\u4e3a\u53d8\u91cf\u9700\u8981\u6539\u4e3a\u4e00\u76f4\u53ef\u4ee5\u5168\u5c40\u66ff\u6362\n#expect send \u4e2d\u7684\"\u53f7\u548c:\u53f7\u9700\u8981\u8fdb\u884c\u8f6c\u8bd1\u4e0d\u7136\u4f1a\u51fa\u73b0\u62a5\u9519\u3002\n#\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4ece\u8282\u70b9\u662f\u6ca1\u6709\u8bfb\u5199\u6743\u9650\u7684\uff0c\u53ef\u4ee5\u589e\u52a0\u8bfb\u7684\u6743\u9650\uff0c\u4f46\u9700\u8981\u8fdb\u884c\u8bbe\u7f6e\u3002\n#\u9700\u8981\u767b\u5f55\u4ece\u8282\u70b9\u914d\u7f6e\u4ee5\u4e0b\u53c2\u6570rs.slaveOk()\n#\u6267\u884c\u540e\u67e5\u770b\u6570\u636e\u5e93 show dbs;\u4e0d\u663e\u793a\u62a5\u9519\u8bf4\u660e\u6210\u529f\n#version v1.0 by gyx\nip='\n192.168.98.157\n192.168.98.158\n192.168.98.159\n'\n#\u4e3b\u8282\u70b9ip\nip_1=192.168.98.157\n#\u526f\u672c\u8282\u70b9ip\nip_2=192.168.98.158\n#\u4ef2\u88c1\u8282\u70b9ip\nip_3=192.168.98.159\npassword=123456\n#\u901a\u7528passwd\nmongodb_file_name='mongodb-linux-x86_64-4.0.10.tgz'\n\nfor a in $ip\ndo\n\tping c1 -w1 $a &amp;&gt;\/dev\/null\n\tif [ $? -ne 0 ];then\n\t\techo \"$a \u4e3b\u673a\u4e0d\u901a\"  &gt; ip.txt\n\tfi\ndone\n\n\nfor  i in $ip\ndo\n\/usr\/bin\/expect &lt;&lt;-EOF\nspawn ssh-copy-id $i\nexpect {\n\t\"yes\/no\" { send \"yes\\r\"; exp_continue }\n\t\"password\" { send \"$password\/r\"}\n}\nEOF\ndone\n\nfor j in $ip\ndo\n\techo \"copy fle $i \"\n\tssh root@$j \"\nrm -rf \/root\/$mongodb_file_name\nrm -rf \/usr\/local\/mongodb\"\n\tscp $mongodb_file_name root@$j:\/root\/\nssh root@$j \"tar -zxvf \/root\/$mongodb_file_name \nmv \/root\/mongodb-linux-x86_64-4.0.10 \/usr\/local\/mongodb\n\"\ndone\n#\u521b\u5efa\u4e3b\u8282\u70b9\nssh root@$ip_1 \"\nmkdir -p \/mongodb\/replica_sets\/myrs_27017\/log\nmkdir -p \/mongodb\/replica_sets\/myrs_27017\/data\/db\ncat &lt;&lt;EOF &gt;\/mongodb\/replica_sets\/myrs_27017\/mongod.conf\nsystemLog:\n    #MongoDB\u53d1\u9001\u6240\u6709\u65e5\u5fd7\u8f93\u51fa\u7684\u76ee\u6807\u6307\u5b9a\u4e3a\u6587\u4ef6\n    destination: file\n    #mongod\u6216mongos\u5e94\u5411\u5176\u53d1\u9001\u6240\u6709\u8bca\u65ad\u65e5\u5fd7\u8bb0\u5f55\u4fe1\u606f\u7684\u65e5\u5fd7\u6587\u4ef6\u7684\u8def\u5f84\n    path: \/mongodb\/replica_sets\/myrs_27017\/log\/mongod.log\n    #\u5f53mongos\u6216mongod\u5b9e\u4f8b\u91cd\u65b0\u542f\u52a8\u65f6\uff0cmongos\u6216mongod\u4f1a\u5c06\u65b0\u6761\u76ee\u9644\u52a0\u5230\u73b0\u6709\u65e5\u5fd7\u6587\u4ef6\u7684\u672b\u5c3e\u3002\n    logAppend: true\nstorage:\n    #mongod\u5b9e\u4f8b\u5b58\u50a8\u5176\u6570\u636e\u7684\u76ee\u5f55\u3002storage.dbPath\u8bbe\u7f6e\u4ec5\u9002\u7528\u4e8emongod\u3002\n    dbPath: \/mongodb\/replica_sets\/myrs_27017\/data\/db\n    journal:\n        #\u542f\u7528\u6216\u7981\u7528\u6301\u4e45\u6027\u65e5\u5fd7\u4ee5\u786e\u4fdd\u6570\u636e\u6587\u4ef6\u4fdd\u6301\u6709\u6548\u548c\u53ef\u6062\u590d\u3002\n        enabled: true\nprocessManagement:\n    #\u542f\u7528\u5728\u540e\u53f0\u8fd0\u884cmongos\u6216mongod\u8fdb\u7a0b\u7684\u5b88\u62a4\u8fdb\u7a0b\u6a21\u5f0f\u3002\n    fork: true\n    #\u6307\u5b9a\u7528\u4e8e\u4fdd\u5b58mongos\u6216mongod\u8fdb\u7a0b\u7684\u8fdb\u7a0bID\u7684\u6587\u4ef6\u4f4d\u7f6e\uff0c\u5176\u4e2dmongos\u6216mongod\u5c06\u5199\u5165\u5176PID\n    pidFilePath: \/mongodb\/replica_sets\/myrs_27017\/log\/mongod.pid\nnet:\n    #\u670d\u52a1\u5b9e\u4f8b\u7ed1\u5b9a\u6240\u6709IP\uff0c\u6709\u526f\u4f5c\u7528\uff0c\u526f\u672c\u96c6\u521d\u59cb\u5316\u7684\u65f6\u5019\uff0c\u8282\u70b9\u540d\u5b57\u4f1a\u81ea\u52a8\u8bbe\u7f6e\u4e3a\u672c\u5730\u57df\u540d\uff0c\u800c\u4e0d\u662fip\n    #bindIpAll: true\n    #\u670d\u52a1\u5b9e\u4f8b\u7ed1\u5b9a\u7684IP\n    bindIp: localhost,$ip_1\n    #bindIp\n    #\u7ed1\u5b9a\u7684\u7aef\u53e3\n    port: 27017\nreplication:\n    #\u526f\u672c\u96c6\u7684\u540d\u79f0\n    replSetName: myrs\nEOF\n\/usr\/local\/mongodb\/bin\/mongod -f \/mongodb\/replica_sets\/myrs_27017\/mongod.conf &gt;\/root\/log.txt\ncat &lt;&lt;EOF &gt;\/root\/mongo_start.sh\n#!\/usr\/bin\/bash\n\/usr\/local\/mongodb\/bin\/mongod -f \/mongodb\/replica_sets\/myrs_27017\/mongod.conf \nEOF\n\"\n\n#\u521b\u5efa\u526f\u672c\u8282\u70b9\nssh root@$ip_2 \"\nmkdir -p \/mongodb\/replica_sets\/myrs_27018\/log \nmkdir -p \/mongodb\/replica_sets\/myrs_27018\/data\/db\ncat &lt;&lt;EOF &gt;\/mongodb\/replica_sets\/myrs_27018\/mongod.conf\nsystemLog:\n    #MongoDB\u53d1\u9001\u6240\u6709\u65e5\u5fd7\u8f93\u51fa\u7684\u76ee\u6807\u6307\u5b9a\u4e3a\u6587\u4ef6\n    destination: file\n    #mongod\u6216mongos\u5e94\u5411\u5176\u53d1\u9001\u6240\u6709\u8bca\u65ad\u65e5\u5fd7\u8bb0\u5f55\u4fe1\u606f\u7684\u65e5\u5fd7\u6587\u4ef6\u7684\u8def\u5f84\n    path: \/mongodb\/replica_sets\/myrs_27018\/log\/mongod.log\n    #\u5f53mongos\u6216mongod\u5b9e\u4f8b\u91cd\u65b0\u542f\u52a8\u65f6\uff0cmongos\u6216mongod\u4f1a\u5c06\u65b0\u6761\u76ee\u9644\u52a0\u5230\u73b0\u6709\u65e5\u5fd7\u6587\u4ef6\u7684\u672b\u5c3e\u3002\n    logAppend: true\nstorage:\n    #mongod\u5b9e\u4f8b\u5b58\u50a8\u5176\u6570\u636e\u7684\u76ee\u5f55\u3002storage.dbPath\u8bbe\u7f6e\u4ec5\u9002\u7528\u4e8emongod\u3002\n    dbPath: \/mongodb\/replica_sets\/myrs_27018\/data\/db\n    journal:\n        #\u542f\u7528\u6216\u7981\u7528\u6301\u4e45\u6027\u65e5\u5fd7\u4ee5\u786e\u4fdd\u6570\u636e\u6587\u4ef6\u4fdd\u6301\u6709\u6548\u548c\u53ef\u6062\u590d\u3002\n        enabled: true\nprocessManagement:\n    #\u542f\u7528\u5728\u540e\u53f0\u8fd0\u884cmongos\u6216mongod\u8fdb\u7a0b\u7684\u5b88\u62a4\u8fdb\u7a0b\u6a21\u5f0f\u3002\n    fork: true\n    #\u6307\u5b9a\u7528\u4e8e\u4fdd\u5b58mongos\u6216mongod\u8fdb\u7a0b\u7684\u8fdb\u7a0bID\u7684\u6587\u4ef6\u4f4d\u7f6e\uff0c\u5176\u4e2dmongos\u6216mongod\u5c06\u5199\u5165\u5176PID\n    pidFilePath: \/mongodb\/replica_sets\/myrs_27018\/log\/mongod.pid\nnet:\n    #\u670d\u52a1\u5b9e\u4f8b\u7ed1\u5b9a\u6240\u6709IP\uff0c\u6709\u526f\u4f5c\u7528\uff0c\u526f\u672c\u96c6\u521d\u59cb\u5316\u7684\u65f6\u5019\uff0c\u8282\u70b9\u540d\u5b57\u4f1a\u81ea\u52a8\u8bbe\u7f6e\u4e3a\u672c\u5730\u57df\u540d\uff0c\u800c\u4e0d\u662fip\n    #bindIpAll: true\n    #\u670d\u52a1\u5b9e\u4f8b\u7ed1\u5b9a\u7684IP\n    bindIp: localhost,$ip_2\n    #bindIp\n    #\u7ed1\u5b9a\u7684\u7aef\u53e3\n    port: 27018\nreplication:\n    #\u526f\u672c\u96c6\u7684\u540d\u79f0\n    replSetName: myrs\nEOF\n\/usr\/local\/mongodb\/bin\/mongod -f \/mongodb\/replica_sets\/myrs_27018\/mongod.conf &gt;\/root\/log.txt\ncat &lt;&lt;EOF &gt;\/root\/mongo_start.sh\n#!\/usr\/bin\/bash\n\/usr\/local\/mongodb\/bin\/mongod -f \/mongodb\/replica_sets\/myrs_27018\/mongod.conf \nEOF\n\"\n\n\n#\u521b\u5efa\u4ef2\u88c1\u8282\u70b9\nssh root@$ip_3 \"\nmkdir -p \/mongodb\/replica_sets\/myrs_27019\/log\nmkdir -p \/mongodb\/replica_sets\/myrs_27019\/data\/db\ncat &lt;&lt;EOF &gt;\/mongodb\/replica_sets\/myrs_27019\/mongod.conf\nsystemLog:\n    #MongoDB\u53d1\u9001\u6240\u6709\u65e5\u5fd7\u8f93\u51fa\u7684\u76ee\u6807\u6307\u5b9a\u4e3a\u6587\u4ef6\n    destination: file\n    #mongod\u6216mongos\u5e94\u5411\u5176\u53d1\u9001\u6240\u6709\u8bca\u65ad\u65e5\u5fd7\u8bb0\u5f55\u4fe1\u606f\u7684\u65e5\u5fd7\u6587\u4ef6\u7684\u8def\u5f84\n    path: \/mongodb\/replica_sets\/myrs_27019\/log\/mongod.log\n    #\u5f53mongos\u6216mongod\u5b9e\u4f8b\u91cd\u65b0\u542f\u52a8\u65f6\uff0cmongos\u6216mongod\u4f1a\u5c06\u65b0\u6761\u76ee\u9644\u52a0\u5230\u73b0\u6709\u65e5\u5fd7\u6587\u4ef6\u7684\u672b\u5c3e\u3002\n    logAppend: true\nstorage:\n    #mongod\u5b9e\u4f8b\u5b58\u50a8\u5176\u6570\u636e\u7684\u76ee\u5f55\u3002storage.dbPath\u8bbe\u7f6e\u4ec5\u9002\u7528\u4e8emongod\u3002\n    dbPath: \/mongodb\/replica_sets\/myrs_27019\/data\/db\n    journal:\n    #\u542f\u7528\u6216\u7981\u7528\u6301\u4e45\u6027\u65e5\u5fd7\u4ee5\u786e\u4fdd\u6570\u636e\u6587\u4ef6\u4fdd\u6301\u6709\u6548\u548c\u53ef\u6062\u590d\u3002\n        enabled: true\nprocessManagement:\n    #\u542f\u7528\u5728\u540e\u53f0\u8fd0\u884cmongos\u6216mongod\u8fdb\u7a0b\u7684\u5b88\u62a4\u8fdb\u7a0b\u6a21\u5f0f\u3002\n    fork: true\n    #\u6307\u5b9a\u7528\u4e8e\u4fdd\u5b58mongos\u6216mongod\u8fdb\u7a0b\u7684\u8fdb\u7a0bID\u7684\u6587\u4ef6\u4f4d\u7f6e\uff0c\u5176\u4e2dmongos\u6216mongod\u5c06\u5199\u5165\u5176PID\n    pidFilePath: \/mongodb\/replica_sets\/myrs_27019\/log\/mongod.pid\nnet:\n    #\u670d\u52a1\u5b9e\u4f8b\u7ed1\u5b9a\u6240\u6709IP\uff0c\u6709\u526f\u4f5c\u7528\uff0c\u526f\u672c\u96c6\u521d\u59cb\u5316\u7684\u65f6\u5019\uff0c\u8282\u70b9\u540d\u5b57\u4f1a\u81ea\u52a8\u8bbe\u7f6e\u4e3a\u672c\u5730\u57df\u540d\uff0c\u800c\u4e0d\u662fip\n    #bindIpAll: true\n    #\u670d\u52a1\u5b9e\u4f8b\u7ed1\u5b9a\u7684IP\n    bindIp: localhost,$ip_3\n    #bindIp\n    #\u7ed1\u5b9a\u7684\u7aef\u53e3\n    port: 27019\nreplication:\n    #\u526f\u672c\u96c6\u7684\u540d\u79f0\n    replSetName: myrs\nEOF\n\/usr\/local\/mongodb\/bin\/mongod -f \/mongodb\/replica_sets\/myrs_27019\/mongod.conf &gt;\/root\/log.txt\ncat &lt;&lt;EOF &gt;\/root\/mongo_start.sh\n#!\/usr\/bin\/bash\n\/usr\/local\/mongodb\/bin\/mongod -f \/mongodb\/replica_sets\/myrs_27019\/mongod.conf\nEOF\n\"\n#\u68c0\u67e5\u670d\u52a1\nfor  g in $ip\ndo\n\tssh root@$g ps -ef|grep mongo\n\tif [ $? -eq 0 ];then\n\t\techo \" $g install success\"\n\telse\n\t\techo \"$g install fail\"\n\t\techo \"\u670d\u52a1\u672a\u542f\u52a8\u6210\u529f\u811a\u672c\u5c06\u65e0\u6cd5\u914d\u7f6emongo\u526f\u672c\u6a21\u5f0f\u3002\u7a0b\u5e8f\u9000\u51fa\u3002\u3002\u3002\"\n\t\texit\n\tfi\ndone\n\n#\u81ea\u52a8\u914d\u7f6e\u526f\u672c\u96c6\u6a21\u5f0f\n#\"rs.initiate()\" \u8282\u70b9\u521d\u59cb\u5316\n#rs.add(\\\"192.168.98.158\\:27018\\\" \u589e\u52a0\u526f\u672c\u8282\u70b9\n#rs.addArb(\\\"192.168.98.159\\:27019\\\") \u589e\u52a0\u4ef2\u88c1\u8282\u70b9\n\/usr\/bin\/expect &lt;&lt;-EOF  \n        spawn ssh root@$ip_1\n        expect \"#*\"\n        send \"\/usr\/local\/mongodb\/bin\/mongo --host=$ip_1 --port=27017 \\n\"\n        expect \"#*\"\n        send \"rs.initiate() \\n\"\n        expect \"#*\"\n        send \"rs.add(\\\"$ip_2\\:27018\\\") \\n\"\n        expect \"#*\"\n        send \"rs.addArb(\\\"$ip_3\\:27019\\\") \\n\"\n        expect \"#*\"\n        send \"exit \\n\"\n        expect eof\nEOF\n\necho \"\u8fdb\u5165mongo\u4e3b\u8282\u70b9\u8f93\u5165rs.status() \u5728\u914d\u7f6e\u6709\u521a\u624d\u914d\u7f6e\u7684\u4e09\u4e2aip\u53ca\u526f\u672c\u521b\u5efa\u6210\u529f\"\necho \"\u767b\u5f55\u547d\u4ee4\u53c2\u7167    \/usr\/local\/mongodb\/bin\/mongo --host=$ip_1 --port=27017\"\n<\/code><\/pre>\n<h2 id=\"installzookeeperkafka\">install_zookeeper_kafka<\/h2>\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=\"\n192.168.98.170\n192.168.98.171\n192.168.98.172\n\"\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=\"zookeeper.connect\\=192.168.98.170:2181,192.168.98.171:2181,192.168.98.172:2181\"\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=\"export JAVA_HOME=\\\/usr\\\/lib\\\/jvm\\\/java-1.8.0-openjdk-1.8.0.292.b10-1.el7_9.x86_64\"\nexp2=\"export CLASSPATH=.:\\$JAVA_HOME\\\/jre\\\/lib\\\/rt.jar:\\$JAVA_HOME\\\/lib\\\/dt.jar:\\$JAVA_HOME\\\/lib\\\/tools.jar\"\nexp3=\"export PATH=\\$PATH:\\$JAVA_HOME\\\/bin\"\nl1=\"unset i\"\necho \"############################1\u3001\u914d\u7f6e\u670d\u52a1\u5668\u5bc6\u94a5############################\"\nfor a in $ip\ndo\n\/usr\/bin\/expect &lt;&lt;EOF\nspawn  ssh-copy-id $a\nexpect {\n\"yes\/no\" { send \"yes\\r\"; exp_continue }\n\"*password\" { send \"$passwd\\n\"; exp_continue }\n{ send \"\\n\"}\n}\nEOF\ndone\n\n\necho \"############################2\u3001\u62f7\u8d1dkafka\u5b89\u88c5\u5305############################\"\nfor i  in $ip\ndo\n\tscp kafka_2.12-2.8.0.tgz tmp.txt  root@$i:\/tmp\/\ndone\nwait;\necho \"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\"\necho \"############################3\u3001\u914d\u7f6ejdk\u3001\u53ca\u670d\u52a1\u53d8\u91cf############################\"\nfor j in $ip\ndo  \n\tssh root@$j \"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 \"\/^broker.id\\=0\/cbroker.id\\=$g\" \/usr\/local\/kafka\/config\/server.properties\nsed -ir \"\/^zookeeper.connect\\=\/c$config\" \/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 '\/unset i\/i$exp1' \/etc\/profile\nsed -ri '\/unset i\/i$exp2' \/etc\/profile\nsed -ri '\/unset i\/i$exp3' \/etc\/profile\nsource \/etc\/profile\n\"\nlet ++p\nlet ++g\ndone\nwait\necho \"\u542f\u52a8\u4efb\u52a1\u5e76\u8bbe\u7f6e\u4e3a\u540e\u53f0\u8fdb\u7a0b\"\necho \"############################4\u3001\u914d\u7f6e\u670d\u52a1\u5f00\u673a\u81ea\u542f############################\"\nfor kk in $ip\ndo\n        {\n        ssh root@$kk \" \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\"\n        }&amp;\ndone\n\necho \"\u670d\u52a1\u542f\u52a8\u5b8c\u6bd5\uff0c\u8bf7\u81ea\u68c0 systemctl status zookeeper\"\necho \"\u670d\u52a1\u542f\u52a8\u5b8c\u6bd5\uff0c\u8bf7\u81ea\u68c0 systemctl status kafka\"\necho \"\u521b\u5efatopic\uff0c\u67e5\u770b\u662f\u5426\u53ef\u4ee5\u521b\u5efa\u6210\u529f\"\necho \"\/usr\/local\/kafka\/bin\/kafka-topics.sh --create --topic quickstart-events --bootstrap-server localhost:9092\"\necho \"\u663e\u793atopic\uff0c\u663e\u793aLeader,\u663e\u793aReplicas,\u663e\u793aIsr\"\necho \"\/usr\/local\/kafka\/bin\/kafka-topics.sh --describe --topic quickstart-events --bootstrap-server localhost:9092\"\necho \"\u521b\u5efa\u751f\u4ea7\u8005,\u751f\u4ea7\u6570\u636e\"\necho \"\/usr\/local\/kafka\/bin\/kafka-console-producer.sh --topic quickstart-events --bootstrap-server localhost:9092\"\necho \"\u521b\u5efa\u6d88\u8d39\u8005\uff0c\u8bfb\u53d6\u751f\u4ea7\u8005\u6570\u636e\"\necho \"\/usr\/local\/kafka\/bin\/kafka-console-consumer.sh --topic quickstart-events --from-beginning --bootstrap-server localhost:9092\"\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>shell\u811a\u672c-install shell\u811a\u672c-install install_elasticsearch # [&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-41","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=\/wp\/v2\/posts\/41","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=41"}],"version-history":[{"count":0,"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=\/wp\/v2\/posts\/41\/revisions"}],"wp:attachment":[{"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=41"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=41"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=41"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}