{"id":51,"date":"2023-07-20T10:36:34","date_gmt":"2023-07-20T02:36:34","guid":{"rendered":"https:\/\/guoyingxu.cn\/?p=51"},"modified":"2023-07-20T10:36:34","modified_gmt":"2023-07-20T02:36:34","slug":"install_prometheus","status":"publish","type":"post","link":"https:\/\/guoyingxu.cn\/?p=51","title":{"rendered":"install_prometheus"},"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='installprometheus'>install_prometheus<\/h2>\n<pre><code class='language-shell' lang='shell'>#!\/usr\/bin\/bash\nurl=&quot;&quot;\nip=`ip addr |grep inet |grep brd |awk &#39;{print $2}&#39; |awk -F &#39;\/&#39; &#39;{print $1}&#39;`\nprometheus_status=`systemctl status prometheus |grep Active |awk  &#39;{print $3}&#39; `\nold_status=&quot;(running)&quot;\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 &quot;\u79fb\u52a8\u6587\u4ef6&quot;\n\t\tmv prometheus-2.28.1.linux-amd64 \/usr\/local\/prometheus\n\t\techo &quot;\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u7684localhost\u4e3a\u672c\u673a$ip&quot;\n\t\tsed -ir &quot;s\/localhost\/$ip\/&quot; \/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 &quot;\u521b\u5efa\u7cfb\u7edf\u670d\u52a1&quot;\n\t\tsystemctl enable prometheus \n\t\techo &quot;\u8bbe\u7f6e\u6210\u5f00\u673a\u81ea\u542f&quot;\n\t\tsystemctl daemon-reload \n\t\techo &quot;\u6bcf\u6b21\u66f4\u6539prometheus.service\u90fd\u9700\u8981\u6267\u884c\u4e00\u6b21\uff0c\u91cd\u65b0\u52a0\u8f7d\u4e00\u4e0b&quot;\n\t\tsystemctl start prometheus\n\t\techo &quot;\u542f\u52a8prometheus\u670d\u52a1&quot;\n\t\tsystemctl status prometheus &amp;&gt;\/dev\/null\n\t\tif [[ $prometheus_status -eq $old_status ]];then\n\t\t\techo &quot;\u670d\u52a1install\u6210\u529f,\u8bf7\u901a\u8fc7http:\/\/$ip:9090\u8fdb\u884c\u8bbf\u95ee\uff0c\u7a0b\u5e8f\u9000\u51fa\u3002\u3002\u3002&quot;\n\t\t\texit\n\t\telse\n\t\t\techo &quot;\u670d\u52a1\u5b89\u88c5\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u3002\u3002&quot;\n\t\t\texit\n\t\tfi\n\telse\n\t\techo &quot;\u76ee\u5f55\u5df2\u5b58\u5728\uff0c\u7a0b\u5e8f\u9000\u51fa&quot;\n\t\texit\n\tfi\n\nelse\n\techo &quot;\u5f53\u524d\u76ee\u5f55\u4e0d\u5b58\u5728\u5b89\u88c5\u5305\uff0c\u5c06\u8981\u5f00\u59cb\u4e0b\u8f7d\u5b89\u88c5\u5305&quot;\n\twget $url\n        tar -zxvf prometheus-2.28.1.linux-amd64.tar.gz\n        if [ ! -d \/usr\/local\/prometheus ];then\n                echo &quot;\u79fb\u52a8\u6587\u4ef6&quot;\n                mv prometheus-2.28.1.linux-amd64 \/usr\/local\/prometheus\n                echo &quot;\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\u7684localhost\u4e3a\u672c\u673a$ip&quot;\n                sed -ir &quot;s\/localhost\/$ip\/&quot; \/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 &quot;\u521b\u5efa\u7cfb\u7edf\u670d\u52a1&quot;\n                systemctl enable prometheus\n                echo &quot;\u8bbe\u7f6e\u6210\u5f00\u673a\u81ea\u542f&quot;\n                systemctl daemon-reload\n                echo &quot;\u6bcf\u6b21\u66f4\u6539prometheus.service\u90fd\u9700\u8981\u6267\u884c\u4e00\u6b21\uff0c\u91cd\u65b0\u52a0\u8f7d\u4e00\u4e0b&quot;\n                systemctl start prometheus\n                echo &quot;\u542f\u52a8prometheus\u670d\u52a1&quot;\n                systemctl status prometheus &amp;&gt;\/dev\/null\n\t\tif [[ $prometheus_status -eq $old_status ]];then\n                        echo &quot;\u670d\u52a1install\u6210\u529f,\u8bf7\u901a\u8fc7http:\/\/$ip:9090\u8fdb\u884c\u8bbf\u95ee\uff0c\u7a0b\u5e8f\u9000\u51fa\u3002\u3002\u3002&quot;\n                        exit\n                else\n                        echo &quot;\u670d\u52a1\u5b89\u88c5\u5931\u8d25\uff0c\u8bf7\u68c0\u67e5\u3002\u3002&quot;\n                        exit\n                fi\n        else\n                echo &quot;\u76ee\u5f55\u5df2\u5b58\u5728\uff0c\u7a0b\u5e8f\u9000\u51fa&quot;\n\t\texit\n\tfi\n\t\nfi\n<\/code><\/pre>\n<\/body>\n<\/html>\n","protected":false},"excerpt":{"rendered":"<p>install_prometheus #!\/usr\/bin\/bash url=&quot;&quot; ip= [&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-51","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=\/wp\/v2\/posts\/51","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=51"}],"version-history":[{"count":0,"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=\/wp\/v2\/posts\/51\/revisions"}],"wp:attachment":[{"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=51"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=51"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/guoyingxu.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=51"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}