CentOS 7、Ubuntu 16.04、Debian 9にGolang 1.8.3をインストールする方法
GolangはGoogleが開発したプログラミング言語です。汎用性、シンプルさ、信頼性のおかげで、Golangは最も人気のあるものの1つになりました
このガイドでは、Vultr Goクライアントを使用してGoアプリケーションでVultrオブジェクトストレージを作成する方法について説明します。Vultr Object StorageはS3 APIと互換性があります。
Vultr囲碁クライアントはと対話するために使用されているVultrのAPI。Vultr APIを使用すると、Vultrオブジェクトストレージなど、アカウントに関連付けられたリソースを制御できます。Vultr Goクライアントの詳細については、この記事をご覧 ください。
現在のディレクトリにフォルダを作成します。
$ mkdir vultr_demo
新しいフォルダを入力します。
$ cd vultr_demo
$ go mod init vultr_demo
$ go get github.com/vultr/govultr
VULTR_API_KEY環境変数をAPIキーに設定します。APIキーは次の場所にあります:https : //my.vultr.com/settings/#settingsapi
警告:パスワードを保護するのと同じように、APIキーを保護してください。APIキーは、請求、サーバー、ストレージを含むアカウント全体にアクセスできます。
たとえば、Ubuntu Linuxでは、この行をに追加し~/.profile
ます。
export VULTR_API_KEY=YOUR_API_KEY_HERE
次の各コードフラグメントをという名前の新しいファイルに貼り付けますmain.go
。 完全なファイルもダウンロードできます。
パッケージをセットアップし、必要なライブラリをインポートします。
package main
import (
"context"
"log"
"os"
"time"
"github.com/vultr/govultr"
)
main()
関数を開始します。
func main() {
APIキーの環境変数を読み取ります。
var (
// Get our Vultr API Key from an environment variable.
VultrAPIKey = os.Getenv("VULTR_API_KEY")
)
Vultrクライアントを作成します。
// Create a Vultr client with our API Key.
vultr := govultr.NewClient(nil, VultrAPIKey)
Object Storageを作成する場所を指定します。クラスターの場所を取得し、使用できることを確認し、クラスターを選択して表示します。
// Find the clusters we can create our Object Storage in.
clusters, err := vultr.ObjectStorage.ListCluster(ctx)
if err != nil {
log.Fatalf("Error listing clusters: %s", err)
}
// Verify there's at least one cluster.
if len(clusters) < 1 {
log.Fatal("Could not find any clusters to create our Object Storage")
}
// Choose the first cluster, and print it.
cluster := clusters[0]
log.Printf("Chosen cluster: %+v", cluster)
選択したクラスターにオブジェクトストレージを作成します。
// Create our Object Storage in the first cluster listed with our custom label.
label := "my-object-storage"
storageID, err := vultr.ObjectStorage.Create(ctx, cluster.ObjectStoreClusterID, label)
if err != nil {
log.Fatalf("Error creating storage: %s", err)
}
log.Printf("Created our Object Storage with the ID: %d", storageID.ID)
オブジェクトストレージがアクティブになるまで待ちます。
var storage govultr.ObjectStorage
// Query the API every five seconds to until our server is ready.
for {
// List all of the Object Storage containers with our label and include the S3 credentials.
list, err := vultr.ObjectStorage.List(ctx, &govultr.ObjectListOptions{
Label: label,
IncludeS3: true,
})
if err != nil {
log.Fatalf("Error listing storage with label \"%s\": %s", label, err)
}
// Make sure we found one (and only one) Object Storage container.
if len(list) != 1 {
log.Fatalf("%d object storage containers exist with the label \"%s\"; we need 1", len(list), label)
}
storage = list[0]
// If the server is active, break out of this loop.
if storage.Status == "active" {
break
}
// Wait for five seconds before querying the API again.
log.Printf("The Object Storage's status is currently \"%s\", waiting for another five seconds to check if it's \"active\".", storage.Status)
time.Sleep(time.Second * 5)
}
エンドポイント名と接続資格情報を表示します。
// Print the information of our new Object Storage.
log.Print("Successfully created and listed our Object Storage!")
log.Printf("Object Storage: %+v", storage)
// We also have S3 credentials here now, so we could open an S3 compatible client.
log.Printf("S3 credentials: %s - %s - %s", storage.S3Hostname, storage.S3AccessKey, storage.S3SecretKey)
メイン関数を終了します。
// end main()
}
完成したmain.go
ファイルを保存して実行します。
go run main.go
2020/03/03 13:05:48 Chosen cluster: {ObjectStoreClusterID:2 RegionID:1 Location:New Jersey Hostname:ewr1.vultrobjects.com Deploy:yes}
2020/03/03 13:05:48 Created our Object Storage with the ID: xxxxxxxx
2020/03/03 13:05:49 The Object Storage's status is currently pending, waiting for another five seconds to check if it's active.
2020/03/03 13:06:06 Object Storage: {ID:34214512 DateCreated:2020-03-03 13:05:47 ObjectStoreClusterID:2 RegionID:1 Location:New Jersey Label:my-object-storage Status:active S3Keys:{S3Hostname:ewr1.vultrobjects.com S3AccessKey:[REDACTED ACCESS KEY] S3SecretKey:[REDACTED SECRET KEY]}}
2020/03/03 13:06:06 S3 credentials: ewr1.vultrobjects.com - [REDACTED ACCESS KEY] - [REDACTED SECRET KEY]
この例では、エンドポイント名はewr1.vultrobjects.comであり、キーは編集されています。Goプログラムで表示されるエンドポイント名、アクセスキー、シークレットキーを使用して、S3互換クライアントで新しいオブジェクトストレージにアクセスします。
GolangはGoogleが開発したプログラミング言語です。汎用性、シンプルさ、信頼性のおかげで、Golangは最も人気のあるものの1つになりました
Go(Golangとも呼ばれます)は、静的に型付けされ、コンパイルされた、Cのようなプログラミング言語で、Googleによって開発されました。シンプルさと多用途性により、b
GolangはGoogleによって開発されたプログラミング言語であり、Cの伝統を守りますが、シンプルさと安全性に重点を置いています。人気の言語になっています
Go(Golang)は、Googleで開発された最新のプログラミング言語であり、シンプルさと安全性を重視しています。server-sidで使用される一般的な言語になりました
要件UNIXの基本的な知識。NginxがインストールされたFreeBSD x64。インストールツールFreeBSDに同梱されていないプログラムがいくつか必要になります。ル
CentOS 7サーバーにApache 2.4をインストールする方法を説明します。安定したウェブサーバーを構築するための前提条件と手順を解説します。
FreeBSD 11.1におけるBlacklistdのインストール方法について詳しく解説します。この方法を通じて、強力なセキュリティ対策を実装できます。
サーバーマネージャーを使用して、Windows Serverの管理が向上します。セキュリティリスクを軽減し、効率的な管理を実現します。
CentOS 7にSeafileサーバーをインストールする方法。Seafile(コミュニティバージョン)は、ownCloudに似た無料のオープンソースファイル同期および共有ソリューションです。
Snortは無料のネットワーク侵入検知システムです。最新の方法で、SnortをDebianにインストールし、設定する手順を紹介します。ネットワークのセキュリティを強化しましょう。
CentOS 7にGraylogサーバーをインストールし、ログ管理を行う方法を学びます。
WindowsサーバーでWebサイトを実行している場合、電子メールも受信できるようにするためにhMailServerを使用する方法を解説します。
FiveMサーバーをUbuntu 19.04にインストールするための詳細なガイド。必要条件からインストール、起動、トラブルシューティングまで、すべてのステップを含みます。
Debian 10にWebDAVをデプロイする方法を学び、WsgiDAVとSSL証明書で安全な接続を実現しましょう。
ヘルスケアにおけるAIは、過去数十年から大きな飛躍を遂げました。したがって、ヘルスケアにおけるAIの未来は、日々成長を続けています。