日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

运维编排场景系列----给实例加到SLS机器组

發布時間:2024/8/23 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 运维编排场景系列----给实例加到SLS机器组 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

場景簡介

我們經常會有這樣的運維場景,擴容一批機器需要配置SLS日志,對于已經配置好的SLS Logstore后,我們只需要將機器加到機器組里。

解決方案

傳統的解決方案是登錄每臺ecs實例并安裝logtail,執行的命令為

wget http://logtail-release-{{ACS::RegionId}}.oss-{{ACS::RegionId}}-internal.aliyuncs.com/linux64/logtail.sh-O logtail.sh; chmod 755 logtail.sh; ./logtail.sh install {{ACS::RegionId}}; echo {{ LogTailUserDefinedId }} > /etc/ilogtail/user_defined_id

分解下Task,需要以下幾步:
1.檢查實例是不是Running狀態
2.調用云助手CreateCommand創建上述命令
3.調用InvokeCommand執行
4.等待執行成功
5.刪除模板

再轉換成OOS模板并創建命名為installSlsAgent

{"FormatVersion": "OOS-2019-06-01","Description": "Install Logtail agent on the ECS Instance.","Parameters": {"InstanceId": {"Type": "String","Description": "the Instance Id to install ilogtail","AllowedPattern": "i-[A-Za-z0-9]*","MinLength": 1,"MaxLength": 30},"LogTailUserDefinedId": {"Type": "String","Description": "the user defined Id write to /etc/ilogtail/user_defined_id","AllowedPattern": "[A-Za-z0-9\\-_]*","MinLength": 1,"MaxLength": 30},"OOSAssumeRole": {"Type": "String","Description": "The RAM role to be assumed by OOS.","Default": "OOSServiceRole"}},"RamRole": "{{OOSAssumeRole}}","Tasks": [{"Name": "checkInstanceReady","Action": "ACS::CheckFor","Description": "describe instances with specified parameters, refer them here: https://help.aliyun.com/document_detail/63440.html","Properties": {"API": "DescribeInstances","Service": "ECS","PropertySelector": "Instances.Instance[].Status","DesiredValues": ["Running"],"Parameters": {"InstanceIds": ["{{ InstanceId }}"]}},"Outputs": {"InstanceIds": {"ValueSelector": "InstanceIdSets.InstanceIdSet[]","Type": "List"}}},{"Name": "createCommand","Action": "ACS::ExecuteApi","Description": "create the command to install logtail agent.","Properties": {"API": "CreateCommand","Service": "ECS","Parameters": {"CommandContent": {"Fn::Base64Encode": "wget http://logtail-release-{{ACS::RegionId}}.oss-{{ACS::RegionId}}-internal.aliyuncs.com/linux64/logtail.sh -O logtail.sh; chmod 755 logtail.sh; ./logtail.sh install {{ACS::RegionId}}; echo {{ LogTailUserDefinedId }} > /etc/ilogtail/user_defined_id"},"Name": "oos-{{ACS::TemplateName}}","Type": "RunShellScript"}},"Outputs": {"CommandId": {"Type": "String","ValueSelector": "CommandId"}}},{"Name": "invokeCommand","Action": "ACS::ExecuteApi","Description": "invoke the command to install ilogtail","Properties": {"Service": "ECS","API": "InvokeCommand","Parameters": {"CommandId": "{{ createCommand.CommandId }}","InstanceIds": ["{{ InstanceId }}"]}},"Outputs": {"InvokeId": {"Type": "String","ValueSelector": "InvokeId"}}},{"Name": "untilInvocationDone","Action": "ACS::WaitFor","Description": "until invocation ready","MaxAttempts": 5,"Properties": {"Service": "ECS","API": "DescribeInvocations","Parameters": {"InvokeId": "{{ invokeCommand.InvokeId }}"},"DesiredValues": ["Finished"],"PropertySelector": "Invocations.Invocation[].InvokeStatus"}},{"Name": "describeInvocationResult","Action": "ACS::ExecuteApi","Description": "get the command invocation result","Properties": {"Service": "Ecs","API": "DescribeInvocationResults","Parameters": {"InvokeId": "{{ invokeCommand.InvokeId }}"}},"Outputs": {"InvocationResult": {"Type": "String","ValueSelector": "Invocation.InvocationResults.InvocationResult[].Output"},"ExitCode": {"Type": "Number","ValueSelector": "Invocation.InvocationResults.InvocationResult[].ExitCode"}}},{"Name": "deleteCommand","Action": "ACS::ExecuteAPI","Description": "clean up the install ilogtail command","Properties": {"Service": "ECS","Risk": "Normal","API": "DeleteCommand","Parameters": {"CommandId": "{{ createCommand.CommandId }}"}}}],"Outputs": {"InvocationResult": {"Type": "String","Value": {"Fn::Base64Decode": "{{ describeInvocationResult.InvocationResult }}"}},"ExitCode": {"Type": "String","Value": "{{ describeInvocationResult.ExitCode }}"}} }

以上模板我們很好的解決了單臺機器執行Install sls Agent的任務,那么對于多臺機器的執行怎么辦呢?OOS的Loop功能可以很好的解決這個問題。并且OOS支持模板嵌套執行,那么我們只需要構建一個傳入實例ID列表的

{"FormatVersion": "OOS-2019-06-01","Parameters": {"InstanceIds":{"Type": "List","Description": "the instance id list"},"LogTailUserDefinedId": {"Type": "String","Description": "log tail user defined id","MinLength": 1,"MaxLength": 30}},"Tasks": [{"Properties": {"TemplateName": "installSlsAgent","Parameters": {"InstanceId": "{{ ACS::TaskLoopItem }}","LogTailUserDefinedId": "{{ LogTailUserDefinedId }}"}},"Name": "installSLSAgent","Action": "ACS::Template","Outputs": {"ExitCode": {"ValueSelector": "ExitCode","Type": "Number"}},"Loop": {"Items": "{{ InstanceIds }}","MaxErrors": 100,"Concurrency": 10,"Outputs": {}}}],"Outputs": {} }

創建一個執行

執行后看詳細信息,發現執行已經成功并且可以看到每個loop子task的狀態

由于子task是一個嵌套執行,我們點擊可以看到嵌套的模板執行情況

最后到機器組查看機器狀態OK說明已經執行成功

總結

以上我們介紹了如何使用資源編排OOS批量安裝SLS-Agent并加入到機器組中,更多場景待挖掘。目前運維編排(OOS)處于內測中,歡迎試用提意見


原文鏈接
本文為云棲社區原創內容,未經允許不得轉載。

總結

以上是生活随笔為你收集整理的运维编排场景系列----给实例加到SLS机器组的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。