{"id":44,"date":"2023-07-20T10:27:27","date_gmt":"2023-07-20T02:27:27","guid":{"rendered":"https:\/\/guoyingxu.cn\/?p=44"},"modified":"2023-07-20T10:27:27","modified_gmt":"2023-07-20T02:27:27","slug":"install_elasticsearch","status":"publish","type":"post","link":"https:\/\/guoyingxu.cn\/?p=44","title":{"rendered":"install_elasticsearch"},"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><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=&quot;\n192.168.98.173 123456\n192.168.98.174 123456\n192.168.98.175 123456\n&quot;\n#\u5b9a\u4e49hosts\u540d\u79f0\nname=&quot;elastic&quot;\n#\u5b9a\u4e49\u5b89\u88c5\u5305\u540d\u79f0\nelasticsearch_package_name=&quot;elasticsearch-7.14.0-linux-x86_64.tar.gz&quot;\n#\u521b\u5efa\u7684elastic\u7528\u6237\nuser=&quot;elastic&quot;\n#\u521b\u5efa\u7684elastic\u7528\u6237\u5bc6\u7801\npass=&quot;1234567&quot;\n#\u5b9a\u4e49elastic\u7684\u65e5\u5fd7\u548c\u6570\u636e\u5b58\u50a8\u8def\u5f84\npath_data=&quot;\/opt\/data&quot;\npath_log=&quot;\/opt\/log&quot;\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=&quot;\/opt&quot;\n#--------------------------------------------------------------------------------------#\n#--------------------------------------------------------------------------------------#\nnode_id=&quot;1&quot;\n\nIFS=&#39;\n&#39;\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 &quot;$line&quot; |awk &#39;{print $1}&#39;`\n\tpasswd=`echo &quot;$line&quot; |awk &#39;{print $2}&#39;`\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&quot;yes\/no&quot; { send &quot;yes\\r&quot; ; exp_continue }\n&quot;password&quot; { send &quot;$passwd\\r&quot; ; exp_continue }\n&quot;*#&quot; { send &quot;\\r&quot;}\n}\nEOF\n\telse\n\t echo &quot;$ip&quot;| tee -a fail_ip.txt\n\tfi\ndone\nwait\necho &quot;1\u3001ssh-copy-id  is ok!&quot;\n\nIFS=&#39;\n&#39;\n#\u4fee\u6539\u4e3b\u673ahosts\u548chostname\nfor e_host in $ip_addr\ndo\n\tip=`echo &quot;$e_host&quot; |awk &#39;{print $1}&#39;`\n\tnet_addr=`ssh root@$ip &quot; ip addr |egrep &#39;\\&lt;inet\\&gt;&#39;|grep -v &#39;127.0.0.1&#39;|awk &#39;{print \\\\$2}&#39;|awk -F&#39;\/&#39; &#39;{print \\\\$1}&#39; &quot;`\n\tssh root@$ip &quot; echo &quot;$name-$net_addr&quot; &gt; \/etc\/hostname &quot;\n\tgg=`ssh root@$ip &quot; cat \/etc\/hostname &quot;`\n\tssh root@$ip &quot; echo &quot;$net_addr $gg&quot; &gt;&gt; \/etc\/hosts &quot;\n\ndone\nwait\n#\u62f7\u8d1d\u5b89\u88c5\u5305\nIFS=&#39;\n&#39;\nfor a_copy in $ip_addr\ndo\n\tip=`echo &quot;$a_copy&quot; |awk &#39;{print $1}&#39;`\n\tel_ip[++j]=`echo &quot;$a_copy&quot;|awk &#39;{print $1}&#39;`\n\tscp $elasticsearch_package_name  root@$ip:\/tmp\/\n\tssh root@$ip &quot; if [ -e &quot;\/tmp\/$elasticsearch_package_name&quot; ];then echo &quot;$ip File copy complete&quot; ; else echo &quot;$ip File copy failed&quot; exit ; fi &quot;\ndone\nwait\n#\u83b7\u53d6ip\u4f20\u9012\u7ed9\u6570\u7ec4\nfor hq_ip in ${!el_ip[@]}\ndo\n\t#echo &quot;${el_ip[hq_ip]}&quot;\n\techo &quot;ipaddr&quot;\ndone\n\n#\u914d\u7f6eelastic\nIFS=&#39;\n&#39;\nfor c_con in $ip_addr\ndo\n\tip=`echo &quot;$c_con&quot; |awk &#39;{print $1}&#39;`\n\t\n\tssh root@$ip &quot; cd \/tmp\ntar -zxvf $elasticsearch_package_name \nmv elasticsearch-7.14.0 \/usr\/local\/elasticsearch\nuseradd $user ; echo &quot;$pass&quot; |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: [&quot;${el_ip[1]}&quot;, &quot;${el_ip[2]}&quot;,&quot;${el_ip[3]}&quot;]\ncluster.initial_master_nodes: [&quot;node-1&quot;, &quot;node-2&quot;,&quot;node-3&quot;]\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&quot;\nlet ++node_id\ndone\n\nsleep 1m\n#\u91cd\u542f\u670d\u52a1\u5668\u662flimit\u914d\u7f6e\u53e5\u67c4\u751f\u6548\nIFS=&#39;\n&#39;\nfor d_res in $ip_addr\ndo\n\techo -n &quot;$ip \u7cfb\u7edf\u53e5\u67c4\u4e3a&quot;\n\tip=`echo &quot;$d_res&quot; |awk &#39;{print $1}&#39;`\n\tssh root@$ip &quot;ulimit -Hu&quot;\n\techo -n &quot;$i \u72b6\u6001\u4e3a&quot;\n        ssh root@$ip &quot; systemctl status elasticsearch.service|grep Active&quot;\n\n\ndone\nwait\necho &quot;\u8bf7\u901a\u8fc7\u4ee5\u4e0b\u94fe\u63a5\u67e5\u770b\u670d\u52a1\u96c6\u7fa4\u662f\u5426\u642d\u5efa\u5b8c\u6210&quot; \necho &quot;http:\/\/${el_ip[1]}:9200\/_cat\/health?v&quot;\n<\/code><\/pre>\n<\/body>\n<\/html>\n","protected":false},"excerpt":{"rendered":"","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-44","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=\/wp\/v2\/posts\/44","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=44"}],"version-history":[{"count":0,"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=\/wp\/v2\/posts\/44\/revisions"}],"wp:attachment":[{"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=44"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=44"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=44"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}