运维编排场景系列----给实例加到SLS机器组
生活随笔
收集整理的這篇文章主要介紹了
运维编排场景系列----给实例加到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机器组的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 漫谈分布式计算框架
- 下一篇: 为什么选择Cassandra