常用公有云接入——阿里
生活随笔
收集整理的這篇文章主要介紹了
常用公有云接入——阿里
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
一、術語
| 地域 | Region | 阿里云建設的數據中心。資源創建成功后無法更換地域。 |
| 可用區 | Zone | 同一地域內,電力和網絡互相獨立的物理數據中心。一個地域下可以有多個可用區。同一地域內可用區之間內網互通并且故障隔離,云服務器 ECS 網絡延時低。 |
| 實例 | Instance | 采用虛擬化技術從阿里云物理服務器上虛擬出來的虛擬機,是一臺云服務器 ECS 的基本計算單位。更多詳情,請參閱?實例規格族。 |
| 鏡像 | Image | 簡稱鏡像,一般包含了操作系統和應用軟件。新建實例的系統盤數據完全拷貝鏡像,包括操作系統,軟件配置等。您可以使用鏡像初始化實例或者更換系統盤。 |
| 磁盤 | Disk | 云服務器 ECS 的存儲設備。 |
| 安全組 | Security group | 虛擬防火墻,一臺實例至少屬于一個安全組。 |
| 快照 | Snapshot | 為磁盤創建的數據還原點,包含特定時刻磁盤數據。快照可以用于還原磁盤數據或創建鏡像。 |
| 標簽 | Tag | 由一對鍵值對(Key-Value)組成,為資源綁定標簽便于快速篩選和分類。 |
| IP 地址 | IP address | 云服務器 ECS 的公網或者私網 IP 地址。 |
?
二、ECS創建方式
支持 HTTP 或者 HTTPS 請求,允許 GET 和 POST 方法。可以通過以下方式調用云服務器 ECS API:
- (推薦)不同編程語言的云服務器 ECS SDK
- 阿里云 CLI
- 阿里云 API Explorer
- API URL 請求
?
三、Java SDK
<!-- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-core --> <dependency><groupId>com.aliyun</groupId><artifactId>aliyun-java-sdk-core</artifactId><version>4.4.1</version> </dependency>阿里云SDK調試
1、創建實例
import com.aliyuncs.DefaultAcsClient; import com.aliyuncs.IAcsClient; import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.exceptions.ServerException; import com.aliyuncs.profile.DefaultProfile; import com.google.gson.Gson; import java.util.*; import com.aliyuncs.ecs.model.v20140526.*;public class EcsDemo {public static void main(String[] args) {DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");IAcsClient client = new DefaultAcsClient(profile);CreateInstanceRequest request = new CreateInstanceRequest();request.setInternetChargeType("22");request.setInstanceName("fir");request.setSecurityGroupId("sg-bp15ed6xe1yxeycg7ov3");request.setInstanceType("ecs.g5.large");request.setImageId("win2008r2_64_ent_sp1_en-us_40G_alibase_20170915.vhd");try {CreateInstanceResponse response = client.getAcsResponse(request);System.out.println(new Gson().toJson(response));} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {System.out.println("ErrCode:" + e.getErrCode());System.out.println("ErrMsg:" + e.getErrMsg());System.out.println("RequestId:" + e.getRequestId());}} }2、創建EIP
import com.aliyuncs.DefaultAcsClient; import com.aliyuncs.IAcsClient; import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.exceptions.ServerException; import com.aliyuncs.profile.DefaultProfile; import com.google.gson.Gson; import java.util.*; import com.aliyuncs.ecs.model.v20140526.*;public class EcsDemo {public static void main(String[] args) {DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");IAcsClient client = new DefaultAcsClient(profile);AllocateEipAddressRequest request = new AllocateEipAddressRequest();try {AllocateEipAddressResponse response = client.getAcsResponse(request);System.out.println(new Gson().toJson(response));} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {System.out.println("ErrCode:" + e.getErrCode());System.out.println("ErrMsg:" + e.getErrMsg());System.out.println("RequestId:" + e.getRequestId());}} }3、啟動實例
import com.aliyuncs.DefaultAcsClient; import com.aliyuncs.IAcsClient; import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.exceptions.ServerException; import com.aliyuncs.profile.DefaultProfile; import com.google.gson.Gson; import java.util.*; import com.aliyuncs.ecs.model.v20140526.*;public class EcsDemo {public static void main(String[] args) {DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "<accessKeyId>", "<accessSecret>");IAcsClient client = new DefaultAcsClient(profile);StartInstanceRequest request = new StartInstanceRequest();request.setInstanceId("i-sdoiwqnldsd");try {StartInstanceResponse response = client.getAcsResponse(request);System.out.println(new Gson().toJson(response));} catch (ServerException e) {e.printStackTrace();} catch (ClientException e) {System.out.println("ErrCode:" + e.getErrCode());System.out.println("ErrMsg:" + e.getErrMsg());System.out.println("RequestId:" + e.getRequestId());}} }?
?
四、REST API
API URL 請求需要自行驗證身份和編碼 URL。可以通過該方法了解阿里云訪問驗證流程。
創建AccessKey
請求結構
公共參數
簽名機制
返回結果
?
?
總結
以上是生活随笔為你收集整理的常用公有云接入——阿里的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何设置共享文件夹最全最详细怎么设置共享
- 下一篇: 三个好用的并发工具类