介紹
Steampipe 將 API 和服務公開為高性能關系數據庫,使您能夠編寫基于 SQL 的查詢來探索動態數據。Mods 通過使用簡單 HCL 構建的儀表板、報告和控件擴展了 Steampipe 的功能。
官網:https://steampipe.io/
steampipe的安裝
下載腳本并執行
sudo /bin/sh -c "$(curl -fsSL https://raw.githubusercontent.com/turbot/steampipe/main/install.sh)"
版本檢查
steampipe -v
steampipe version 0.14.3
安裝第一個插件
steampipe plugin install steampipeInstalled plugin: steampipe
測試運行您的第一個查詢
steampipe query "select name from steampipe_registry_plugin;"+------------------+
| name |
+------------------+
| turbot/aws |
| turbot/steampipe |
| turbot/azure |
| ... |
+------------------+
- 上面這些步驟是Steampipe 的一步安裝程序下載steampipe 二進制文件,將其安裝到/usr/local/bin.,然后.steampipe在您的主目錄中創建一個目錄,其中包含所有支持庫和啟動所需的配置(包括 PostgreSQL)。
- 如需更新只需重新運行第一步上面的 curl 腳本即可安裝最新發布的 Steampipe 版本。
- Steampipe 也可以作為二進制可執行文件使用(或者您可以從源代碼構建)。要手動安裝 Steampipe,請解壓縮可執行文件并將其移動到系統的. PATH 可以從Steampipe Github
存儲庫的發布部分訪問源代碼、壓縮的可執行文件和二進制校驗和。
steampipe的使用
因為我有一臺aws的服務器我們本次舉例aws的插件
首先需要在服務器在設置 AWS 環境(CLI)
配置 AWS 命令行界面 (CLI)
簡介
AWS 命令行界面 (CLI) 是用于管理 AWS 產品的統一工具。只需要下載和配置一個工具,您就可以使用命令行控制多個 AWS 產品并利用腳本來自動執行這些服務。要使用 CLI 與 AWS 交互,需要配置憑證以供其在進行 API 調用時使用。
安裝 AWS CLI
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"unzip awscliv2.zip./aws/install
安裝后查看是否安裝成功
aws --version
aws-cli/2.2.17 Python/3.9.6 Darwin/20.5.0 source/x86_64 prompt/off
AWS CLI 現已正確安裝,我們需要配置憑證。可以嘗試運行諸如 aws ec2 describe-vpcs 之類的命令來查看是否一切運轉正常。由于缺少憑證,您可能會看到以下錯誤消息:
aws ec2 describe-vpcs# You may not see this error if you have already configured the CLI previously.
Unable to locate credentials. You can configure credentials by running ‘aws configure’.
配置 AWS CLI 憑證
要配置憑證,請使用命令 aws configure 。系統將要求您提供 AWS 訪問密鑰 ID、AWS 秘密訪問密鑰、原定設置區域和原定設置輸出格式。
最后,格式類型是原定設置顯示輸出的方式,包括但不限于:json、yaml、text。完成后,您應該在終端中看到以下內容 (如果您選擇 us-east-1 作為原定設置區域):
aws configure
AWS Access Key ID [None]: ANOTREALACCESSKEYID
AWS Secret Access Key [None]: ANOTREALSECRETACCESSKEY
Default region name [None]: us-east-1
Default output format [None]: json
(查找方法會在下面介紹)
現在我們可以運行之前的命令并查看結果,因為每個新的 AWS 賬戶都配置了原定設置 VPC:
aws ec2 describe-vpcs# Output
{"Vpcs": [{"CidrBlock": "10.0.0.0/16","DhcpOptionsId": "dopt-d12345","State": "available","VpcId": "vpc-0123456789abcdef","OwnerId": "123456789012",....
這就確認了 AWS CLI 現在已正確設置。它在 ~/.aws 中創建了兩個文件:config 和 credentials。credentials 文件包含您指定的憑證:
[default]
aws_access_key_id = AKNOTREALACCESSKEYID
aws_secret_access_key ==AyNOTREALSECRETACCESSKEY
配置文件的任何其他配置都存儲在 config 文件中。使用 aws configure 時,它將包含以下內容 (可能具有不同的區域):
[default]
region = us-east-1
output = json
AWS access ID 和 Secret的查找方法
在IAM的控制臺上的右邊找到我的安全憑證
選擇訪問密鑰(訪問密鑰ID和秘密訪問密鑰)后即可查看
選擇插件
選擇插件的時候我們可以在官方網站上選擇可用的插件
選擇aws service插件
steampipe為了減少風險不支持在root用戶上運行所以需要在普通用戶下操作。
steampipe plugin install aws #這邊已經下好了
填寫相關的配置
vim .steampipe/config/aws.spcconnection "aws" {plugin = "aws"access_key = "***************"secret_key = "***************"# You may connect to one or more regions. If `regions` is not specified,# Steampipe will use a single default region using the same resolution# order as the AWS CLI:# 1. The `AWS_DEFAULT_REGION` or `AWS_REGION` environment variable# 2. The region specified in the active profile (`AWS_PROFILE` or default)#regions = ["us-east-1", "us-west-2"]regions=["**-****-*"]# If no credentials are specified, the plugin will use the AWS credentials# resolver to get the current credentials in the same manner as the CLI.# Alternatively, you may set static credentials with the `access_key`,# `secret_key`, and `session_token` arguments, or select a named profile# from an AWS credential file with the `profile` argument:profile = "******" #把credentials的標頭寫上就好# The maximum number of attempts (including the initial call) Steampipe will# make for failing API calls. Can also be set with the AWS_MAX_ATTEMPTS environment variable.# Defaults to 9 and must be greater than or equal to 1.#max_error_retry_attempts = 9# The minimum retry delay in milliseconds after which retries will be performed.# This delay is also used as a base value when calculating the exponential backoff retry times.# Defaults to 25ms and must be greater than or equal to 1ms.#min_error_retry_delay = 25
保存退出后測試
[lcf@server4 ~]$ steampipe query
Welcome to Steampipe v0.14.1
For more information, type .help
> select * from aws_vpc
+-----------------------+--------------------------------------------------------------+---------------+-----------+------------+-----------------------
| vpc_id | arn | cidr_block | state | is_default | dhcp_options_id
+-----------------------+--------------------------------------------------------------+---------------+-----------+------------+-----------------------
| vpc-************* | arn:aws:ec2:********:**********:vpc/vpc-*************** | ***.**.0.0/16 | available | true | ********************
+-----------------------+--------------------------------------------------------------+---------------+-----------+------------+-----------------------
>
成功!
更多功能請查看官方文檔