Article
puppetexplorer设置
注意: 使用 PuppetExplorer 的前提是已经安装 PuppetDB (安装参考:Puppetdb安装配置)。
PuppetDB 提供的8080界面太过于简单,其实8080主要提供非常多的接口。PuppetExplorer 就是使用这些 restful 查询接口来进行展示。比默认的 PuppetDB-UI 更具体和详细。
配置 PuppetExplorer 有两种方式:
- 两个服务在 同一个域 下面,配置 /api 跳转到 PuppetDB:8080
- 两个服务,配置各自的地址 。修改config.js,同时处理跨域的问题。
https://github.com/spotify/puppetexplorer
- The recommended way to install it is on the same host as your PuppetDB instance. Then proxy /api to port 8080 of your PuppetDB instance (except the /commands endpoint). This avoids the need for any CORS headers.
- It is possible to have it on a separate domain from your PuppetDB though. If you do, make sure you have the correct Access-Control-Allow-Origin header and a Access-Control-Expose-Headers: X-Records header.
# 适配 PuppetDB4
官网的版本已经几个月没有更新,新的 API 接口略有不同:
# puppetdb-4.0
/metrics/v1/mbeans/puppetlabs.puppetdb.population:name=num-active-nodes
# puppetexplorer-2.0.0
/metrics/v1/mbeans/puppetlabs.puppetdb.query.population:type=default,name=num-nodes
修改 app.js 拼接链接的字符串即可,删除 .query. 和 type=default :
[puppetdb4-puppetexplorer.png 图片]
配置好后的效果:
[puppetexplorer.png 图片]
# 同一服务器下访问配置
使用 nginx 作为html的服务器,同时 proxy_pass 代理跳转到 cu3:8080(PuppetDB服务) :
[hadoop@cu2 puppetexplorer-2.0.0]$ mv config.js.example config.js
[hadoop@cu2 nginx]$ vi conf/nginx.conf
...
# 路径最后带上 / !!
location /api/ {
proxy_pass http://cu3:8080/;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
}
location /puppetexplorer {
alias /opt/puppetlabs/puppetexplorer-2.0.0;
}
[hadoop@cu2 nginx]$ sbin/nginx -s reload
然后打开网页访问 http://cu2:8888/puppetexplorer 即可。
nginx的配置参考: Nginx配置proxy_pass转发的/路径问题, nginx as proxy to jetty
apache配置
- https://httpd.apache.org/docs/2.2/mod/mod_proxy.html#x-headers
- http://www.tech126.com/apache2-proxypass-header/
[root@hadoop-master1 html]# vi /etc/httpd/conf/httpd.conf
...
# puppetdb
ProxyPass /puppetdb/api/ http://hadoop-master1:8080/
[root@hadoop-master1 html]# vi puppetexplorer/config.js
...
PUPPETDB_SERVERS = [
['production', '/puppetdb/api'],
['testing', '/puppetdb/api']
# 不同服务器,跨域访问
老实说,完全不推荐这种做法。但是跨域的设置震惊到我了,原来自认为的方式完全不对。例如A javascript访问B,跨域头设置在B服务,是要B容许A访问!!
[root@hadoop-master2 puppetexplorer]# vi config.js
// List of PuppetDB servers, pairs of name, URL and $http config object
// The first one will be used as the default server
PUPPETDB_SERVERS = [
['production', 'http://cu2:8888'],
['testing', 'http://cu2:8888']
];
# Nginx配置,加上跨域访问源范围控制
location ~ /(metrics|pdb) {
add_header "Access-Control-Allow-Origin" "*";
proxy_pass http://cu3:8080;
}
# 参考
- http://www.html5rocks.com/en/tutorials/cors/?redirect_from_locale=zh
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Requests_with_credentials
- https://en.wikipedia.org/wiki/Cross-origin_resource_sharing
–END
Related
Related posts
-
杀鸡焉用牛刀:DuckDB 正取代部分 Spark 场景
2026-02-16
-
WIN 挂载 S3:像本地文件夹一样用对象存储
2026-02-10
-
n8n 终于还是部署到 Docker 了,经验就是要反反复复地去验证:要想少走弯路,就按官方推荐的最佳实践
2025-12-29
-
无需 Docker:n8n 2.x internal 模式下 Python Task Runner 配置实践
2025-12-25