如何使用Doctl,DigitalOcean官方命令行客户端

An earlier version of this tutorial was written by Brennen Bearnes.

本教程的早期版本由Brennen Bearnes编写

介绍 (Introduction)

DigitalOcean’s web-based control panel provides a point-and-click interface for managing Droplets. However, you may prefer a command-line tool if you have many Droplets to manage, need to administer Droplets from the terminal without a graphical desktop available, or have tasks which would benefit from a scriptable interface.

DigitalOcean基于Web的控制面板提供了用于管理Droplet的点击界面。 但是,如果您要管理许多Droplet,需要在没有可用图形桌面的情况下从终端管理Droplet或具有可从可编写脚本的界面中受益的任务,则可能更喜欢使用命令行工具。

doctl is the official DigitalOcean command-line client. It uses the DigitalOcean API to provide access to most account and Droplet features.

doctl是DigitalOcean的官方命令行客户端。 它使用DigitalOcean API提供对大多数帐户和Droplet功能的访问。

先决条件 (Prerequisites)

To follow this tutorial, you will need:

要遵循本教程,您将需要:

This tutorial is intended as a reference for most of doctl’s operations. Because doctl commands closely parallel the API, it may also be helpful to read the API documentation and How To Use the DigitalOcean API v2.

本教程旨在作为doctl大部分操作的参考。 由于doctl命令与API紧密并行,因此阅读API文档How to Use DigitalOcean API v2也可能会有所帮助。

通用doctl用法 (Generic doctl Usage)

调用命令 (Invoking Commands)

In doctl, individual features are invoked by giving the utility a command, one or more sub-commands, and sometimes one or more options specifying particular values. Commands are grouped under three main categories:

doctl ,通过向实用程序提供命令,一个或多个子命令以及有时一个或多个指定特定值的选项来调用各个功能。 命令分为三大类:

  • account for account-related information

    account相关信息

  • auth for authenticating with DigitalOcean

    auth与DigitalOcean认证

  • compute for managing infrastructure

    用于管理基础架构的compute

To see an overview of all commands, you can invoke doctl by itself. To see all available commands under one of the three main categories, you can use doctl category, like doctl compute. For a usage guide on a specific command, enter the command with the --help flag, as in doctl compute droplet --help.

要查看所有命令的概述,您可以doctl调用doctl 。 要查看三个主要类别之一下的所有可用命令,可以使用doctl category ,例如doctl compute 。 有关特定命令的用法指南,请输入带有--help标志的命令,如doctl compute droplet --help

以JSON格式检索数据 (Retrieving Data in JSON Format)

In scripting environments, or when working on the command line with data-processing tools, it’s often helpful to get machine-readable output from a command.

在脚本环境中,或在命令行中使用数据处理工具时,从命令中获取机器可读的输出通常会很有帮助。

By default, doctl formats its output in columns of human-readable text, but can produce detailed JSON output using the --output json option.

默认情况下, doctl其输出格式化为人类可读的文本列,但可以使用--output json选项生成详细的JSON输出。

  • doctl compute droplet get droplet_id --output json

    doctl计算droplet获取drop_id --output json


   
   
