您的位置: 首页 - 站长

php可以做移动端网站成都建站免费模板

当前位置: 首页 > news >正文

php可以做移动端网站,成都建站免费模板,网站开发访客ip,银川建网站那家好目录 promtool检查语法 部署Prometheus Server 检查语法是否规范 部署node-exporter 部署Consul 直接请求API进行服务注册 使用register命令注册服务#xff08;建议使用#xff09; 单个和多个注册#xff0c;多个后面多加了s 在Prometheus上做consul的服务发现 部署… 目录 promtool检查语法 部署Prometheus Server 检查语法是否规范 部署node-exporter 部署Consul 直接请求API进行服务注册 使用register命令注册服务建议使用 单个和多个注册多个后面多加了s 在Prometheus上做consul的服务发现 部署Consul Exporter 在Prometheus上做Consul Exporter的服务发现 因为Prometheus是对Consul做的服务发现所以 部署MySQL Exporter 在Prometheus上做Consul Exporter的服务发现 部署nginx Exporter 在Prometheus上做Consul Exporter的服务发现 在Prometheus上做tomcat tomcat允许远程登录 tomcat下载及扩充支持相应的功能 注册到consul上面去及Prometheus上做服务发现 署Blackbox Exporter 取决于黑盒监控 在Prometheus里面做黑河发现  Record Rule: 保存在配置文件中由Prometheus Server周期去评估结果会生成一个时序数据回存至TSDB并支持查询  Alert Rule: 布尔型告警表达式保存在配置文件中由Prometheus Server周期去评估结果会生成一个时序数据服务状态转换时即会生成告警 布尔型告警表达式监控指标的值或其他相关条件来判断系统是否处于异常状态并触发相应的告警。 record 记录规则 当Prometheus里面用promQL写的规则执行文件执行完成时如果恰巧是grafana所需要的文件就会直接在这里读取而不是再从TSDB里面重新读取从而省去大量IO 查询持久化     把查询语句的执行结果长期保存  记录规则保存于配置文件由Server自动在后台周期性执行      evaluation_interval: 15s  promtool检查语法 ./promtool check config prometheus.yml    #  promtool 可以用这命令检查语法 /usr/local/consul services register server02.json   注册consul的发现表 /usr/local/consul services dederegister -id server02.json  注销consul的发现表 https://prometheus.io/download/ 官网部署Prometheus Server 下载程序包以2.40.2版为例 curl -LO https://github.com/prometheus/prometheus/releases/download/v2.40.2/prometheus-2.40.2.linux-amd64.tar.gz 展开程序包 tar xf prometheus-2.40.2.linux-amd64.tar.gz -C /usr/local/ ln -sv /usr/local/prometheus-2.40.2.linux-amd64 /usr/local/prometheus 创建用户并设定目录权限 useradd -r prometheus mkdir /usr/local/prometheus/data chown -R prometheus.prometheus /usr/local/prometheus/data 创建Systemd Unitfile保存于/usr/lib/systemd/system/prometheus.service文件中: [Unit] DescriptionMonitoring system and time series database Documentationhttps://prometheus.io/docs/introduction/overview/[Service] Restartalways Userprometheus EnvironmentFile-/etc/default/prometheus ExecStart/usr/local/prometheus/prometheus --config.file/usr/local/prometheus/prometheus.yml --storage.tsdb.path/usr/local/prometheus/data --web.console.libraries/usr/share/prometheus/console_libraries --web.enable-lifecycle $ARGS ExecReload/bin/kill -HUP $MAINPID TimeoutStopSec20s SendSIGKILLno LimitNOFILE8192[Install] WantedBymulti-user.target如有必要可创建环境配置文件/etc/default/prometheus通过变量ARGS为prometheus指定启动参数 启动服务 systemctl daemon-reload systemctl start prometheus.service systemctl enable prometheus.service 验证监听的端口并测试访问其暴露的指标 ss -tnlp | grep 9090 curl localhost:9090/metrics 修改配置后的重载命令 curl -XPOST http://localhost:9090/-/reload 基于文件的服务发现 [rootrocky8 prometheus]#mkdir targets [rootrocky8 targets]#vim nodes-linux.yml #以yml结尾就行后续容易在Prometheus里面指定

  • targets: #可以名字- 10.0.0.18:9100 - 10.0.0.8:9100labels: #标签。可以多个app: nede-exporter[rootrocky8 prometheus]#vim prometheus.yml- job_name: node_exportermetrics_path: /metrics #默认定义的输出路径scheme: httpfile_sd_configs: #基于文件发现- files:- targets/nodes-*.yml #可以通配符refresh_interval: 2m curl -XPOST http://localhost:9090/-/reload 定义完成之后可以重启 检查语法是否规范 [rootrocky8 prometheus]#./promtool check config ./prometheus.yml   可以检查语法是否规范 部署node-exporter 提示每个主机节点上均应该部署node-exporter 下载程序包以1.4.0版本为例 curl -LO https://github.com/prometheus/node_exporter/releases/download/v1.4.0/node_exporter-1.4.0.linux-amd64.tar.gz 展开程序包 tar xf node_exporter-1.4.0.linux-amd64.tar.gz -C /usr/local/ ln -sv /usr/local/node_exporter-1.4.0.linux-amd64 /usr/local/node_exporter 创建用户若prometheus用户已经存在可略过该步骤 useradd -r prometheus 创建Systemd Unitfile保存于/usr/lib/systemd/system/node_exporter.service文件中: [Unit] Descriptionnode_exporter Documentationhttps://prometheus.io/docs/introduction/overview/ Afternetwork.target[Service] Typesimple Userprometheus ExecStart/usr/local/node_exporter/node_exporter --collector.ntp --collector.mountstats --collector.systemd --collector.ethtool --collector.tcpstat ExecReload/bin/kill -HUP \(MAINPID TimeoutStopSec20s Restartalways[Install] WantedBymulti-user.target启动服务 systemctl daemon-reload systemctl start node_exporter.service systemctl enable node_exporter.service 验证监听的端口并测试访问其暴露的指标 ss -tnlp | grep 9100 curl localhost:9100/metrics 部署Consul 组件功能用于为Prometheus提供基于Consul进行服务发现的测试环境。 部署 下载Consul以1.14.1版本为例 curl -LO https://releases.hashicorp.com/consul/1.14.1/consul_1.14.1_linux_amd64.zip 展开程序包 mkdir -p /usr/local/consul/{data,config} #给consul 保存配置文件和数据的目录 unzip consul_1.14.1_linux_amd64.zip -d /usr/local/consul 创建用户若consul用户已经存在可略过该步骤 useradd -r consul chown consul.consul /usr/local/consul/{data,config} 创建Systemd Unitfile保存于/usr/lib/systemd/system/consul.service文件中: [Unit] DescriptionHashiCorp Consul - A service mesh solution Documentationhttps://www.consul.io/ Requiresnetwork-online.target Afternetwork-online.target[Service] EnvironmentFile-/etc/consul.d/consul.env Userconsul Groupconsul ExecStart/usr/local/consul/consul agent -dev -bootstrap \-config-dir /usr/local/consul/config \-data-dir /usr/local/consul/data \-ui \-log-level INFO \-bind 127.0.0.1 \-client 0.0.0.0 ExecReload/bin/kill --signal HUP \)MAINPID KillModeprocess KillSignalSIGTERM Restarton-failure LimitNOFILE65536[Install] WantedBymulti-user.target启动服务 systemctl daemon-reload systemctl start consul.service systemctl enable consul.service #开机自动 直接请求API进行服务注册 列出已经注册的服务 curl -XGET http://localhost:8500/v1/agent/services获取某个特定服务的配置信息 curl -XGET http://localhost:8500/v1/agent/service/SERVICE_ID例如下面定义了一个要注册的tomcat服务示例它保存于tomcat.json文件中 {id: tomcat,name: tomcat,address: tomcat,port: 8080,tags: [tomcat],checks: [{http: http://tomcat:8080/metrics,interval: 5s}] }我们可以使用类似如下命令完成服务注册。 curl -XPUT –data tomcat.json http://localhost:8500/v1/agent/service/register注销某个服务 curl -XPUT http://localhost:8500/v1/agent/service/deregister/SERVICE_ID使用register命令注册服务建议使用 单个和多个注册多个后面多加了s consul services register命令也可用于进行服务注册只是其使用的配置格式与直接请求HTTP API有所不同。 -addressXXX 指明服务器地址不指默认本地 -portxx   指定服务的端口号 consul services register /path/to/pyload_file.json注册单个服务时使用service进行定义注册多个服务时使用services以列表格式进行定义。下面的示例定义了单个要注册的服务。 {service: {id: tomcat,name: tomcat,address: tomcat,port: 8080,tags: [tomcat],checks: [{http: http://tomcat:8080/metrics,interval: 5s}]} }下面的示例以多个的服务的格式给出了定义。 {services: [{id: tomcat,name: tomcat,address: tomcat,port: 8080,tags: [tomcat],checks: [{http: http://tomcat:8080/metrics,interval: 5s}]}] }注销服务也可以使用consul services deregister命令进行。 consul services deregister -id SERVICE_ID 在Prometheus上做consul的服务发现 在consul上可以正常查到相关节点后在Prometheus.yml上增加相关配置 - job_name: node_exporterconsul_sd_configs:- server: 10.0.0.8:8500tags:- node_exporter #只有consul里带有该标签的服务才会被 Prometheus 发现和监控refresh_interval: 1m[rootrocky8 prometheus]#curl -XPOST localhost:9090/-/reload #重启部署Consul Exporter 提示仅需要为每个Consul实例部署consul-exporter它负责将Consul的状态信息转为Prometheus兼容的指标格式并予以暴露。 下载程序包以0.8.0版本为例 curl -LO https://github.com/prometheus/consul_exporter/releases/download/v0.8.0/consul_exporter-0.8.0.linux-amd64.tar.gz 展开程序包 tar xf consul_exporter-0.8.0.linux-amd64.tar.gz -C /usr/local/ ln -sv /usr/local/consul_exporter-0.8.0.linux-amd64 /usr/local/consul_exporter 创建用户若consul用户已经存在可略过该步骤 useradd -r consul 创建Systemd Unitfile保存于/usr/lib/systemd/system/consul_exporter.service文件中: [Unit] Descriptionconsul_exporter Documentationhttps://prometheus.io/docs/introduction/overview/ Afternetwork.target[Service] Typesimple Userconsul EnvironmentFile-/etc/default/consul_exporter

    具体使用时若consul_exporter与consul server不在同一主机时consul server要指向实际的地址

    ExecStart/usr/local/consul_exporter/consul_exporter --consul.serverhttp://localhost:8500 --web.listen-address:9107 --web.telemetry-path/metrics --log.levelinfo $ARGS ExecReload/bin/kill -HUP $MAINPID TimeoutStopSec20s Restartalways[Install] WantedBymulti-user.target启动服务 systemctl daemon-reload systemctl start consul_exporter.service systemctl enable consul_exporter.service 在Prometheus上做Consul Exporter的服务发现 因为Prometheus是对Consul做的服务发现所以 Consul Exporter用于监控Consul万一consul崩了呢 [rootrocky8 services]#cat consul-exporter.json {id: consul_exporter,name: consul_exporter.magedu.com,address: prometheus.magedu.com,port: 9107,tags: [consul_exporter],checks: [{http:http://prometheus.magedu.com9107/metrics,interval: 5s}] }[rootrocky8 prometheus]#vim prometheus.yml- job_name: consul_exporterconsul_sd_configs:- server: 10.0.0.8tags:- consul_exporterrefresh_interval: 1m加入服务注册 curl -XPUT –data consul-exporter.json http://localhost:8500/v1/agent/service/registercurl -XGET http://localhost:8500/v1/agent/services 查看部署MySQL Exporter 提示仅需要为每个MySQL Server实例部署mysql-exporter它负责将MySQL Server的状态信息转为Prometheus兼容的指标格式并予以暴露。 下载程序包以0.14.0版本为例 curl -LO https://github.com/prometheus/mysqld_exporter/releases/download/v0.14.0/mysqld_exporter-0.14.0.linux-amd64.tar.gz 展开程序包 tar xf mysqld_exporter-0.14.0.linux-amd64.tar.gz -C /usr/local/ ln -sv /usr/local/mysqld_exporter-0.14.0.linux-amd64 /usr/local/mysqld_exporter 创建用户或mysql用户已经存在可略过该步骤 useradd -r mysql 创建Systemd Unitfile保存于/usr/lib/systemd/system/mysqld_exporter.service文件中: [Unit] Descriptionconsul_exporter Documentationhttps://prometheus.io/docs/introduction/overview/ Afternetwork.target[Service] Typesimple Usermysql EnvironmentFile-/etc/default/mysqld_exporter

    具体使用时若mysql_exporter与mysql server不在同一主机时mysql server要指向实际的地址

    mysql_exporter连接mysql server使用的用户名和密码均为exporter该用户要获得正确的授权

    EnvironmentDATA_SOURCE_NAMEexporter:exporter(localhost:3306) ExecStart/usr/local/mysqld_exporter/mysqld_exporter --web.listen-address:9104 --web.telemetry-path/metrics --collect.info_schema.innodb_tablespaces --collect.info_schema.innodb_metrics --collect.global_status --collect.global_variables --collect.slave_status --collect.engine_innodb_status $ARGS ExecReload/bin/kill -HUP $MAINPID TimeoutStopSec20s Restartalways[Install] WantedBymulti-user.target在mysqld server上添加用户并授权其能够加载mysql的信息并转换为指标输出。需要注意的是用户账号授权时使用的主机范围。 mysql CREATE USER exporterlocalhost IDENTIFIED BY exporter; mysql GRANT PROCESS, REPLICATION CLIENT ON . TO exporterlocalhost; mysql GRANT SELECT ON performance_schema.* TO exporterlocalhost; mysql FLUSH PRIVILEGES;启动服务 systemctl daemon-reload systemctl start mysqld_exporter.service systemctl enable mysqld_exporter.service 在Prometheus上做Consul Exporter的服务发现 [rootrocky8 services]#cat mysqld_exporter.json {id: mysqld_exporter,name: mysqld_exporter.magedu.com,address: prometheus.magedu.com,port: 9107,tags: [mysqld_exporter],checks: [{http:http://prometheus.magedu.com/metrics,interval: 5s}] }[rootrocky8 prometheus]#vim prometheus.yml- job_name: mysqld_exporterconsul_sd_configs:- server: 10.0.0.8tags:- mysqld_exporterrefresh_interval: 1m加入服务注册 curl -XPUT –data mysqld_exporter.json http://localhost:8500/v1/agent/service/registercurl -XGET http://localhost:8500/v1/agent/services 查看部署nginx Exporter 基于镜像 version: 3.6networks:monitoring:driver: bridgeipam:config:- subnet: 172.31.107.0/24services:nginx:image: nginx:1.22.1volumes: - ./nginx/stub_status-server.conf:/etc/nginx/conf.d/stub_status-server.conf:ro #定义·文件夹networks:- monitoringexpose:- 8080- 80ports:- 80:80nginx-exporter:image: nginx/nginx-prometheus-exporter:0.11command:- -nginx.scrape-urihttp://nginx:8080/stub_statusnetworks:- monitoringports:- 9113:9113depends_on:- nginx ~
    [rootrocky8 nginx-and-exporter]#ls docker-compose.yml nginx [rootrocky8 nginx-and-exporter]#vim docker-compose.yml [rootrocky8 nginx-and-exporter]#tree nginx/ nginx/ └── stub_status-server.conf0 directories, 1 file[rootrocky8 nginx-and-exporter]#cat nginx/stub_status-server.conf server {listen 8080;server_name localhost; 文件·location /stub_status {stub_status;access_log off;#allow 172.31.0.0/16;#deny all;} }启动 [rootrocky8 nginx-and-exporter]#docker-compose up /usr/local/lib/python3.6/site-packages/paramiko/transport.py:32: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core  在Prometheus上做Consul Exporter的服务发现 [rootrocky8 services]#/usr/local/consul/consul services register nginx-exporter.json   curl -XGET http://localhost:8500/v1/agent/services   查看 [rootrocky8 services]#cat nginx-exporter.json {service:{id: nginx_exporter,name: nginx_exporter.magedu.com,address: server02.magedu.com,port: 9113,tags: [nginx_exporter],checks: [{http: http://server02.magedu.com:9113/metrics,interval: 5s}]} }[rootrocky8 services]#cat prometheus.yml- job_name: nginx_exporterconsul_sd_configs:- server: 10.0.0.8:8500tags:- nginx_exporterrefresh_interval: 1m[rootrocky8 prometheus]#curl -XPOST localhost:9090/-/reload  刷新在Prometheus上面查看 在Prometheus上做tomcat [rootrocky8 tomcat-and-metrics]#ls docker-compose.yml tomcat [rootrocky8 tomcat-and-metrics]#cat docker-compose.yml #安装 version: 3.6volumes:tomcat_webapps: {}networks:monitoring:driver: bridgeipam:config:- subnet: 172.31.130.0/24services:tomcat:#image: tomcat:jdk11build:context: tomcatdockerfile: Dockerfile hostname: tomcat.magedu.comexpose:- 8080ports:- 8080:8080volumes:- tomcat_webapps:/usr/local/tomcat/webapps- ./tomcat/tomcat-users.xml:/usr/local/tomcat/conf/tomcat-users.xmlnetworks:- monitoringenvironment:TZ: Asia/Shanghai [rootrocky8 tomcat-and-metrics]#cd tomcat/[rootrocky8 tomcat]#ls context.xml Dockerfile sources.list tomcat-users.xml[rootrocky8 tomcat]#cat tomcat-users.xml #tomcat账户配置 ?xml version1.0 encodingUTF-8?

    !–Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements. See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to You under the Apache License, Version 2.0(the License); you may not use this file except in compliance withthe License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an AS IS BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.

    tomcat-users xmlnshttp://tomcat.apache.org/xmlxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://tomcat.apache.org/xml tomcat-users.xsdversion1.0

    !–By default, no user is included in the manager-gui role requiredto operate the /manager/html web application. If you wish to use this app,you must define such a user - the username and password are arbitrary.Built-in Tomcat manager roles:- manager-gui - allows access to the HTML GUI and the status pages- manager-script - allows access to the HTTP API and the status pages- manager-jmx - allows access to the JMX proxy and the status pages- manager-status - allows access to the status pages onlyThe users below are wrapped in a comment and are therefore ignored. If youwish to configure one or more of these users for use with the manager webapplication, do not forget to remove the !.. .. that surrounds them. Youwill also need to set the passwords to something appropriate.

    !–user usernameadmin passwordmust-be-changed rolesmanager-gui/user usernamerobot passwordmust-be-changed rolesmanager-script/

    !–The sample user and role entries below are intended for use with theexamples web application. They are wrapped in a comment and thus are ignoredwhen reading this file. If you wish to configure these users for use with theexamples web application, do not forget to remove the !.. .. that surroundsthem. You will also need to set the passwords to something appropriate.

    !–role rolenametomcat/role rolenamerole1/user usernametomcat passwordmust-be-changed rolestomcat/user usernameboth passwordmust-be-changed rolestomcat,role1/user usernamerole1 passwordmust-be-changed rolesrole1/ –role rolenamemanager-gui/role rolenamemanager-script/user usernametomcat passwordmagedu.com rolesmanager-gui,manager-script/ /tomcat-users tomcat允许远程登录 [rootrocky8 tomcat]#cat context.xml 允许远程登录 ?xml version1.0 encodingUTF-8?

    !–Licensed to the Apache Software Foundation (ASF) under one or morecontributor license agreements. See the NOTICE file distributed withthis work for additional information regarding copyright ownership.The ASF licenses this file to You under the Apache License, Version 2.0(the License); you may not use this file except in compliance withthe License. You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an AS IS BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.

    Context antiResourceLockingfalse privilegedtrue CookieProcessor classNameorg.apache.tomcat.util.http.Rfc6265CookieProcessorsameSiteCookiesstrict / !–Valve classNameorg.apache.catalina.valves.RemoteAddrValveallow127.\d.\d.\d|::1|0:0:0:0:0:0:0:1 / –Manager sessionAttributeValueClassNameFilterjava.lang.(?:Boolean|Integer|Long|Number|String)|org.apache.catalina.filters.CsrfPreventionFilter$LruCache(?:$1)?|java.util.(?:Linked)?HashMap/ /Contexttomcat的镜像仓库地址 [rootrocky8 tomcat]#cat sources.list deb https://repo.huaweicloud.com/debian/ bullseye main non-free contrib deb-src https://repo.huaweicloud.com/debian/ bullseye main non-free contrib deb https://repo.huaweicloud.com/debian-security/ bullseye-security main deb-src https://repo.huaweicloud.com/debian-security/ bullseye-security main deb https://repo.huaweicloud.com/debian/ bullseye-updates main non-free contrib deb-src https://repo.huaweicloud.com/debian/ bullseye-updates main non-free contrib deb https://repo.huaweicloud.com/debian/ bullseye-backports main non-free contrib deb-src https://repo.huaweicloud.com/debian/ bullseye-backports main non-free contribtomcat下载及扩充支持相应的功能 [rootrocky8 tomcat]#cat Dockerfile FROM tomcat:9.0-jdk17-openjdk-slimADD ./sources.list /etc/apt/sources.listENV TOMCAT_SIMPLECLIENT_VERSION0.12.0 ENV TOMCAT_EXPORTER_VERSION0.0.15RUN apt-get update apt-get install -y curl \curl -v –fail –location https://search.maven.org/remotecontent?filepathio/prometheus/simpleclient/${TOMCAT_SIMPLECLIENT_VERSION}/simpleclient-${TOMCAT_SIMPLECLIENT_VERSION}.jar –output /usr/local/tomcat/lib/simpleclient-\({TOMCAT_SIMPLECLIENT_VERSION}.jar \curl -v --fail --location https://search.maven.org/remotecontent?filepathio/prometheus/simpleclient_common/\){TOMCAT_SIMPLECLIENT_VERSION}/simpleclient_common-\({TOMCAT_SIMPLECLIENT_VERSION}.jar --output /usr/local/tomcat/lib/simpleclient_common-\){TOMCAT_SIMPLECLIENT_VERSION}.jar \curl -v –fail –location https://search.maven.org/remotecontent?filepathio/prometheus/simpleclient_hotspot/${TOMCAT_SIMPLECLIENT_VERSION}/simpleclient_hotspot-${TOMCAT_SIMPLECLIENT_VERSION}.jar –output /usr/local/tomcat/lib/simpleclient_hotspot-\({TOMCAT_SIMPLECLIENT_VERSION}.jar \curl -v --fail --location https://search.maven.org/remotecontent?filepathio/prometheus/simpleclient_servlet/\){TOMCAT_SIMPLECLIENT_VERSION}/simpleclient_servlet-\({TOMCAT_SIMPLECLIENT_VERSION}.jar --output /usr/local/tomcat/lib/simpleclient_servlet-\){TOMCAT_SIMPLECLIENT_VERSION}.jar \curl -v –fail –location https://search.maven.org/remotecontent?filepathio/prometheus/simpleclient_servlet_common/${TOMCAT_SIMPLECLIENT_VERSION}/simpleclient_servlet_common-${TOMCAT_SIMPLECLIENT_VERSION}.jar –output /usr/local/tomcat/lib/simpleclient_servlet_common-\({TOMCAT_SIMPLECLIENT_VERSION}.jar \curl -v --fail --location https://search.maven.org/remotecontent?filepathnl/nlighten/tomcat_exporter_client/\){TOMCAT_EXPORTER_VERSION}/tomcat_exporter_client-\({TOMCAT_EXPORTER_VERSION}.jar --output /usr/local/tomcat/lib/tomcat_exporter_client-\){TOMCAT_EXPORTER_VERSION}.jar \curl -v –fail –location https://search.maven.org/remotecontent?filepathnl/nlighten/tomcat_exporter_servlet/${TOMCAT_EXPORTER_VERSION}/tomcat_exporter_servlet-${TOMCAT_EXPORTER_VERSION}.war –output /usr/local/tomcat/webapps/metrics.warRUN mv /usr/local/tomcat/webapps.dist/* /usr/local/tomcat/webapps/ ADD ./context.xml /usr/local/tomcat/webapps/manager/META-INF/context.xml注册到consul上面去及Prometheus上做服务发现 [rootrocky8 services]#/usr/local/consul/consul services register tomcat.json Node name rocky8.wang.org will not be discoverable via DNS due to invalid characters. Valid characters include all alpha-numerics and dashes. Registered service: tomcat.magedu.com[rootrocky8 services]#cat tomcat.json {service:{id: tomcat,name: tomcat.magedu.com,address: server02.magedu.com,port: 8080,tags: [tomcat],checks: [{http: http://server02.magedu.com:8080/metrics,interval: 5s}]} }[rootrocky8 prometheus]#cat prometheus.yml- job_name: tomcatconsul_sd_configs:- server: 10.0.0.8:8500tags:- tomcatrefresh_interval: 1m[rootrocky8 prometheus]#curl -XPOST localhost:9090/-/reload 重新加载 署Blackbox Exporter 取决于黑盒监控 提示仅需要部署的Blackbox Exporter实例数据取决于黑盒监控的任务量及节点的可用资源。 [rootrocky8 blackbox-exporter]#cat configs/blackbox.yml modules:# https://github.com/prometheus/blackbox_exporter/blob/master/example.ymlhttp_2xx:prober: httptimeout: 5shttp:valid_http_versions: - HTTP/1.1- HTTP/2valid_status_codes: [] # Defaults to 2xxenable_http2: falsemethod: GETno_follow_redirects: false# fail_if_ssl为true时表示如果站点启用了SSL则探针失败反之成功; # fail_if_not_ssl刚好相反;fail_if_ssl: falsefail_if_not_ssl: false# fail_if_body_matches_regexp, fail_if_body_not_matches_regexp, fail_if_header_matches, fail_if_header_not_matches# 可以定义一组正则表达式用于验证HTTP返回内容是否符合或者不符合正则表达式的内容fail_if_body_matches_regexp:- Could not connect to databasetls_config:insecure_skip_verify: falsepreferred_ip_protocol: ip4 # defaults to ip6http_with_proxy:prober: httphttp:proxy_url: http://127.0.0.1:3128skip_resolve_phase_with_proxy: truehttp_post_2xx:prober: httptimeout: 5shttp:method: POSTheaders:Content-Type: application/jsonbody: {}http_basic_auth_example:prober: httptimeout: 5shttp:method: POSTheaders:Host: login.example.combasic_auth:username: usernamepassword: mysecrethttp_custom_ca_example:prober: httphttp:method: GETtls_config:ca_file: /certs/my_cert.crthttp_gzip:prober: httphttp:method: GETcompression: gziphttp_gzip_with_accept_encoding:prober: httphttp:method: GETcompression: gzipheaders:Accept-Encoding: gziptls_connect:prober: tcptimeout: 5stcp:tls: truedns_udp_example:prober: dnstimeout: 5sdns:query_name: www.prometheus.ioquery_type: Avalid_rcodes:- NOERRORvalidate_answer_rrs:fail_if_matches_regexp:- .*127.0.0.1fail_if_all_match_regexp:- .*127.0.0.1fail_if_not_matches_regexp:- www.magedu.com.\t300\tIN\tA\t127.0.0.1fail_if_none_matches_regexp:- 127.0.0.1validate_authority_rrs:fail_if_matches_regexp:- .*127.0.0.1validate_additional_rrs:fail_if_matches_regexp:- .*127.0.0.1 [rootrocky8 blackbox-exporter]#ls configs docker-compose.yml [rootrocky8 blackbox-exporter]#cat docker-compose.yml version: 3.6networks:monitoring:driver: bridgeipam:config:- subnet: 172.31.136.0/24services:blackbox_exporter:image: prom/blackbox-exporter:v0.24.0volumes:- ./configs/:/etc/blackboxexporter/command:- –config.file/etc/blackboxexporter/blackbox.ymlnetworks:- monitoringports:- 9115:9115在Prometheus里面做黑河发现  [rootrocky8 prometheus]#cat prometheus.yml# Blackbox Exporter- job_name: blackboxmetrics_path: /probeparams:module: [http_2xx] # Look for a HTTP 200 response.static_configs:- targets:- www.magedu.com- www.google.comrelabel_configs:- source_labels: [address]target_label: param_target- source_labels: [param_target]target_label: instance- target_label: addressreplacement: 10.0.0.18:9115 # Blackbox exporter.- target_label: regionreplacement: remote[rootrocky8 prometheus]#curl -XPOST localhost:9090/-/reload #加载