{"id":11085,"date":"2022-11-08T14:52:32","date_gmt":"2022-11-08T06:52:32","guid":{"rendered":"https:\/\/www.lwops.cn\/?p=11085"},"modified":"2022-11-10T15:03:14","modified_gmt":"2022-11-10T07:03:14","slug":"prometheus%e6%8a%80%e6%9c%af%e5%88%86%e4%ba%ab-prometheus%e9%80%9a%e8%bf%87nginx%e5%8a%a0%e5%af%86%e7%99%bb%e9%99%86","status":"publish","type":"post","link":"https:\/\/www.lwops.cn\/index.php\/prometheus\/prometheus-artisan\/11085","title":{"rendered":"Prometheus\u6280\u672f\u5206\u4eab\u2014\u2014Prometheus\u901a\u8fc7Nginx\u52a0\u5bc6\u767b\u9646"},"content":{"rendered":"\n
\u6700\u8fd1\u7ecf\u5e38\u6709\u5c0f\u4f19\u4f34\u95ee\u4e50\u7ef4\u541b\u4e00\u4e2a\u95ee\u9898\uff0cprometheus\u5982\u4f55\u52a0\u5bc6\u767b\u5f55\uff0c\u672c\u8eabPrometheus\u9ed8\u8ba4\u5f00\u7bb1\u5373\u98df\uff0c\u5e76\u6ca1\u6709\u8bbe\u7f6e\u8ba4\u8bc1\u65b9\u5f0f\uff0c\u5982\u679c\u4f60\u4f7f\u7528Grafana\u90a3\u5c31\u53e6\u5f53\u522b\u8bba\u3002 \u5982\u679c\u4f60\u60f3\u76f4\u63a5\u8bbf\u95eePrometheus\u5e76\u4e14\u9700\u8981\u8bbe\u7f6e\u4e2a\u8ba4\u8bc1\uff0c\u90a3\u4e48\u901a\u8fc7Nginx\u53cd\u5411\u4ee3\u7406\u662f\u4e00\u4e2a\u4e0d\u9519\u7684\u9009\u62e9\u3002 \u672c\u6587\u4e50\u7ef4\u541b<\/a>\u5c06\u4ecb\u7ecd\u901a\u8fc7Nginx\u53cd\u5411\u4ee3\u7406\u589e\u52a0401\u8ba4\u8bc1\u65b9\u5f0f\u6765\u5b9e\u73b0\u52a0\u5bc6\u767b\u5f55\u3002<\/p>\n\n\n\n \u5176\u4e2dserver_name 192.168.1.191\u4e3a\u672c\u673aIP\uff0c\u53ef\u6839\u636e\u4e2a\u4eba\u4f7f\u7528\u60c5\u51b5\u81ea\u884c\u9009\u62e9<\/p>\n\n\n\n1\u3001\u5b89\u88c5Nginx<\/h2>\n\n\n\n
\u5b89\u88c5Nginx\u65b9\u5f0f\u591a\u79cd\uff0c\u6211\u8fd9\u91cc\u4ee5whsir\u4e00\u952e\u5305\u4e3a\u4f8b\nrpm -ivh http:\/\/mirrors.whsir.com\/centos\/whsir-release-centos.noarch.rpm\nyum install wnginx<\/code><\/pre>\n\n\n\n
2\u3001\u5b89\u88c5apache-htpasswd\u5de5\u5177<\/h2>\n\n\n\n
yum -y install httpd-tools<\/code><\/pre>\n\n\n\n
3\u3001\u52a0\u5bc6\u8ba4\u8bc1\u5bc6\u7801<\/h2>\n\n\n\n
\u8fd9\u91cc\u8d26\u53f7\u662fwhsir\uff0c\u5bf9\u5bc6\u7801\u52a0\u5bc6\nhtpasswd -cs \/usr\/local\/nginx\/conf\/401htpasswd whsir<\/code><\/pre>\n\n\n\n
4\u3001\u8bbe\u7f6eNginx\u53cd\u5411\u4ee3\u7406\u53ca401\u8ba4\u8bc1<\/h2>\n\n\n\n
cd \/usr\/local\/nginx\/conf\/vhost\nrm -f demo.conf\nvi demo.conf\nserver {\n listen 80;\n server_name 192.168.1.191;\n\n location \/ {\n auth_basic \"Prometheus\";\n auth_basic_user_file \/usr\/local\/nginx\/conf\/401htpasswd;\n proxy_pass http:\/\/localhost:9090\/;\n }\n}<\/code><\/pre>\n\n\n\n
5\u3001\u542f\u52a8Nginx\u9a8c\u8bc1<\/h2>\n\n\n\n
\/etc\/init.d\/nginx start\n\u8bbf\u95eehttp:\/\/192.168.1.191\n\u6b63\u5e38\u8f93\u5165\u5bc6\u7801\u540e\uff0c\u4f1a\u770b\u5230Prometheus\u9875\u9762\uff0c\u5982\u679c\u63d0\u793a403\u5219\u8868\u793a\u8d26\u53f7\u5bc6\u7801\u4e0d\u6b63\u786e\uff0c\u6216\u8005\u8def\u5f84\u914d\u9519\u3002<\/code><\/pre>\n\n\n\n