基于阿里云的基础架构设施保障(二)IAAS云存储
1. 云硬盤
HDD(普通云盤)
特征: 性能一般, IOPS大概在數(shù)百左右。
應(yīng)用場景: 數(shù)據(jù)不被經(jīng)常訪問或者低I/O負(fù)載的應(yīng)用場景,需要低成本并且有隨機(jī)讀寫I/O的應(yīng)用環(huán)境。
混合HDD(高效云盤)
特征: 結(jié)合HDD和SSD硬盤構(gòu)建, IOPS為1000~5000左右。
應(yīng)用場景: 開發(fā)與測試業(yè)務(wù)、系統(tǒng)盤。
SSD云盤
特征: 具有穩(wěn)定的IO能力, IOPS能夠達(dá)到10000~25000左右。
應(yīng)用場景:I/O密集型應(yīng)用、中小型關(guān)系數(shù)據(jù)庫、NoSQL數(shù)據(jù)庫。
企業(yè)級SSD(ESSD云盤)
特征: 優(yōu)化增強(qiáng)的SSD云盤, 一般是采用企業(yè)級的閃存硬件, IOPS能夠達(dá)到10000~1000000左右。
應(yīng)用場景: 大型OLTP數(shù)據(jù)庫等關(guān)系型數(shù)據(jù)庫、NoSQL數(shù)據(jù)庫、ELK分布式日志存儲等。
測試:
安裝fio工具
yum -y install fioiops測試
fio --name=disktest --filename=~/disktest --rw=randread --refill_buffers --bs=4k --size=1G -runtime=5 -direct=1 -iodepth=128 -ioengine=libaio輸出結(jié)果:
[root@iZm5egp1t778ocdk7f1j6fZ ~]# fio --name=disktest --filename=~/disktest --rw=randread --refill_buffers --bs=4k --size=1G -runtime=5 -direct=1 -iodepth=128 -ioengine=libaio disktest: (g=0): rw=randread, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=libaio, iodepth=128 fio-3.7 Starting 1 process Jobs: 1 (f=1): [r(1)][100.0%][r=8560KiB/s,w=0KiB/s][r=2140,w=0 IOPS][eta 00m:00s] disktest: (groupid=0, jobs=1): err= 0: pid=1417: Thu Nov 12 22:09:25 2020read: IOPS=2151, BW=8606KiB/s (8812kB/s)(42.3MiB/5032msec)slat (usec): min=2, max=166, avg= 6.54, stdev= 3.69clat (usec): min=794, max=157946, avg=59467.61, stdev=47971.33lat (usec): min=799, max=157950, avg=59474.73, stdev=47971.03clat percentiles (usec):| 1.00th=[ 1172], 5.00th=[ 1434], 10.00th=[ 1614], 20.00th=[ 1860],| 30.00th=[ 2147], 40.00th=[ 2999], 50.00th=[ 98042], 60.00th=[ 98042],| 70.00th=[ 99091], 80.00th=[ 99091], 90.00th=[ 99091], 95.00th=[100140],| 99.00th=[127402], 99.50th=[127402], 99.90th=[156238], 99.95th=[156238],| 99.99th=[158335]bw ( KiB/s): min= 8544, max= 8560, per=99.46%, avg=8558.40, stdev= 5.06, samples=10iops : min= 2136, max= 2140, avg=2139.60, stdev= 1.26, samples=10lat (usec) : 1000=0.16%lat (msec) : 2=25.15%, 4=15.13%, 10=0.03%, 50=0.59%, 100=56.23%lat (msec) : 250=2.71%cpu : usr=0.58%, sys=1.93%, ctx=1154, majf=0, minf=163IO depths : 1=0.1%, 2=0.1%, 4=0.1%, 8=0.1%, 16=0.1%, 32=0.3%, >=64=99.4%submit : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%complete : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.1%issued rwts: total=10826,0,0,0 short=0,0,0,0 dropped=0,0,0,0latency : target=0, window=0, percentile=100.00%, depth=128Run status group 0 (all jobs):READ: bw=8606KiB/s (8812kB/s), 8606KiB/s-8606KiB/s (8812kB/s-8812kB/s), io=42.3MiB (44.3MB), run=5032-5032msecDisk stats (read/write):vda: ios=10486/0, merge=0/1, ticks=614779/0, in_queue=485314, util=75.89%iops平均達(dá)到2139.60,與高效云盤標(biāo)示的2120基本是一致。
也可以掛在動(dòng)態(tài)硬盤進(jìn)行測試, 不同的類型和存儲空間, IOPS是不一樣:
2. 對象存儲
Amazon S3 vs 阿里云 OSS
Amazon S3,全稱亞馬遜簡易存儲服務(wù)(Amazon Simple Storage Service)
阿里云 OSS(Object Storage Service,簡稱OSS),是阿里云對外提供的海量、安全、低成本、高可靠的云存儲服務(wù)。
對比:
| 存儲對象 | 對象 | 對象 |
| 對象ACL | 支持 | 支持 |
| 最大對象大小 | 5T | 48.8T |
| 數(shù)據(jù)可靠性 | 99.999999999(11個(gè)9) | 99.999999999(11個(gè)9) |
| 對象元數(shù)據(jù) | 元數(shù)據(jù) | 對象元 |
| 對象生命周期管理 | 支持 | 支持 |
| 對象版本控制 | 支持 | 支持(可選) |
| 更新事件通知 | 支持 | 支持 |
| 跨地域復(fù)制 | 支持 | 支持 |
| 對象追加寫入 | 不支持 | 支持 |
| 并行或分段上傳 | 支持 | 支持 |
| 高一致性 | 支持 | 支持 |
| 數(shù)據(jù)加密 | 在客戶端和服務(wù)端加密 | 在客戶端和服務(wù)端加密 |
| 請求協(xié)議 | HTTP/HTTPS | HTTP/HTTPS/Bit Torrent |
| 圖片處理 | 不支持 | 支持 |
對象存儲VS云硬盤
提供接口訪問
對象存儲本質(zhì)是一個(gè)網(wǎng)絡(luò)化的服務(wù), 云硬盤是掛載到虛擬機(jī)的虛擬硬盤,必須連接到虛擬機(jī)才能操作。
存儲結(jié)構(gòu)不一致
云硬盤是一個(gè)可以作為一個(gè)真正的文件系統(tǒng), 而云存儲是一個(gè)近似鍵值(key和value)的存儲服務(wù)。
海量數(shù)據(jù)存儲
云硬盤一般會(huì)受自身容量的限制, 不能支撐海量數(shù)據(jù)存儲, 對象存儲得益于其底層設(shè)計(jì), 天生就能夠支撐大數(shù)據(jù)存儲。對象存儲服務(wù)不僅可以支持海量的小文件, 也適合處理大型文件。
實(shí)踐操作
流程:
開通OSS服務(wù)OSS產(chǎn)品詳情頁
創(chuàng)建存儲空間, Bucket名稱要具備唯一性。
開通對應(yīng)的訪問權(quán)限
不要采用主賬號,會(huì)存在安全隱患, 授權(quán)給RAM用戶。
添加依賴
<dependency><groupId>com.aliyun.oss</groupId><artifactId>aliyun-sdk-oss</artifactId><version>3.10.2</version> </dependency>上傳文件
UploadApplication:
public class UploadApplication {public static void main(String[] args) throws Exception{// 創(chuàng)建OSSClient實(shí)例。OSS ossClient = new OSSClientBuilder().build(Constants.endpoint, Constants.accessKeyId, Constants.accessKeySecret);// 創(chuàng)建PutObjectRequest對象。PutObjectRequest putObjectRequest = new PutObjectRequest(Constants.bucketName, "readme", new File("d:/readme.txt"));// 上傳文件。PutObjectResult result = ossClient.putObject(putObjectRequest);System.out.println("upload complete.");// 關(guān)閉OSSClient。ossClient.shutdown();} }下載文件
DownloadApplication:
public class DownloadApplication {public static void main(String[] args) {// Endpoint以杭州為例,其它Region請按實(shí)際情況填寫。String endpoint = Constants.endpoint;// 阿里云主賬號AccessKey擁有所有API的訪問權(quán)限,風(fēng)險(xiǎn)很高。強(qiáng)烈建議您創(chuàng)建并使用RAM賬號進(jìn)行API訪問或日常運(yùn)維,請登錄 https://ram.console.aliyun.com 創(chuàng)建RAM賬號。String accessKeyId = Constants.accessKeyId;String accessKeySecret = Constants.accessKeySecret;String bucketName = Constants.bucketName;String objectName = "readme";// 創(chuàng)建OSSClient實(shí)例。OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);// 下載OSS文件到本地文件。如果指定的本地文件存在會(huì)覆蓋,不存在則新建。ossClient.getObject(new GetObjectRequest(bucketName, objectName), new File("e:/"+ objectName));// 關(guān)閉OSSClient。ossClient.shutdown();System.out.println("download complete.");} }3. 表單上傳案例
應(yīng)用場景
表單上傳非常適合嵌入在HTML網(wǎng)頁中來上傳Object,比較常見的場景是網(wǎng)站應(yīng)用,以招聘網(wǎng)站為例, 流程比對:
不使用表單上傳
- 網(wǎng)站用戶上傳簡歷。
- 網(wǎng)站服務(wù)器回應(yīng)上傳頁面。
- 簡歷被上傳到網(wǎng)站服務(wù)器。
- 網(wǎng)站服務(wù)器再將簡歷上傳到OSS。
采用表單上傳
使用表單上傳,少了一步轉(zhuǎn)發(fā)流程, 并且在上傳量過大時(shí), 減少了業(yè)務(wù)應(yīng)用方服務(wù)擴(kuò)容的壓力。
通過STS臨時(shí)授權(quán)訪問OSS
通過阿里云STS(Security Token Service)進(jìn)行臨時(shí)授權(quán)訪問, 可以為第三方應(yīng)用頒發(fā)一個(gè)自定義時(shí)效和權(quán)限的訪問憑證, 用以保障服務(wù)安全性(類似于OAuth2的授權(quán)碼訪問模式)。
實(shí)現(xiàn)機(jī)制:
RAM用戶STS授權(quán)配置
進(jìn)入RAM訪問控制后臺->用戶->添加權(quán)限, 輸入框填寫"sts"過濾, 選擇AliyunSTSAssumeRoleAccess權(quán)限。
創(chuàng)建權(quán)限策略
輸入權(quán)限策略名稱, 可以選擇腳本配置, 更為靈活。
策略內(nèi)容:
{"Version": "1","Statement": [{"Effect": "Allow","Action": ["oss:*"],"Resource": ["acs:oss:*:*:cloudstorage-test","acs:oss:*:*:cloudstorage-test/*"]}] }意思是對名稱為cloudstorage-test的Bucket具有完全控制權(quán)限。如果更細(xì)力度的控制, 可以修改Action,例如:
"Action": [ "oss:ListBuckets", "oss:GetBucketStat", "oss:GetBucketInfo", "oss:GetBucketTagging", "oss:GetBucketAcl" ],創(chuàng)建訪問角色
打開"RAM角色管理",點(diǎn)擊"創(chuàng)建RAM角色“,可信實(shí)體類型選擇“阿里云賬號”
接下來輸入角色名稱, 選擇當(dāng)前云賬號;添加上面所創(chuàng)建的權(quán)限策略“oss_access”。
配置完成后, 會(huì)生成一個(gè)ARN值, 需要將它記錄下來。
申請STS的訪問TOKEN信息
StsServiceApplication代碼:
public class StsServiceApplication {public static void main(String[] args) {String endpoint = "sts.cn-beijing.aliyuncs.com";String AccessKeyId = Constants.accessKeyId;String accessKeySecret = Constants.accessKeySecret;String roleArn = "acs:ram::1567235516853620:role/ram-oss-access";String roleSessionName = "oss_access_session";String policy = "{\n" +" \"Version\": \"1\", \n" +" \"Statement\": [\n" +" {\n" +" \"Action\": [\n" +" \"oss:*\"\n" +" ], \n" +" \"Resource\": [\n" +" \"acs:oss:*:*:*\" \n" +" ], \n" +" \"Effect\": \"Allow\"\n" +" }\n" +" ]\n" +"}";try {// 添加endpoint(直接使用STS endpoint,前兩個(gè)參數(shù)留空,無需添加region ID)DefaultProfile.addEndpoint("", "", "Sts", endpoint);// 構(gòu)造default profile(參數(shù)留空,無需添加region ID)IClientProfile profile = DefaultProfile.getProfile("", AccessKeyId, accessKeySecret);// 用profile構(gòu)造clientDefaultAcsClient client = new DefaultAcsClient(profile);final AssumeRoleRequest request = new AssumeRoleRequest();request.setMethod(MethodType.POST);request.setRoleArn(roleArn);request.setRoleSessionName(roleSessionName);request.setPolicy(policy); // 若policy為空,則用戶將獲得該角色下所有權(quán)限r(nóng)equest.setDurationSeconds(1000L); // 設(shè)置憑證有效時(shí)間final AssumeRoleResponse response = client.getAcsResponse(request);System.out.println("Expiration: " + response.getCredentials().getExpiration());System.out.println("Access Key Id: " + response.getCredentials().getAccessKeyId());System.out.println("Access Key Secret: " + response.getCredentials().getAccessKeySecret());System.out.println("Security Token: " + response.getCredentials().getSecurityToken());System.out.println("RequestId: " + response.getRequestId());} catch (ClientException e) {System.out.println("Failed:");System.out.println("Error code: " + e.getErrCode());System.out.println("Error message: " + e.getErrMsg());System.out.println("RequestId: " + e.getRequestId());}} }返回結(jié)果:
Expiration: 2020-11-15T06:37:51Z Access Key Id: STS.NT2Mshx5eaKbLScAzcwXLLK5V Access Key Secret: 7buxRohgRr6vT1EVAqq4FWjxaUFRQMuC4vvV55utenkJ Security Token: CAISjwJ1q6Ft5B2yfSjIr5eHBsnclepE1omJTnXSpXo2e9dgo46etDz2IHxMenFgA+sfv/0ynGBR5/YSlrt0UIRyTEfPYNBr2Y9a6higZIyZdz4iUQhC2vOfAmG2J0PR7q27OpfELr70fvOqdCqz9Etayqf7cjOPRkGsNYbz57dsctUQWHvXD1dBH8wEZHEhyqkgOGDWKOymPzPzn2PUFzAIgAdnjn5l4qnNpa/54xHF3lrh0b1X9cajYLrcNpQyY80kDorsgrwrLfSbiBQ9sUYaqP1E64Vf4irCs92nBF1c3g6LKeK88Kc0cFcnPvhgQPcV9aWkxaQp6rzJ8Z7+zlNKJvoQWi/USZu70Fd2+ykG8lpTGoABiIGFt+WCBkX/yLkY3uHDiWq4Uud32DzXWQAQpGmOWXwYzPRepi0XCcC029hPoXwCsj6mWbd/Ls2bUQsLUPtG3ozr6WawG2XUBXgZI5dNip8dZJCWZSet9qGsNXubhA3hTC+Wi7MNOariEkmr1kjqnG6N/YNaWuMYJ3BUobvLL4g= RequestId: 480E0B98-ACA5-4C98-AA82-6D9901CD7EE4表單上傳
FormPostApplication代碼:
public class FormPostApplication {// The local file path to upload.private String localFilePath = "d:/trade_stock.sql";// OSS domain, such as http://oss-cn-hangzhou.aliyuncs.comprivate String endpoint = Constants.endpoint;// Access key Id. Please get it from https://ak-console.aliyun.comprivate String accessKeyId = "STS.NTcqigyooFzFUeV2GRZPWDLt8";private String accessKeySecret = "HwdZYJ8wVUopdNscwDYFf7oPgBpA4WXgG6K4JggztqW9";private String oss_security_token= "CAISjwJ1q6Ft5B2yfSjIr5fWOtPTlLBO8bitV0Pn1kcHVt97q4nf2jz2IHxMenFgA+sfv/0ynGBR5/YSlrt0UIRyTEfPYNBr2Y9a6higZIyZW2tYUAhC2vOfAmG2J0PR7q27OpfELr70fvOqdCqz9Etayqf7cjOPRkGsNYbz57dsctUQWHvXD1dBH8wEZHEhyqkgOGDWKOymPzPzn2PUFzAIgAdnjn5l4qnNpa/54xHF3lrh0b1X9cajYLrcNpQyY80kDorsgrwrLfSbiBQ9sUYaqP1E64Vf4irCs92nBF1c3g6LKeK88Kc0cFcnPvhgQPcV9aWkxaQp6rzJ8Z7+zlNKJvoQWi/USZu70Fd2+ykG8lpTGoABUJly6VzNT0fNrAW2uTyuuGX+PI/PaV7df5cewy7WoAnvtjDe0PM8vBWuD6zY3dQFgQOPFkY8RxxQUrSkZ9wpS3E7FBjzTfkFGlRHmmc+ad8uCLPaWIb/B9QGI6uKidSXnEnLqcK+8xsB1HBsyCkL600PJfcuSWBs9CHh9uiJTG0=";// The existing bucket nameprivate String bucketName = Constants.bucketName;// The key name for the file to upload.private String key = "trade_stock"; private void postObject() throws Exception {// append the 'bucketname.' prior to the domain, such as http://bucket1.oss-cn-hangzhou.aliyuncs.com.String urlStr = endpoint.replace("http://", "http://" + bucketName + ".");// form fieldsMap<String, String> formFields = new LinkedHashMap<String, String>();// keyformFields.put("key", this.key);// Content-DispositionformFields.put("Content-Disposition", "attachment;filename="+ localFilePath);// OSSAccessKeyIdformFields.put("OSSAccessKeyId", accessKeyId);// policyString policy= "{\"expiration\": \"2120-01-01T12:00:00.000Z\",\"conditions\": [[\"content-length-range\", 0, 104857600]]}";String encodePolicy = new String(Base64.encodeBase64(policy.getBytes()));formFields.put("policy", encodePolicy);// SignatureString signaturecom = computeSignature(accessKeySecret, encodePolicy);formFields.put("Signature", signaturecom);// Set security token.formFields.put("x-oss-security-token", oss_security_token);String ret = formUpload(urlStr, formFields, localFilePath);System.out.println("Post Object [" + this.key + "] to bucket [" + bucketName + "]");System.out.println("post reponse:" + ret);}private static String computeSignature(String accessKeySecret, String encodePolicy)throws UnsupportedEncodingException, NoSuchAlgorithmException, InvalidKeyException {// convert to UTF-8byte[] key = accessKeySecret.getBytes("UTF-8");byte[] data = encodePolicy.getBytes("UTF-8");// hmac-sha1Mac mac = Mac.getInstance("HmacSHA1");mac.init(new SecretKeySpec(key, "HmacSHA1"));byte[] sha = mac.doFinal(data);// base64return new String(Base64.encodeBase64(sha));}private static String formUpload(String urlStr, Map<String, String> formFields, String localFile)throws Exception {String res = "";HttpURLConnection conn = null; // String boundary = "9431149156168";String boundary = "abc";try {URL url = new URL(urlStr);conn = (HttpURLConnection)url.openConnection();conn.setConnectTimeout(5000);conn.setReadTimeout(30000);conn.setDoOutput(true);conn.setDoInput(true);conn.setRequestMethod("POST");conn.setRequestProperty("User-Agent","Mozilla/5.0 (Windows; U; Windows NT 6.1; zh-CN; rv:1.9.2.6)");// Set Content-MD5. The MD5 value is calculated based on the whole message body. // conn.setRequestProperty("Content-MD5", "<yourContentMD5>");conn.setRequestProperty("Content-Type","multipart/form-data; boundary=" + boundary);OutputStream out = new DataOutputStream(conn.getOutputStream());// textif (formFields != null) {StringBuffer strBuf = new StringBuffer();Iterator<Entry<String, String>> iter = formFields.entrySet().iterator();int i = 0;while (iter.hasNext()) {Entry<String, String> entry = iter.next();String inputName = entry.getKey();String inputValue = entry.getValue();if (inputValue == null) {continue;}if (i == 0) {strBuf.append("--").append(boundary).append("\r\n");strBuf.append("Content-Disposition: form-data; name=\""+ inputName + "\"\r\n\r\n");strBuf.append(inputValue);} else {strBuf.append("\r\n").append("--").append(boundary).append("\r\n");strBuf.append("Content-Disposition: form-data; name=\""+ inputName + "\"\r\n\r\n");strBuf.append(inputValue);}i++;}out.write(strBuf.toString().getBytes());}// fileFile file = new File(localFile);String filename = file.getName();String contentType = new MimetypesFileTypeMap().getContentType(file);if (contentType == null || contentType.equals("")) {contentType = "application/octet-stream";}StringBuffer strBuf = new StringBuffer();strBuf.append("\r\n").append("--").append(boundary).append("\r\n");strBuf.append("Content-Disposition: form-data; name=\"file\"; "+ "filename=\"" + filename + "\"\r\n");strBuf.append("Content-Type: " + contentType + "\r\n\r\n");out.write(strBuf.toString().getBytes());DataInputStream in = new DataInputStream(new FileInputStream(file));int bytes = 0;byte[] bufferOut = new byte[1024];while ((bytes = in.read(bufferOut)) != -1) {out.write(bufferOut, 0, bytes);}in.close();byte[] endData = ("\r\n--" + boundary + "--\r\n").getBytes();out.write(endData);out.flush();out.close();// Gets the file datastrBuf = new StringBuffer();BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));String line = null;while ((line = reader.readLine()) != null) {strBuf.append(line).append("\n");}res = strBuf.toString();reader.close();reader = null;} catch (Exception e) {System.err.println("Send post request exception: " + e);throw e;} finally {if (conn != null) {conn.disconnect();conn = null;}}return res;}public static void main(String[] args) throws Exception {FormPostApplication ossPostObject = new FormPostApplication();ossPostObject.postObject();}}將上面所獲取的key,secret和token填入。
bucket名稱要和上面授權(quán)對應(yīng)的bucket一致。
這里是模擬form表單提交,編碼采用UTF-8。
policy里面可以配置超時(shí)時(shí)間, 內(nèi)容長度范圍等。
如果出現(xiàn)403錯(cuò)誤,檢查token等權(quán)限信息的配置是否正確。
如果出現(xiàn)400錯(cuò)誤, 檢查參數(shù)配置是否正確, 比如說MD5參數(shù)如果傳遞, 但沒配置正確, 會(huì)出現(xiàn)此錯(cuò)誤。
conn.setRequestProperty("Content-MD5", "<yourContentMD5>");操作成功后, 能夠在后臺看到對應(yīng)的文件信息。
4. 服務(wù)上傳驗(yàn)證
代碼:
添加阿里云依賴。
添加阿里云配置信息。
采用表單方式上傳, 直接將數(shù)據(jù)存至OSS服務(wù)中。實(shí)現(xiàn)類: FormFileUploadServiceImpl。
打包app-file服務(wù)
maven clean install
上傳至云服務(wù)器
運(yùn)行:
java -jar app-file.jar功能驗(yàn)證
對文件上傳和下載進(jìn)行驗(yàn)證。
5. 云數(shù)據(jù)庫
云數(shù)據(jù)庫 VS 傳統(tǒng)數(shù)據(jù)庫
云數(shù)據(jù)庫和傳統(tǒng)數(shù)據(jù)庫在搭建、運(yùn)維、管理層面,云數(shù)據(jù)庫提升了一個(gè)層次,實(shí)現(xiàn)了較高程度的智能化和自動(dòng)化,極大地提升了用戶友好度,降低了使用門檻。比如靈活的性能等級調(diào)整、詳盡的監(jiān)控體系、攻擊防護(hù)機(jī)制等等。
云數(shù)據(jù)庫的高級特性:
讀寫分離
提供可視化的讀寫分離配置管理功能。從數(shù)據(jù)庫實(shí)例的創(chuàng)建, 到同步關(guān)系以及讀寫流量分發(fā), 云數(shù)據(jù)庫都能自動(dòng)化完成。
自動(dòng)調(diào)優(yōu)
云數(shù)據(jù)庫都自帶性能分析和改進(jìn)的模塊, 能夠自動(dòng)地發(fā)現(xiàn)性能熱點(diǎn),還能夠智能地給出調(diào)整建議,比如進(jìn)行個(gè)別語句的調(diào)整,添加額外的索引等等。云數(shù)據(jù)庫的性能分析和自動(dòng)調(diào)優(yōu)的能力,是將生產(chǎn)運(yùn)行數(shù)據(jù)和服務(wù)內(nèi)置的 AI 模型進(jìn)行了結(jié)合,做到了真正的智能化運(yùn)維, 極大的節(jié)省了成本。
阿里云的數(shù)據(jù)庫自治服務(wù)DAS:
自治服務(wù)DAS是一種基于機(jī)器學(xué)習(xí)和專家經(jīng)驗(yàn)實(shí)現(xiàn)數(shù)據(jù)庫自感知、自修復(fù)、自優(yōu)化、自運(yùn)維及自安全的云服務(wù),使用了DAS之后您可以避免這樣的復(fù)雜性和人工操作引起的故障,有效保障數(shù)據(jù)庫服務(wù)的穩(wěn)定、安全及高效。
監(jiān)控維護(hù)
云數(shù)據(jù)庫提供了全面強(qiáng)大的監(jiān)控維護(hù)功能, 提供了豐富的性能監(jiān)控項(xiàng),能夠及時(shí)發(fā)現(xiàn)并預(yù)警。
監(jiān)控包含CPU和內(nèi)存使用率、磁盤空間、IOPS、連接數(shù)、CPU內(nèi)存使用率和網(wǎng)絡(luò)流量等。
報(bào)警功能:
可以根據(jù)不同的規(guī)則來組合設(shè)定預(yù)警條件:

6. 云數(shù)據(jù)庫操作
創(chuàng)建云數(shù)據(jù)庫實(shí)例
根據(jù)自身需要, 選擇相應(yīng)配置:
訪問權(quán)限配置
申請外網(wǎng)訪問地址:
這里提供了內(nèi)網(wǎng)和外網(wǎng)不同訪問地址。
需要設(shè)定白名單, 0.0.0.0/0是允許所有主機(jī)訪問, 在實(shí)際應(yīng)用中, 最好要指定具體的IP。
hdm_security_ips是DAS服務(wù)白名單, 自動(dòng)生成。
數(shù)據(jù)庫賬號配置
創(chuàng)建訪問數(shù)據(jù)庫的賬號密碼。
服務(wù)授權(quán)標(biāo)簽可以開通配置權(quán)限與數(shù)據(jù)權(quán)限。
連接配置
SQL洞察
連入數(shù)據(jù)庫后, 做一些SQL操作, 通過SQL洞察就能看到詳細(xì)的信息:
全量SQL統(tǒng)計(jì)
這里面會(huì)側(cè)重性能分析, 并給出自動(dòng)優(yōu)化提示。
7. 服務(wù)連接云數(shù)據(jù)庫
代碼
- 編寫下單與查詢訂單的接口。
- 配置數(shù)據(jù)源連接, 指向云數(shù)據(jù)庫。
- 采用JPA方式對數(shù)據(jù)進(jìn)行操作。
修改連接配置
修改application.yml配置文件:
服務(wù)打包
maven clean install
上傳至云服務(wù)器
運(yùn)行:
java -jar app-server.jar功能驗(yàn)證
測試數(shù)據(jù)庫的新增與查詢功能。
新增: http://47.104.9.75:10692/addOrder?accountNo=1&execPrice=2
查詢:http://47.104.9.75:10692/getAllOrders
8. 新一代原生數(shù)據(jù)庫
新一代原生數(shù)據(jù)庫 VS 云數(shù)據(jù)庫
更強(qiáng)的性能與擴(kuò)展性
云原生數(shù)據(jù)庫由于原生設(shè)計(jì), 專門為云設(shè)計(jì)的專業(yè)化存儲架構(gòu), 可以支撐更大規(guī)模的數(shù)據(jù)量,關(guān)系型云原生數(shù)據(jù)庫能夠脫離典型的數(shù) TB 的容量上限,達(dá)到單庫數(shù)十 TB 甚至百 TB 的級別。
云原生數(shù)據(jù)庫可以利用云快速地進(jìn)行水平擴(kuò)展,迅速調(diào)整、提升數(shù)據(jù)庫的處理能力, 能夠有效應(yīng)對高并發(fā)場景。
更高的可用性與可靠性
云原生數(shù)據(jù)庫默認(rèn)就具備多副本高可用的,數(shù)據(jù)同步、讀寫分離等高級特性,比如Amazon Aurora云原生數(shù)據(jù)庫, 就自動(dòng)包含了分布在 3 個(gè)可用區(qū)、多達(dá) 6 份的數(shù)據(jù)副本。
對于多種數(shù)據(jù)模型也有很好的支持, 除了兼容關(guān)系型數(shù)據(jù)庫外, 還會(huì)推出適合不同形態(tài)和查詢范式的云數(shù)據(jù)庫,與 NoSQL 數(shù)據(jù)庫形成競爭, 比如說AWS的圖數(shù)據(jù)庫 Neptune,Azure Cosmos DB的NoSQL 數(shù)據(jù)庫服務(wù)。
低成本與易維護(hù)性
大部分云原生數(shù)據(jù)庫, 在存儲上不需要預(yù)先設(shè)置大小, 會(huì)隨著存儲占用自動(dòng)擴(kuò)展;在計(jì)算上, 也有部分云數(shù)據(jù)庫推出了無服務(wù)器版本,比如 亞馬遜 的 Aurora Serverless,在面對間歇偶發(fā)性工作負(fù)載時(shí),都能節(jié)省較多的成本。
阿里云PolarDB
阿里云 PolarDB 放棄了通用分布式數(shù)據(jù)庫OLTP多路并發(fā)寫的支持,采用一寫多讀的架構(gòu)設(shè)計(jì),存儲與計(jì)算分離的技術(shù)架構(gòu),簡化了分布式系統(tǒng)難以兼顧的理論模型,又能滿足絕大多數(shù)OLTP的應(yīng)用場景和性能要求。
PolarDB 的設(shè)計(jì)革新:
產(chǎn)品架構(gòu)設(shè)計(jì)
一寫多讀
主節(jié)點(diǎn)處理讀寫請求,只讀節(jié)點(diǎn)僅處理讀請求。一個(gè)集群版集群包含一個(gè)主節(jié)點(diǎn)和最多15個(gè)只讀節(jié)點(diǎn)。
計(jì)算與存儲分離
計(jì)算與存儲分離的設(shè)計(jì),計(jì)算節(jié)點(diǎn)僅存儲元數(shù)據(jù), 存儲節(jié)點(diǎn)負(fù)責(zé)數(shù)據(jù)文件、Redo Log等存儲。
共享分布式存儲
多個(gè)計(jì)算節(jié)點(diǎn)共享一份數(shù)據(jù),并非每個(gè)計(jì)算節(jié)點(diǎn)都存儲一份數(shù)據(jù), 降低存儲成本。存儲節(jié)點(diǎn)的數(shù)據(jù)采用多副本形式,確保數(shù)據(jù)的可靠性,并通過Parallel-Raft協(xié)議保證數(shù)據(jù)一致性。基于全新設(shè)計(jì)的分布式塊存儲和文件系統(tǒng),存儲容量可以在線平滑擴(kuò)展。
POLARDB 2.0 vs POLARDB 1.0
PolarDB-X 1.0 是基于DRDS + RDS 的分布式云數(shù)據(jù)庫服務(wù), 產(chǎn)品的特征是采用 Share-Nothing 架構(gòu)、以解決存儲擴(kuò)展性為出發(fā)點(diǎn)、提供面向用戶的產(chǎn)品化交付能力。
PolarDB-X 2.0 主要是解決企業(yè)的各種復(fù)雜需求:
針對以上問題, POLARDB2.0應(yīng)運(yùn)而生,不但完全繼承了1.0的架構(gòu)體系,同時(shí)兼容了另外兩個(gè)流行數(shù)據(jù)庫Oracle與PostgreSQL。POLARDBv2.0forOracle,高度兼容Oracle;POLARDBv2.0 for PostgreSQL,完全兼容PostgreSQL。
本文由mirson創(chuàng)作分享,如需進(jìn)一步交流,請加QQ群:19310171或訪問www.softart.cn
總結(jié)
以上是生活随笔為你收集整理的基于阿里云的基础架构设施保障(二)IAAS云存储的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: WDF VIOLATION 你的电脑遇到
- 下一篇: MediaCoder压缩参数设置