Use the Linux Command Line to manage DigitalOcean VPS water drops
DigitalOcean is the most popular newborn in the cloud VPS host market. Although it does not provide integrated services like Amazon, DigitalOcean is positioned for small and medium-sized enterprises and developers and has become a strong competitor of the best cloud VPS Service Based on Linux, this is all due to their competitive prices and user-friendly management interfaces.
Whenever you need a network-oriented server for your personal project, you can start a nickname for the VPS instance in DigitalOcean at full speed ), you can also kill it when you don't need it. There's no need to burn your wallet to keep your VPS running. Although DigitalOcean's network-based management interface is very efficient, it still provides a drop-down management tool based on the command line interface, called tugboat, for those command line interfaces. Thanks to this command line tool, all complex water drop management tasks can be simply converted into a script.
In this article, I plan to describeHow to Use tugboat to manage DigitalOcean water drops from the command line.
Install tugboat on Linux
Install tugboat On Debian, Ubuntu, or Linux Mint:
- $ sudo apt-get install ruby-dev
- $ sudo gem install tugboat
Install tugboat on Fedora:
- $ sudo yum install ruby-devel
- $ sudo gem install tugboat
To install tugboat on CentOS, first install or upgrade to the latest Ruby version, because in CentOS 6.5 and earlier versions, the default Ruby version does not meet the minimum version 1.9 and later required by Tugboat ). After Ruby 1.9 and later are installed, install tugboat as follows.
- $ sudo gem install tugboat
Configuration for the first use of tugboat
After the installation is complete, configure it once, including authorizing tugboat to access the DigitalOcean account.
Go to https://cloud.digitalocean.com/api_accessand create a new API to record the customer ID and API secret.
Run the following command to start the authorization process:
- $ tugboat authorize
Enter the customer ID and API key when prompted. It will ask several other questions. Currently, you can accept the default answer. We will customize the default settings later.
Now, let's customize the default water drop settings to reflect your typical usage. To do this, first check the available settings provided by the Water Drop, such as available images, regions, and sizes ).
Run the following command to list available image drops. Select a default image and record the related ID.
- $ tugboat images --global
Similarly, select a default geographic location from the available region:
- $ tugboat regions
At the same time, select a default water drop size from the available RAM size:
- $ tugboat sizes
Now, place your default options in ~ /. Tugboat. For example, I have customized the default settings here: the region is in New York, the system is Ubuntu 14.04, and the memory is 512 MB. If you want to enable SSH Through key verification and set "ssh_user" to root, I will talk about it soon.
- $ vi ~/.tugboat
- ---
- authentication:
- client_key: XXXXXXXXXXXXXXXXXXX
- api_key: XXXXXXXXXXXXXXXXXXXX
- ssh:
- ssh_user: root
- ssh_key_path: /home/dev/.ssh/id_rsa
- ssh_port: '22'
- defaults:
- region: '4'
- image: '3240036'
- size: '66'
- ssh_key: ''
- private_networking: 'false'
- backups_enabled: 'false'
Create and add an SSH key to DigitalOcean
To access a water drop instance, a secure method is to connect to the instance through SSH key verification.
In fact, you can use DigitalOcean to register an SSH public key and automatically enable key verification for your water drop. The following shows how to do this.
First, generate a public/private key pair if you do not have one ).
- $ ssh-keygen -t rsa -C "your@emailaddress.com"
Assume that the generated key pair is from ~ /. Ssh/id_rsa Private Key) and ~ /. Ssh/id_rsa.pub Public Key) to upload your public key. The command is as follows:
- $ tugboat add-key [name-of-your-key]
You can name your key as needed, for example, "my-default-key "). When prompted, enter the Public Key Path, for example,/home/user/. ssh/id_rsa.pub ). After the key is uploaded, run the following command to verify that the key is correctly added:
- $ tugboat keys
The key should also appear on the DigitalOcean SSH key page. If you want the key to be automatically used in the Water Drop, add the key ID ~ /. Tugboat.
- ssh_key: '182710'
Basic usage of Tugboat
The basic usage of the tugboat command line is listed here.
-
Use the default settings to create a new water drop.
- $ tugboat create
-
Lists All active water drops.
- $ tugboat droplets
-
Displays the information of water drops.
- $ tugboat info
-
Close the Water Drop and remove the image.
- $ tugboat destroy
-
Close the water drop, but keep the image
- $ tugboat halt
-
Create a snapshot for the Water Drop. The water drop must be closed first.
- $ tugboat snapshot
-
Adjust the size of the Water Drop to increase or reduce the RAM size), the Water Drop must be disabled first.
- $ tugboat resize -s
If you want to know more options for a specific command, run:
- $ tugboat help <command>
Troubleshooting
Tugboat requires Ruby 1.9 and later. You need to upgrade Ruby to solve this problem. For CentOS, refer to this tutorial
The following error occurs when I try to install Tugboat using gem.
- /usr/local/share/ruby/site_ruby/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- json/pure (LoadError)
Install the following gem to fix the problem.
- $ sudo gem install json_pure