安装和使用 influx CLI
使用 influx 命令行工具与管理您的 InfluxDB Cloud 实例。编写和查询数据,生成 InfluxDB 模板,导出数据等。
安装 influx CLI
执行以下操作之一:
使用 Homebrew
brew install influxdb-cli
手动下载和安装
下载
influxCLI 包 通过你的浏览器 或 通过命令行。从您的浏览器下载
从命令行下载
curl -LO https://dl.influxdata.com/influxdb/releases/influxdb2-client-2.7.5-darwin-amd64.tar.gz \ --output-dir ~/Downloads解压下载的二进制文件。
执行以下操作之一:
在 查找器 中,双击下载的包文件。
在你的终端(例如,Terminal 或 iTerm2)使用
tar来解压包—例如,输入以下命令将其解压到~/Downloads:tar zxvf ~/Downloads/influxdb2-client-2.7.5-darwin-amd64.tar.gz \ --directory ~/Downloads
可选:将
influx二进制文件放入您的$PATH中——例如,将二进制文件复制到/usr/local/bin:sudo cp ~/Downloads/influx /usr/local/bin/要使用位于你的
$PATH(/usr/local/bin) 中的influx二进制文件,你可以在终端中输入influx来运行 CLI。如果您不将
influx二进制文件移动到您的$PATH中,请输入二进制文件的路径以运行 CLI,例如:~/Downloads/influx(macOS Catalina 及更新版本) 授权
influx二进制文件。macOS要求下载的二进制文件由注册的Apple开发者签名。 当您首次尝试运行
influx时,macOS会阻止它运行。 要授权influx二进制文件:允许在macOS Ventura上运行二进制文件
- Follow the preceding instructions to attempt to start
influx. - Open System Settings and click Privacy & Security.
- Under the Security heading, there is a message about “influxd” being blocked, click Allow Anyway.
- When prompted, enter your password to allow the setting.
- Close System Settings.
- Attempt to start
influx. - A prompt appears with the message “macOS cannot verify the developer of “influx”…”". Click Open.
允许在macOS Catalina上运行二进制文件
- Attempt to run an
influxcommand. - Open System Preferences and click Security & Privacy.
- Under the General tab, there is a message about
influxbeing blocked. Click Open Anyway.
- Follow the preceding instructions to attempt to start
下载
influxCLI 包 通过你的浏览器 或 通过命令行。从您的浏览器下载
influx CLI v2.7.5 (amd64) influx CLI v2.7.5 (arm)
从命令行下载
# amd64 wget https://dl.influxdata.com/influxdb/releases/influxdb2-client-2.7.5-linux-amd64.tar.gz# arm wget https://dl.influxdata.com/influxdb/releases/influxdb2-client-2.7.5-linux-arm64.tar.gz解压下载的二进制文件。
注意: 以下命令为示例。如有必要,请调整文件名、路径和工具。
# amd64 tar xvzf ./influxdb2-client-2.7.5-linux-amd64.tar.gz# arm tar xvzf ./influxdb2-client-2.7.5-linux-arm64.tar.gz可选:将未打包的
influx可执行文件放置在您的系统$PATH中。# amd64 sudo cp ./influx /usr/local/bin/# arm sudo cp ./influx /usr/local/bin/如果您没有将
influxd二进制文件移动到您的$PATH中,请输入二进制文件的路径以启动服务器,例如:./influx
我们推荐在 Powershell 中运行 influx CLI 命令。命令提示符不完全兼容。
下载
influxCLI 包。展开下载的压缩文件。
将下载的压缩包解压到
C:\Program Files\InfluxData\并根据需要重命名。> Expand-Archive .\influxdb2-client-2.7.5-windows-amd64.zip -DestinationPath 'C:\Program Files\InfluxData\' > mv 'C:\Program Files\InfluxData\influxdb2-client-2.7.5-windows-amd64' 'C:\Program Files\InfluxData\influx'授予对
influxCLI 的网络访问权限。当首次使用
influxCLI 时, Windows Defender 显示以下消息:Windows Defender 防火墙阻止了此应用程序的某些功能。
要授予
influxCLI 所需的访问权限,请执行以下操作:- Select Private networks, such as my home or work network.
- Click Allow access.
设置 influx CLI
提供所需的认证凭据
为了避免每个命令都需要传递您的 InfluxDB 主机、API 令牌 和 组织,请将它们存储在 influx CLI 配置 (config) 中。需要这些凭据的 influx 命令会自动从活动配置中检索这些凭据。
使用influx config create命令创建一个influx CLI配置并将其设置为活动状态:
influx config create --config-name CONFIG_NAME \
--host-url http://localhost:8086 \
--org ORG \
--token API_TOKEN \
--active
替换以下内容:
有关管理CLI配置的更多信息,请参阅
influx config 文档。
有关如何创建API令牌的说明,请参见 创建令牌。
启用命令行补全(可选)
要安装 influx shell 完成脚本,请参见
influx completion。
使用 influx CLI 命令
有关 influx CLI 命令的信息,请参见influx CLI 参考文档。