Winse Blog

走走停停都是风景, 熙熙攘攘都向最好, 忙忙碌碌都为明朝, 何畏之.

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 接口略有不同:

1
2
3
4
5
# 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 :

配置好后的效果:

同一服务器下访问配置

使用 nginx 作为html的服务器,同时 proxy_pass 代理跳转到 cu3:8080(PuppetDB服务) :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[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配置

1
2
3
4
5
6
7
8
9
10
[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访问!!

1
2
3
4
5
6
7
8
9
10
11
12
13
[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;
}

参考

–END

Comments