Azure IoT Edge运行时控制
项目描述
弃用通知
现在,azure-iot-edge-runtime-ctl (iotedgectl) 工具已被弃用!当使用此工具启动时,Azure IoT Edge运行时(Edge Agent和Edge Hub)将继续工作。然而,自从Edge安全守护进程的官方发布以来,不建议使用此工具启动IoT Edge运行时。有关官方支持的Azure IoT Edge的更多信息,请访问IoT Edge文档。
简介
Azure IoT Edge运行时控制实用程序帮助用户管理和控制IoT Edge运行时。
具体来说,它可以帮助:* 初始设置或引导 * 证书提供 * 启动/停止和其他IoT Edge运行时控制选项。
先决条件
Python 2.7+
Python setuptools(用于pip安装)
Docker
安装
Python
安装需要Python和setuptools。在此处下载python。
在Windows上,确保python.exe和python Scripts目录在您的路径上。有关在Windows上安装python的更多信息,请参阅此处。
注意:如果您遇到任何问题,请参阅下面的安装故障排除部分。
Python
Docker
按照以下说明在您的宿主机上安装Docker https://docs.microsoft.com/en-us/azure/iot-edge
在Windows Subsystem for Linux (WSL)上启用Docker
注意: 本节仅适用于Windows机器,通常针对开发环境。
要在WSL中运行iotedgectl,需要执行以下额外的安装步骤。
不要在WSL中安装Docker,而是首先在您的Windows机器上安装Docker。
安装在Windows机器上的Docker可以直接在bash shell中使用。
在Docker设置窗口的“通用”部分,勾选“在tcp://localhost:2375上暴露Docker守护进程,不使用TLS”
下一步需要从bash shell运行
将docker可执行文件添加到环境变量$PATH中,并设置别名。
编辑文件~/.bashrc并添加以下行
PATH="$HOME/bin:$HOME/.local/bin:$PATH" PATH="$PATH:/mnt/c/Program\ Files/Docker/Docker/resources/bin" alias docker=docker.exe alias docker-machine=docker-machine.exe alias docker-compose=docker-compose.exe export DOCKER_HOST="tcp://localhost:2375"
保存并关闭~/.bashrc文件
将环境变量DOCKER_HOST添加到sudoers。
通过运行来编辑sudoers配置
sudo visudo
向文件中添加以下行
Defaults env_keep += "DOCKER_HOST"
保存并关闭文件
确保环境变量被导出
source ~/.bashrc
通过运行任何docker命令来测试安装。示例
docker ps docker images
安装工具
在终端中,完成以下步骤运行pip install azure-iot-edge-runtime-ctl(可能需要以管理员身份运行)
这应该在您的路径上安装iotedgectl工具。
有关常见安装问题,请参阅安装故障排除。
如何运行
操作IoT Edge运行时的主要命令是:setup、start、restart、stop、status、update、login和uninstall。
setup:此命令接受用户输入以配置运行时。IoT Edge运行时所需的配置文件和证书作为此步骤的一部分创建。
IoT Edge可以通过使用输入配置文件和命令行(CLI)参数–config-file来设置,也可以通过指定各种配置值来设置–setup CLI参数。如果使用–config-file参数,则将忽略所有其他CLI参数。
可能需要以管理员(sudo)权限运行“setup”命令。此命令的一个输出结果是生成一个JSON格式的配置文件。该文件的生成目录是可配置的,如果未指定,则将使用默认路径(见下文)。
设置Edge配置目录有3种方法,以下是优先级顺序
环境变量EDGECONFIGDIR - 当使用此变量时,必须指定一个绝对路径作为该变量的值。
iotedgectl CLI选项用于指定目录路径。
–config-file:使用本文件中描述的目录路径配置输入JSON配置文件。
–edge-config-dir:当使用此选项时,必须指定一个主机上的目录的绝对路径。
注意:如果指定了环境变量EDGECONFIGDIR和CLI选项,则环境变量将具有优先权,CLI选项将被忽略。
如果上述所有选项都没有设置,则将选择以下默认路径
Default IoT Edge Configuration Host Paths: ------------------------------------------ Linux: /etc/azure-iot-edge Windows: %PROGRAMDATA%\azure-iot-edge\config MacOS: /etc/azure-iot-edge
start:此命令启动IoT Edge运行时。除非已存在于主机机器上,否则此命令将下载Edge Agent镜像。在上述setup步骤中指定的配置信息将提供给在实例化时Edge Agent。
stop:此命令停止IoT Edge运行时。注意:Edge模块被停止,而不是被删除。
restart:此命令重新启动IoT Edge运行时。如果Edge运行时不存在于主机上,则行为类似于start。如果有一个运行时是活动的,它将停止以及由Edge运行时部署的任何模块。随后,将重新启动Edge运行时以及所有其他模块。
status:打印IoT Edge运行时的当前状态。
卸载:此命令停止并卸载IoT Edge运行时。运行卸载将删除配置文件、证书。此外,IoT Edge运行时和所有模块都将被移除。
更新:此命令接受一个Edge Agent镜像作为输入,并使用此新镜像配置IoT Edge。运行此命令将使用此新镜像更新IoT Edge配置文件,现有的Edge Agent将被停止,其旧镜像将被删除并使用新镜像重新启动。
登录:此命令接受注册服务器、用户名和凭证作为输入,并使用这些数据配置IoT Edge。运行登录将更新IoT Edge配置文件中的注册信息。这对于将模块镜像托管在私有注册表上的用户很有用。注意:如果Edge运行时处于活动状态并正在运行,Edge Agent将被停止,现有实例将被删除,并使用新凭证重新启动。
以下是几个示例命令调用
打印帮助并退出
$> iotedgectl --help
使用IoT Edge主机配置文件设置IoT Edge运行时。请参阅IoT Edge主机配置文件描述
$> iotedgectl setup --help $> iotedgectl setup --config-file edge_config.json $> iotedgectl --verbose DEBUG setup --config-file edge_config.json Note: When specifying the homeDir path on Windows please use "C:\\example\\edge-home"
使用手动指定的命令行参数设置IoT Edge运行时
$> iotedgectl setup --connection-string "HostName=<>;DeviceId=<>;SharedAccessKey=<>" Note: When specifying the connection string ensure that it is surrounded by double quotes ". In general, anything with a semicolon should be put into quotes.
启动IoT Edge运行时
$> iotedgectl start $> iotedgectl --verbose INFO start
重新启动IoT Edge运行时
$> iotedgectl restart $> iotedgectl --verbose INFO restart
停止IoT Edge运行时
$> iotedgectl stop $> iotedgectl --verbose INFO stop
卸载IoT Edge运行时
$> iotedgectl uninstall $> iotedgectl --verbose DEBUG uninstall
打印IoT Edge运行时的当前状态
$> iotedgectl status $> iotedgectl --verbose INFO status
IoT Edge主目录描述
IoT Edge运行时需要在主机机器上创建一个目录才能执行。此目录将包含必要的配置文件、证书和特定模块的文件。这被称为EDGEHOMEDIR。要配置EDGEHOMEDIR的目录路径,可以使用CLI选项“iotedgectl setup –edge-home-dir <path>”。如果没有指定,将使用以下列出的默认目录作为EDGEHOMEDIR。
Default Host Paths: ------------------- Linux: /var/lib/azure-iot-edge Windows: %PROGRAMDATA%\azure-iot-edge\data MacOS: /var/lib/azure-iot-edge
当使用–config-file选项时,需要提供绝对目录路径来设置Edge运行时(见下文)。
注意:如果目录不存在,它将被创建。
当IoT Edge运行时执行时,以下文件系统结构将在EDGEHOMEDIR下创建。
EDGEHOMEDIR Structure: ----------------------- EDGEHOMEDIR . +-- certs -- This directory is created by the iotedgectl utility when generating | either self signed certificates or Device CA based certificates. +-- modules -- This directory is created by the iotedgectl utility to host all the Edge Module specific files.
IoT Edge主机配置文件描述
以下部分描述了设置IoT Edge所需的各种配置项。* 当使用命令行选项设置IoT Edge时,此文件将自动生成。* 当使用–config-file设置IoT Edge设备时,需要提供带有适当输入数据的配置文件。
// Config file format schema; Users should not need to modify this. "schemaVersion": "1", // IoTHub Device Connection string in the format listed below. // A connection string is required when using the --config-file option // to setup the Edge runtime. "deviceConnectionString": "HostName=<>;DeviceId=<>;SharedAccessKey=<>", // Absolute path to the IoT Edge home dir. // An absolute directory path is required when using the --config-file option // to setup the Edge runtime. // If the specified directory does not exist, it will be created. // For Windows paths, use \\ as the path separator. Example: C:\\path\\file.ext "homeDir": "<EDGEHOMEDIR>", // Absolute path to the IoT Edge configuration dir. This is an optional // configuration item. Please review the setup command section above to see // how this field is used by this utility. // An absolute directory path is required when using the --config-file option // to setup the Edge runtime. // If the specified directory does not exist, it will be created. // For Windows paths, use \\ as the path separator. Example: C:\\path\\file.ext "configDir": "<EDGECONFIGDIR>", // IoT Edge device's DNS name; // Specifying a FQDN is only required when operating the // IoT Edge as a 'Gateway' for leaf device connectivity. // If a FQDN is unavailable, the host name (or machine name) could be used. // This typically occurs when the host is not domain registered such as // a device on a home Wifi network. This should work just fine for Edge module // to Edge Hub communication but may not work for leaf device connectivity. // This hostname value is needed specifically to name the Edge Hub server // and is also used to generate the Edge Hub server certificate. // This server certificate is used to enable TLS connections from IoT Edge // modules and leaf devices. // The DNS host name is required when using the --config-file option // to setup the Edge runtime. "hostName": "<Hostname>", // Log level setting for IoT Edge runtime diagnostics. "info" and "debug". // are the supported levels and default is info. This should only // modified for debugging purposes. // A log level is required when using the --config-file option // to setup the Edge runtime. "logLevel": "info", // Upstream protocol to be used by the Edge runtime (and possibly other module) // when connecting to IoTHub. The permitted values are Amqp and AmqpWs. // This is an optional setting. "upstreamProtocol": "Amqp", // Configuration settings for the IoT Edge Runtime "security": { // Configuration of X.509 certificates; There are two options: // - Self Signed Certificates: This mode is NOT secure and is only // (selfSigned) intended for development purposes // and quick start type scenarios. // // - Pre Installed Certificates: When this is enabled, it is expected // (preInstalled) that the "Device CA" and "Owner CA" // certificates and their corresponding // certificate chain be provided. Additionally, // the Device CA private key and its // optional passphrase should be provided. // This is more of a real world setup // where the IoT Edge is configured to run // as a gateway. // // The "option" key below selects any of the modes listed above. // An option is required when using the --config-file option // to setup the Edge runtime. "certificates": { "option": "selfSigned", "selfSigned": { // If the boolean value of forceNoPasswords is true, // it is not required to supply valid paths // to the Edge Device or Edge Agent private key // passphrase (password) files described below. "forceNoPasswords": true // Absolute path to the passphrase file for the Edge Device private key. // The passphrase must be between 4 - 1023 characters in length and the // file should be a regular ascii text file containing the passphrase. "deviceCAPassphraseFilePath": "", // Absolute path to the passphrase file for the Edge Agent private key. // The passphrase must be between 4 - 1023 characters in length and the // file should be a regular ascii text file containing the passphrase. "agentCAPassphraseFilePath": "" }, "preInstalled": { // Absolute path to the Edge Owner CA certificate file in X.509 PEM format. // An absolute file path is required when using the --config-file option // and 'preInstalled' is the certificate option selected // to setup the Edge runtime. // For Windows paths, use \\ as the path separator. Example: C:\\path\\file.ext "ownerCACertificateFilePath": "", // Absolute path to the Edge Device CA certificate file in X.509 PEM format // An absolute file path is required when using the --config-file option // and 'preInstalled' is the certificate option selected // to setup the Edge runtime. // For Windows paths, use \\ as the path separator. Example: C:\\path\\file.ext "deviceCACertificateFilePath": "", // Absolute path to the Edge Device CA certificate chain file in X.509 PEM format. // This is the certificate chain from the Owner CA up to and including the // Device CA certificate. // An absolute file path is required when using the --config-file option // and 'preInstalled' is the certificate option selected // to setup the Edge runtime. // For Windows paths, use \\ as the path separator. Example: C:\\path\\file.ext "deviceCAChainCertificateFilePath": "", // Absolute path to the Edge Device CA certificate's private key // file in X.509 PEM format. // An absolute file path is required when using the --config-file option // and 'preInstalled' is the certificate option selected // to setup the Edge runtime. // For Windows paths, use \\ as the path separator. Example: C:\\path\\file.ext // Note: If a passphrase was used to generate the private key, // the passphrase must be provided via the deviceCAPassphraseFilePath // option described below. "deviceCAPrivateKeyFilePath": "", // Absolute path to the passphrase file for the Edge Device private key. // The passphrase must be between 4 - 1023 characters in length and the // file should be regular ascii text file containing the passphrase. // This would need to be provided only if the Edge Device CA private // was created with a passphrase. // For Windows paths, use \\ as the path separator. Example: C:\\path\\file.ext "deviceCAPassphraseFilePath": "", // If the boolean value of forceNoPasswords is true, // it is not required to supply valid paths // to the Edge Agent private key password (passphrase) file. "forceNoPasswords": true // Absolute path to the passphrase file for the Edge Agent private key. // The passphrase must be between 4 - 1023 characters in length and the // file should be a regular ascii text file containing the passphrase. // For Windows paths, use \\ as the path separator. Example: C:\\path\\file.ext "agentCAPassphraseFilePath": "" }, // Certificate subject data. // These are values that are used when auto generating // any certificates required for operating the IoT Edge. // These values can be modified as needed // and the values for all the fields can be empty strings. // These values are not when using the preInstalled certificate // option, rather they are determined from the Device CA certificate. "subject": { "countryCode": "US", "state": "Washington", "locality": "Redmond", "organization": "Default Edge Organization", "organizationUnit": "Edge Unit", "commonName": "Edge Device CA" } } }, // Section containing Configuration of IoT Edge Runtime Deployment and Host. "deployment": { // Currently "docker" is the only deployment type supported. // Specifying this value is required when using the --config-file option // to setup the Edge runtime. "type": "docker", // Docker host settings "docker": { // Docker Daemon socket URI; This is the end point that the Edge Agent // will use to communicate with the daemon. Please note this may not be // the same docker URI end point that a user might use on their host. // This is true when running Linux containers on Windows. // A valid URI is required when using the --config-file option // to setup the Edge runtime. "uri": "unix:///var/run/docker.sock", // IoT Edge runtime image; This value may need to be updated as newer // images are released over time either by updating the config file and // using --config-file or the **update** command. // A runtime image is required when using the --config-file option // to setup the Edge runtime. "edgeRuntimeImage": "edge_repository_address/edge_image_name:version", // Docker registries can be added in this array for custom modules. // If there is no username or password associated with a registry, // there is no need to add any data here. // NOTE: This is a temporary configuration item required by the IoT Edge // Longer term, it will be possible to manage registries and // credentials using the IoTHub portal. // Adding a registry to the array can be done either by updating the // config file and using --config-file or the **login** command. "registries": [ { "address": "example-repository-address-1", "username": "example-username-1", "password": "example-password-1" }, { "address": "example-repository-address-2", "username": "example-username-2", "password": "example-password-2" } ], // Logging options for the IoT Edge runtime. The format complies with // the docker schema described here: // https://docs.docker.net.cn/engine/admin/logging/overview/ // Appropriate log configuration values are required when using the // --config-file option to setup the Edge runtime. "loggingOptions": { "log-driver": "json-file", "log-opts": { "max-size": "10m" } } } }
安装故障排除
Raspbian
在Raspbian平台上,您可能需要更新pip或设置工具
sudo pip install --upgrade setuptools pip
Python安装可能需要构建一些C库,这些库需要开发包,这些开发包不是默认安装的
sudo apt-get install python2.7-dev libffi-dev libssl-dev
项目详情
哈希值 for azure-iot-edge-runtime-ctl-1.0.0rc24.tar.gz
算法 | 哈希摘要 | |
---|---|---|
SHA256 | 3951b3ef8ddc4da7ec32784e46b48be7acfd4fb850f84c55212996e12ca0bbc4 |
|
MD5 | 0303f814417a0c85890906481379d587 |
|
BLAKE2b-256 | 3eceeb2f362fb7ccf8758896e33e40d0f091d379cb0c6513ca68449a33e5c951 |
哈希值 for azure_iot_edge_runtime_ctl-1.0.0rc24-py2.py3-none-any.whl
算法 | 哈希摘要 | |
---|---|---|
SHA256 | ecaf6ecd54c32ec6fc9568b12d0f756b9ff270bb57c33f3f9609b4b2d748780e |
|
MD5 | 290b9b236b8abe3276b21364e291f28a |
|
BLAKE2b-256 | 98b87a6ece3d4430807a7f1d61a49e458f0f768d93dd8dc75237d15e184236ac |