Sample Output
{ "id": droplet_id, "name": "droplet_name", "memory": 1024, "vcpus": 1, "disk": 30, "region": { "slug": "nyc3", "name": "New York 3", "sizes": [ ...

In addition to being a format readable with standard libraries in most programming languages, the JSON output may allow more fine-grained inspection of Droplets and other resources.

除了是大多数编程语言中的标准库都可读的格式外,JSON输出还可允许对Droplet和其他资源进行更细粒度的检查。

格式化 (Formatting)

It’s often useful to obtain only a set of fields from output. To do this, you can use the --format flag followed by a list of your desired fields. For example, if you want to obtain only the ID, name, and IP address of your Droplets, you can use the following command:

从输出中仅获取一组字段通常很有用。 为此,可以使用--format标志,后跟所需字段的列表。 例如,如果您只想获取Droplet的ID,名称和IP地址,则可以使用以下命令:

  • doctl compute droplet list --format "ID,Name,PublicIPv4"

    doctl计算液滴列表-格式“ ID,名称,公共IPv4”

   
   
Sample output
ID Name Public IPv4 50513569 doctl-1 67.205.152.65 50513570 test 67.205.148.128 50513571 node-1 67.205.131.88

范本 (Templates)

The doctl compute droplet get command supports output templating, which lets you customize the format of the output. To use this feature, specify the Go-formatted template via the --template flag.

doctl compute droplet get命令支持输出模板化,可让您自定义输出格式。 要使用此功能,请通过--template标志指定Go格式的模板

For example, if you want to get a Droplet’s name in the format droplet_name: droplet_name, you would use the following get command:

例如,如果您想以droplet_name: droplet_name的格式获取Droplet的名称,则可以使用以下get命令:

  • doctl compute droplet get 12345678 --template "droplet_name: {{ .Name}}

    doctl计算Droplet获取12345678 --template“ droplet_name:{{.Name}}


   
   
Output
droplet_name: ubuntu-1gb-nyc3-01

处理资源 (Working with Resources)

上市资源 (Listing Resources)

To get a list of resources, like Droplets, you can use the list command with no parameters.

要获取诸如Droplet之类的资源列表,可以使用不带参数的list命令。

  • doctl compute droplet list

    doctl计算液滴列表

   
   
Sample output for list command
ID Name Public IPv4 Private IPv4 Public IPv6 Memory VCPUs Disk Region Image Status Tags 50513569 test-1 67.205.152.65 512 1 20 nyc1 Ubuntu 16.04.2 x64 active 50513571 test-2 67.205.131.88 512 1 20 nyc1 Ubuntu 16.04.2 x64 active 50513570 site 67.205.148.128 512 1 20 nyc1 Ubuntu 16.04.2 x64 active

The list command supports a glob as an optional parameter. A glob represents pattern with wildcard characters which can be used to filter specific resources by name. For example, to get a list of Droplets whose names start with test, you can use the following command:

list命令支持将glob作为可选参数。 通配符表示带有通配符的模式,可用于按名称过滤特定资源。 例如,要获取名称以test开头的Droplet列表,可以使用以下命令:

doctl compute droplet list 'test*'

   
   
Sample output for list command with 'doctl-' as glob
ID Name Public IPv4 Private IPv4 Public IPv6 Memory VCPUs Disk Region Image Status Tags 50513569 test-1 67.205.152.65 512 1 20 nyc1 Ubuntu 16.04.2 x64 active 50513571 test-2 67.205.131.88 512 1 20 nyc1 Ubuntu 16.04.2 x64 active

创建资源 (Creating Resources)

Creating a resource requires longer commands with more detailed parameters. To create a Droplet, you’ll need to specify the image you want to use, the datacenter region, and the kind of Droplet you want by using its associated slug. See New Size Slugs for Droplet Plan Changes to find the slug you want to use. Alternatively, run the doctl compute size list command.

创建资源需要更长的命令以及更详细的参数。 要创建Droplet,您需要通过使用其关联的标签来指定要使用的图像,数据中心区域以及所需的Droplet类型。 请参阅“用于液滴计划更改的新大小的弹头以查找要使用的弹头。 或者,运行doctl compute size list命令。

For example, the following command creates a 64-bit Debian 8 Droplet named test with 1GB of memory, one CPU, an SSH key, and backups enabled.

例如,以下命令创建一个名为test的64位Debian 8 Droplet,具有1GB内存,一个CPU,一个SSH密钥和启用的备份。

  • doctl compute droplet create test --size s-1vcpu-1gb --image debian-8-x64 --region nyc1 --ssh-keys 4d:23:e6:e4:8c:17:d2:cf:89:47:36:b5:c7:33:40:4e --enable-backups

    doctl计算液滴创建测试 --size s-1vcpu-1gb --image debian-8-x64-区域nyc1 --ssh-keys 4d:23:e6:e4:8c:17:d2:cf:89:47: 36:b5:c7:33:40:4e-启用备份

You’ll see this output:

您将看到以下输出:


   
   
Sample Droplet creation output
ID Name Public IPv4 Memory VCPUs Disk Region Image Status 11450164 test 1024 1 30 nyc1 Debian 8.3 x64 new

Deleting a resource requires a resource ID as an argument, or a resource name in the event that an ID doesn’t exist for given resource (e.g. tags). To confirm your intentions, you need to confirm all delete actions by answering the confirmation question with y or yes.

删除资源需要使用资源ID作为自变量,或者在给定资源(例如标签)不存在ID的情况下使用资源名称。 为了确认您的意图,您需要通过使用yyes回答确认问题来确认所有删除操作。

doctl compute droplet delete 123456

   
   
Output
Warning: Are you sure you want to delete droplet(s) (y/N) ?

Not providing an answer or providing an answer different from y or yes will cancel the action without deleting the resource. You can make doctl assume an affirmative answer without explicitly providing it, using --f (--force) flag:

不提供答案或提供与yyes不同的答案将取消操作而不删除资源。 您可以使用--f (-- --force )标志使doctl假定肯定的答案而无需明确提供它:

doctl compute droplet delete -f 123456

查找资源的唯一标识符 (Finding Unique Identifiers for Resources)

The Droplet creation command requires a series of identifiers, like nyc1 for the NYC1 region, debian-8-x64 for the Debian image, and an SSH key fingerprint like 4d:23:e6:e4:8c:17:d2:cf:89:47:36:b5:c7:33:40:4e.

Droplet创建命令需要一系列标识符,例如nyc1区域的nyc1,Debian图像的debian-8-x64以及SSH密钥指纹,例如4d:23:e6:e4:8c:17:d2:cf:89:47:36:b5:c7:33:40:4e

A number of resources, such as Droplets and images, are identified by a value (often numeric) unique within DigitalOcean’s database.

通过DigitalOcean数据库中唯一的值(通常是数字)来标识诸如Droplet和图像之类的许多资源。

You can get the required unique identifiers for most commands from the API:

您可以从API获取大多数命令所需的唯一标识符:

CommandNotes
doctl compute droplet listYour Droplets. Some commands also take the name; most require the numeric value from the ID column.
doctl compute ssh-key listThe SSH keys associated with your account. For Droplet creation, you can specify either the numeric ID or fingerprint.
doctl compute region listAvailable regions. Use the string in the Slug column.
doctl compute image listAvailable images, including snapshots, backups, and base distribution images. Use the string in the Slug column for creating new Droplets.
doctl compute size listAvailable Droplet sizes. Use the string in the Slug column.
doctl compute tag listAvailable Tags. Use the string in the Name column.
命令 笔记
doctl compute droplet list 您的水滴。 有些命令也使用该名称。 最需要ID列中的数字值。
doctl compute ssh-key list 与您的帐户关联的SSH密钥。 对于Droplet创建,您可以指定数字ID指纹
doctl compute region list 可用区域。 使用“ 子弹”列中的字符串。
doctl compute image list 可用映像,包括快照,备份和基本分发映像。 使用“ 子弹”列中的字符串来创建新的Droplet。
doctl compute size list 可用的液滴尺寸。 使用“ 子弹”列中的字符串。
doctl compute tag list 可用标签。 使用“ 名称”列中的字符串。

使用液滴 (Working with Droplets)

创建,删除和检查液滴 (Creating, Deleting, and Inspecting Droplets)

The doctl compute droplet command lets you create, delete, and inspect Droplets. Again, most commands for working with individual Droplets require the Droplet’s unique ID, and these can be found in the output from doctl droplet list.

doctl compute droplet命令使您可以创建,删除和检查Droplet。 同样,大多数用于处理各个Droplet的命令都需要Droplet的唯一ID,这些命令可以在doctl droplet list的输出中找到。

doctl compute droplet subcommandNotes
actions droplet_idDisplay a history of actions taken for a Droplet.
backups droplet_idList backups for a Droplet.
create name --size s-1vcpu-1gb --image image_slug --region nyc1Create a Droplet. Size, image and region are all mandatory.
delete droplet_id_or_nameDelete a Droplet by id or name.
get droplet_idGet details for a particular Droplet.
kernels droplet_idList kernels for a Droplet.
listList your current Droplets.
neighbors droplet_idList your Droplets running on the same physical hardware as a specific Droplet.
snapshots droplet_idList snapshots for a Droplet.
tag droplet_id/droplet_nameTag a Droplet.
untag droplet_id/droplet_nameUntag a Droplet.
doctl compute droplet子命令 笔记
actions droplet_id 显示对Droplet采取的操作的历史记录。
backups droplet_id 列出Droplet的备份。
create name --size s-1vcpu-1gb --image image_slug --region nyc1 创建一个Droplet。 大小,图像和区域都是必填项。
delete droplet_id_or_name 通过ID或名称删除Droplet。
get droplet_id 获取特定Droplet的详细信息。
kernels droplet_id 列出Droplet的内核。
list 列出您当前的Droplet。
neighbors droplet_id 列出与特定Droplet在相同物理硬件上运行的Droplet。
snapshots droplet_id 列出Droplet的快照。
tag droplet_id/droplet_name 标记一个Droplet。
untag droplet_id/droplet_name 取消标记液滴。

启动液滴动作 (Initiating Droplet Actions)

The doctl compute droplet-action command lets you trigger various actions for a Droplet, including power management actions and toggling features like backups and private networking.

doctl compute droplet-action命令可让您触发Droplet的各种操作,包括电源管理操作和切换功能,例如备份和专用网络。

doctl compute droplet-action subcommandNotes
get droplet_id --action-id action_idGet details about action on a Droplet.
disable-backups droplet_idDisable backups for a Droplet.
reboot droplet_idReboot a Droplet.
power-cycle droplet_idTurn a Droplet off and back on again.
shutdown droplet_idShut down a Droplet.
power-off droplet_idPower off a Droplet. The Droplet must be powered on. It’s usually best to do this from the command line of the Droplet itself in order to prevent data loss.
power-on droplet_idPower on a Droplet. The Droplet must be powered off.
power-reset droplet_idPower reset Droplet.
enable-ipv6 droplet_idEnable ipv6 for a Droplet.
enable-private-networking droplet_idEnable private networking for a Droplet.
upgrade droplet_idUpgrade a Droplet.
restore droplet_id --image-id image_idRestore a Droplet to a specific backup image. The image_id must be a backup of the Droplet.
resize droplet_id --size 2gbResize a Droplet. The Droplet must be powered off. By default, disk is not resized, which allows Droplet to be downgraded. You can resize disk using the --resize-disk flag.
rebuild droplet_id --image-id image_idRebuild a Droplet from a specific image.
rename droplet_id --droplet-name new_nameRename a Droplet to new_name.
change-kernel droplet_id --kernel-id kernel_idChange a Droplet’s kernel to kernel_id.
snapshot droplet_id --snapshot-name snapshot_nameTake a snapshot of a Droplet, naming it snapshot_name.
doctl compute droplet-action子命令 笔记
get droplet_id --action-id action_id 获取有关在Droplet上执行操作的详细信息。
disable-backups droplet_id 禁用Droplet的备份。
reboot droplet_id 重新启动Droplet。
power-cycle droplet_id 关闭Droplet,然后再次打开。
shutdown droplet_id 关闭一个Droplet。
power-off droplet_id 关闭Droplet电源。 Droplet必须已打开电源。 通常最好从Droplet本身的命令行执行此操作,以防止数据丢失。
power-on droplet_id 开启液滴。 液滴必须关闭电源。
power-reset droplet_id 电源重置液滴。
enable-ipv6 droplet_id 为Droplet启用ipv6。
enable-private-networking droplet_id 为Droplet启用专用网络
upgrade droplet_id 升级Droplet。
restore droplet_id --image-id image_id 将Droplet还原到特定的备份映像。 image_id必须是Droplet的备份。
resize droplet_id --size 2gb 调整液滴大小。 液滴必须关闭电源。 默认情况下,不调整磁盘大小,这允许降级Droplet。 您可以使用--resize-disk标志来调整磁盘大小。
rebuild droplet_id --image-id image_id 从特定图像重建液滴。
rename droplet_id --droplet-name new_name 将Droplet重命名为new_name
change-kernel droplet_id --kernel-id kernel_id 将Droplet的内核更改为kernel_id
snapshot droplet_id --snapshot-name snapshot_name 拍摄Droplet的快照,并将其命名为snapshot_name

使用SSH (Working with SSH)

建立SSH连接 (Making SSH Connections)

In order to connect to an individual Droplet with SSH, it’s usually necessary to know either its IP address or fully-qualified domain name. You can instead use doctl to connect to a Droplet by its name, numeric ID or Private IP:

为了使用SSH连接到单个Droplet,通常必须知道其IP地址或完全合格的域名。 您可以改为使用doctl通过其名称,数字ID或专用IP连接到Droplet:

  • doctl compute ssh droplet_name

    doctl计算sshdroplet_name

  • doctl compute ssh droplet_id

    doctl计算sshdroplet_id

  • doctl compute ssh --ssh-private-ip droplet_private_ip

    doctl计算ssh --ssh-private-ip drop_private_ip

Also, you can provide a command to execute once the SSH connection is established using the --ssh-command flag. This will run the command, the output of which will be printed on your local terminal, and then the SSH session will close.

另外,您可以使用--ssh-command标志提供建立SSH连接后要执行--ssh-command 。 这将运行命令,该命令的输出将打印在您的本地终端上,然后SSH会话将关闭。

  • doctl compute ssh --ssh-command command

    doctl compute ssh --ssh-command 命令

Note: SSH command forwarding is currently not available on Windows.

注意 :SSH命令转发当前在Windows上不可用。

The default SSH user name is root (core for CoreOS) and the default port is 22. You can use flags to set non-default values and enable other features:

默认的SSH用户名是root (CoreOS的核心 ),默认端口是22 。 您可以使用标志来设置非默认值并启用其他功能:

FlagDescription
--ssh-user stringUser name to use for the SSH session.
--ssh-port intThe port for the SSH session.
--ssh-key-path stringPath to SSH key.
--ssh-agent-forwardingEnable agent forwarding.
描述
--ssh-user string SSH会话使用的用户名。
--ssh-port int SSH会话的端口。
--ssh-key-path string SSH密钥的路径。
--ssh-agent-forwarding 启用代理转发。

You can also change the default configuration values in a configuration file. The project’s README file has more detail on how to do this.

您还可以在配置文件中更改默认配置值。 该项目的README文件具有有关如何执行此操作的更多详细信息。

使用SSH密钥 (Using SSH Keys)

You can manage the SSH public keys associated with your account using the doctl compute ssh-key command. Most commands which reference SSH keys accept either the numeric ID for the key or its fingerprint.

您可以使用doctl compute ssh-key命令管理与您的帐户关联的SSH doctl compute ssh-key 。 大多数引用SSH密钥的命令都接受密钥的数字ID或其指纹。

doctl compute ssh-key subcommandNotes
listList SSH keys associated with your account.
get ssh_key_id_or_fingerprintGet info on a specific key, by numeric ID or key’s fingerprint.
create new_key_name --public-key "public_key"Associate a public key with your account by specifying its contents.
import new_key_name --public-key-file ~/.ssh/id_rsa.pubAssociate a public key with your account by specifying a source file.
delete ssh_key_id_or_fingerprintDelete a key from your account by numeric ID or fingerprint.
update ssh_key_id_or_fingerprint --key-name new_key_nameChange a key’s name by numeric ID or fingerprint.
doctl compute ssh-key子命令 笔记
list 列出与您的帐户关联的SSH密钥。
get ssh_key_id_or_fingerprint 通过数字ID或键的指纹获取有关特定键的信息。
create new_key_name --public-key " public_key " 通过指定公共密钥的内容将其与您的帐户关联。
import new_key_name --public-key-file ~/.ssh/id_rsa.pub 通过指定源文件将公钥与您的帐户关联。
delete ssh_key_id_or_fingerprint 通过数字ID或指纹从您的帐户中删除密钥。
update ssh_key_id_or_fingerprint --key-name new_key_name 通过数字ID或指纹更改密钥的名称。

使用浮动IP (Working with Floating IPs)

A Floating IP is a publicly-accessible static IP address that can be assigned to one of your Droplets. For a detailed description of the feature, you can read How To Use Floating IPs on DigitalOcean. You can manipulate floating IPs with doctl compute floating-ip.

浮动IP是可以分配给您的Droplet之一的可公开访问的静态IP地址。 有关此功能的详细说明,您可以阅读如何在DigitalOcean上使用浮动IP 。 您可以使用doctl compute floating-ip操作浮动IP。

doctl compute floating-ip subcommandNotes
listList all Floating IP addresses.
get floating_ip_addressGet the details for a Floating IP address.
create --region nyc1Create a Floating IP in nyc1 region.
delete floating_ip_addressDelete a floating IP address.
doctl compute floating-ip子命令 笔记
list 列出所有浮动IP地址。
get floating_ip_address 获取浮动IP地址的详细信息。
create --region nyc1 nyc1区域中创建一个浮动IP。
delete floating_ip_address 删除浮动IP地址。

将浮动IP分配给液滴 (Assigning Floating IPs to Droplets)

The doctl compute floating-ip-action command is used to assign or unassign a Floating IP from a Droplet.

doctl compute floating-ip-action命令用于从Droplet分配或doctl compute floating-ip-action分配Floating IP。

doctl compute floating-ip-action subcommandNotes
assign floating_ip droplet_idAssign a Floating IP to the Droplet by its numeric ID.
unassign floating_ipUnassign a Floating IP.
get floating_ip action_idGet details about a Floating IP action by its numeric ID.
doctl compute floating-ip-action子命令 笔记
assign floating_ip droplet_id 通过其数字ID将浮动IP分配给Droplet。
unassign floating_ip 取消分配浮动IP。
get floating_ip action_id 通过其数字ID获取有关浮动IP操作的详细信息。

使用域 (Working with Domains)

The doctl compute domain command is used to manage domains. See our Introduction to Managing DNS series for a broad overview of the subject.

doctl compute domain命令用于管理域。 有关该主题的广泛概述,请参见我们的DNS管理简介系列

doctl compute domain subcommandNotes
listList domains.
create domain_name --ip-address droplet_ip_addressCreate a domain with default records for droplet_ip_address.
get domain_nameGet a domain record.
delete domain_nameDelete a domain.
doctl compute domain子命令 笔记
list 列出域。
create domain_name --ip-address droplet_ip_address 创建一个域,其默认记录为droplet_ip_address
get domain_name 获取域记录。
delete domain_name 删除域。

管理域记录 (Managing Domain Records)

The doctl compute domain records command can be used to create, delete, update or get information about domain’s DNS records.

doctl compute domain records命令可用于创建,删除,更新或获取有关域的DNS记录的信息。

doctl compute domain records subcommandNotes
list domain_nameList records for given domain.
create domain_name --record-type record_typeCreate an record for domain.
delete domain_name record_idDelete record by numeric ID.
update domain_name --record-id record_idUpdate record by numeric ID.
doctl compute domain records子命令 笔记
list domain_name 列出给定域的记录。
create domain_name --record-type record_type 创建域记录。
delete domain_name record_id 通过数字ID删除记录。
update domain_name --record-id record_id 通过数字ID更新记录。

使用块存储卷 (Working with Block Storage Volumes)

创建,删除和检查块存储卷 (Creating, Deleting, and Inspecting Block Storage Volumes)

The doctl compute volume command can be used to create, delete, or get information about DigitalOcean’s Block Storage volumes. For more information about this feature, read our guide on How To Use Block Storage on DigitalOcean.

doctl compute volume命令可用于创建,删除或获取有关DigitalOcean的块存储卷的信息。 有关此功能的更多信息,请阅读有关如何在DigitalOcean使用块存储的指南。

doctl compute volume subcommandNotes
listList volumes.
create volume_name --region volume_region --size volume_sizeCreate a volume. The name, region, and size are mandatory.
get volume_IDGet volume by numeric ID.
delete volume_IDDelete volume.
snapshot volume_IDSnapshot volume.
doctl compute volume命令 笔记
list 列出卷。
create volume_name --region volume_region --size volume_size 创建一个卷。 名称,区域和大小是强制性的。
get volume_ID 通过数字ID获取音量。
delete volume_ID 删除音量。
snapshot volume_ID 快照量。

启动音量动作 (Initiating Volume Actions)

The doctl compute volume-action command lets you trigger actions for a volume, including attaching volumes to and detaching volumes from Droplets.

doctl compute volume-action命令使您可以触发doctl compute volume-action ,包括将卷附加到Droplet或从Droplet分离卷。

doctl compute volume-action subcommandNotes
attach volume_id droplet_idAttach a volume to a Droplet.
detach volume_id droplet_idDetach a volume from a Droplet.
resize volume_id --region volume_region --size new_sizeResize a volume.
doctl compute volume-action子命令 笔记
attach volume_id droplet_id 将卷附加到Droplet。
detach volume_id droplet_id 从Droplet上分离一个体积。
resize volume_id --region volume_region --size new_size 调整音量。

使用负载均衡器 (Working with Load Balancers)

The doctl compute load-balancer command can be used to create, delete, or get information about DigitalOcean’s Load Balancers. For more information about this feature, read our Introduction to DigitalOcean Load Balancers.

doctl compute load-balancer命令可用于创建,删除或获取有关DigitalOcean的Load Balancer的信息。 有关此功能的更多信息,请阅读我们的DigitalOcean负载均衡器简介

doctl compute load-balancer subcommandNotes
listList load balancers.
create --name lb_name --region lb_region --tag-name tag_name --forwarding-rules forwarding_ruleCreate a Load Balancer. The name, region, a tag or list of Droplet IDs, and at least one forwarding rule are mandatory.
update --name lb_name --region lb_region --tag-name tag_name --forwarding-rules forwarding_ruleCreate a Load Balancer. The name, region, a tag or list of Droplet IDs, and at least one forwarding rule are mandatory.
get lb_IDGet a load balancer.
delete lb_IDDelete a load balancer.
add-droplets lb_ID --droplet-ids droplet_IDAdd Droplets to a load balancer.
remove-droplets lb_ID --droplet-ids droplet_IDRemove Droplets from a load balancer.
add-forwarding-rules lb_ID --forwarding-rules forwarding_ruleAdd forwarding rules to a load balancer.
remove-forwarding-rules lb_ID --forwarding-rules forwarding_ruleRemove forwarding rules from a load balancer.
doctl compute load-balancer子命令 笔记
list 列出负载均衡器。
create --name lb_name --region lb_region --tag-name tag_name --forwarding-rules forwarding_rule 创建一个负载均衡器。 必须输入Droplet ID的名称,区域,标签或列表,以及至少一个转发规则。
update --name lb_name --region lb_region --tag-name tag_name --forwarding-rules forwarding_rule 创建一个负载均衡器。 必须输入Droplet ID的名称,区域,标签或列表,以及至少一个转发规则。
get lb_ID 获取负载均衡器。
delete lb_ID 删除负载均衡器。
add-droplets lb_ID --droplet-ids droplet_ID 将Droplet添加到负载均衡器。
remove-droplets lb_ID --droplet-ids droplet_ID 从负载均衡器中删除液滴。
add-forwarding-rules lb_ID --forwarding-rules forwarding_rule 将转发规则添加到负载均衡器。
remove-forwarding-rules lb_ID --forwarding-rules forwarding_rule 从负载均衡器中删除转发规则。

When used as an argument to doctl, forwarding rules should be expressed like: entry_protocol:protocol,entry_port:port,target_protocol:protocol,target_port:port.

当用作doctl的参数时,转发规则应表示为: entry_protocol: protocol ,entry_port: port ,target_protocol: protocol ,target_port: port

管理证书 (Managing Certificates)

The doctl compute certificate subcommand allows you to upload and manage SSL certificates, private keys, and certificate chains.

doctl compute certificate子命令允许您上载和管理SSL证书,私钥和证书链。

doctl compute certificate subcommandNotes
listList all Certificates.
get certificate_idGet a Certificate by ID.
create --name certificate_name --leaf-certificate-path leaf_certificate_pathCreate a Certificate. Name and Leaf Certificate Path are mandatory.
delete certificate_idDelete a Certificate by ID.
doctl compute certificate子命令 笔记
list 列出所有证书。
get certificate_id 通过ID获取证书。
create --name certificate_name --leaf-certificate-path leaf_certificate_path 创建一个证书。 名称和叶子证书路径是必填项。
delete certificate_id 通过ID删除证书。

使用快照 (Working with Snapshots)

The doctl compute snapshot command can be used to list, delete, or get information about Droplet and Volume Snapshots.

doctl compute snapshot命令可用于列出,删除或获取有关Droplet和卷快照的信息。

doctl compute snapshot subcommandNotes
listList all Snapshots.
get snapshot_IDGet a Snapshot.
delete snapshot_IDDelete a Snapshot.
doctl compute snapshot子命令 笔记
list 列出所有快照。
get snapshot_ID 获取快照。
delete snapshot_ID 删除快照。

To create a new Snapshot, you need to use the appropriate command under the relevant resource command tree. For example:

要创建新的快照,您需要在相关资源命令树下使用适当的命令。 例如:

  • doctl compute droplet-action snapshot droplet_ID creates a Snapshot from a Droplet.

    doctl compute droplet-action snapshot droplet_ID从Droplet创建快照。

  • doctl compute volume snapshot volume_ID creates a Snapshot from a Volume.

    doctl compute volume snapshot volume_ID从卷创建快照。

处理图像 (Working with Images)

The doctl compute image command allows you to manage all images, including distribution images, application images, and user-created images such as backups and snapshots. We recommend using the snapshot command for managing snapshots because it provides more detail, has delete functionality, and supports Block Storage snapshots.

doctl compute image命令允许您管理所有映像,包括分发映像,应用程序映像和用户创建的映像(例如备份和快照)。 我们建议使用snapshot命令来管理快照,因为它提供了更多详细信息,具有删除功能并支持块存储快照。

doctl compute image subcommandNotes
list --publicList all images.
list-distribution --publicList all available distribution images.
list-application --publicList all available One-Click Applications.
list-userList all user-created images.
get image_idGet an Image by ID.
update image_id --name image_nameUpdate Image’s name. Name is mandatory.
delete image_idDelete an Image by ID.
doctl compute image子命令 笔记
list --public 列出所有图像。
list-distribution --public 列出所有可用的分发映像。
list-application --public 列出所有可用的一键式应用程序
list-user 列出所有用户创建的图像。
get image_id 通过ID获取图像。
update image_id --name image_name 更新图像的名称。 名称是必填项。
delete image_id 按ID删除图像。

调用图像动作 (Invoking Image Actions)

The doctl compute image-action command allows you to transfer images and get details about actions invoked on images.

doctl compute image-action命令允许您传输图像并获取有关在图像上调用的操作的详细信息。

doctl compute image-action subcommandNotes
get image_id --action-id action_idGet an Action for Image by its ID. Action ID is mandatory.
transfer image_id --region regionTransfer an Image to the another region. Image ID and region are mandatory.
doctl compute image-action子命令 笔记
get image_id --action-id action_id 通过其ID获取图像操作。 动作ID是必填项。
transfer image_id --region region 将图像传输到另一个区域。 图片ID和区域是必填项。

使用防火墙 (Working with Firewalls)

The doctl compute firewall command lets you create and manage Firewalls, including creating and maintaining rules. For more about information about administering Firewalls using doctl, check out the How To Secure Web Server Infrastructure With DigitalOcean Cloud Firewalls Using Doctl tutorial.

doctl compute firewall命令可让您创建和管理防火墙,包括创建和维护规则。 有关使用doctl管理防火墙的更多信息,请查看如何使用DigitalOcean Cloud Doctl使用防火墙保护Web服务器基础结构教程。

doctl compute firewall commandNotes
listList all Firewalls.
list-by-droplet droplet_idList all Firewalls by Droplet’s numeric ID.
create --name firewall_name --inbound-rules inbound_rules --outbound-rules outbound_rulesCreate a Firewall. The name and at least an inbound or outbound rule are mandatory.
update firewall_id --name firewall_name --inbound-rules inbound_rules --outbound-rules outbound_rulesUpdate a Firewall. The numeric ID, name and at least an inbound or outbound rule are mandatory.
get firewall_idGet a Firewall by its numeric ID.
delete firewall_idDelete a Firewall by numeric ID.
add-droplets firewall_id --droplet-ids droplet_IDsAdd Droplets by their numeric ID to the Firewall.
remove-droplets firewall_id --droplet-ids droplet_IDsRemove Droplets from the Firewall by their numeric IDs.
add-tags firewall_id --tag-names tagsAdd Tags to the Firewall.
remove-tags firewall_id --tag-names tagsRemove Tags from the Firewall.
add-rules firewall_id --inbound-rules inbound_rules --outbound-rules outbound_rulesAdd inbound or outbound rules to the Firewall.
remove-rules firewall_id --inbound-rules inbound_rules --outbound-rules outbound_rulesRemove inbound or outbound rules to the Firewall.
doctl compute firewall命令 笔记
list 列出所有防火墙。
list-by-droplet droplet_id 按Droplet的数字ID列出所有防火墙。
create --name firewall_name --inbound-rules inbound_rules --outbound-rules outbound_rules 创建防火墙。 名称和至少一个入站或出站规则是强制性的。
update firewall_id --name firewall_name --inbound-rules inbound_rules --outbound-rules outbound_rules 更新防火墙。 数字ID,名称和至少一个入站或出站规则是强制性的。
get firewall_id 通过其数字ID获取防火墙。
delete firewall_id 通过数字ID删除防火墙。
add-droplets firewall_id --droplet-ids droplet_IDs 通过数字ID将Droplet添加到防火墙。
remove-droplets firewall_id --droplet-ids droplet_IDs 通过其数字ID从防火墙中删除Droplet。
add-tags firewall_id --tag-names tags 将标签添加到防火墙。
remove-tags firewall_id --tag-names tags 从防火墙中删除标签。
add-rules firewall_id --inbound-rules inbound_rules --outbound-rules outbound_rules 将入站或出站规则添加到防火墙。
remove-rules firewall_id --inbound-rules inbound_rules --outbound-rules outbound_rules 将入站或出站规则删除到防火墙。

When used as an argument to doctl, inbound or outbound rules should be expressed like: protocol:protocol,ports:ports,droplet_id:droplet-id.

当用作doctl的参数时,入站或出站规则应表示为: protocol: protocol ,ports: ports ,droplet_id: droplet-id

使用标签 (Working with Tags)

Tags are used to apply custom labels to resources, allowing you to easily filter them. You can learn more about Tags in the How To Tag DigitalOcean Droplets tutorial.

标签用于将自定义标签应用于资源,从而使您轻松过滤它们。 您可以在如何标记DigitalOcean Droplet教程中了解有关标记的更多信息。

doctl compute tag subcommandNotes
create tag_nameCreate a Tag.
get tag_nameGet a Tag by name.
listList all Tags.
delete tag_nameDelete a Tag by name.
doctl compute tag子命令 笔记
create tag_name 创建一个标签。
get tag_name 按名称获取标签。
list 列出所有标签。
delete tag_name 按名称删除标签。

使用您的帐户 (Working with Your Account)

阅读您帐户的操作历史记录 (Reading History of Actions for Your Account)

The DigitalOcean system logs a history of the actions taken on your Droplets, Floating IPs, and other resources. You can access this data with the doctl compute action command:

DigitalOcean系统记录对Droplet,浮动IP和其他资源执行的操作的历史记录。 您可以使用doctl compute action命令访问此数据:

  • doctl compute action list

    doctl计算动作列表

You can see actions for a specific Droplet like so:

您可以看到特定Droplet的操作,如下所示:

  • doctl compute droplet actions droplet_id

    doctl计算液滴动作drop_id

检索您的帐户信息 (Retrieving Your Account Information)

You can discover basic details about your account, such as your configured e-mail address and Droplet limit:

您可以发现有关帐户的基本详细信息,例如配置的电子邮件地址和Droplet限制:

  • doctl account get

    doctl帐户获取

Because API requests are rate-limited, it may be helpful to see how many requests you’ve made recently, and when the limit is due to reset:

由于API请求受到速率的限制,因此查看最近发出的请求数量以及该限制的到期时间可能会有所帮助:

  • doctl account ratelimit

    doctl帐户利率限制

结论 (Conclusion)

The doctl utility is a helpful tool for managing Droplets and other resources at the command line. It can greatly reduce the amount of manual interaction with web-based interfaces needed for daily development and administrative tasks.

doctl实用程序是在命令行管理Droplet和其他资源的有用工具。 它可以大大减少与日常开发和管理任务所需的与基于Web的界面进行手动交互的数量。

In addition to learning about the underlying API, you may want to explore libraries which wrap the API for popular programming languages, and tools such as Ansible for automating system-level tasks.

除了了解基础API之外 ,您可能还想探索包装了流行编程语言的API的库 ,以及诸如Ansible之类的用于自动化系统级任务的工具。

翻译自: https://www.digitalocean.com/community/tutorials/how-to-use-doctl-the-official-digitalocean-command-line-client

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值