运维编排场景系列----给实例加到SLS机器组
場(chǎng)景簡(jiǎn)介
我們經(jīng)常會(huì)有這樣的運(yùn)維場(chǎng)景,擴(kuò)容一批機(jī)器需要配置SLS日志,對(duì)于已經(jīng)配置好的SLS Logstore后,我們只需要將機(jī)器加到機(jī)器組里。
解決方案
傳統(tǒng)的解決方案是登錄每臺(tái)ecs實(shí)例并安裝logtail,執(zhí)行的命令為
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.檢查實(shí)例是不是Running狀態(tài)
2.調(diào)用云助手CreateCommand創(chuàng)建上述命令
3.調(diào)用InvokeCommand執(zhí)行
4.等待執(zhí)行成功
5.刪除模板
再轉(zhuǎn)換成OOS模板并創(chuàng)建命名為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 }}"}} }以上模板我們很好的解決了單臺(tái)機(jī)器執(zhí)行Install sls Agent的任務(wù),那么對(duì)于多臺(tái)機(jī)器的執(zhí)行怎么辦呢?OOS的Loop功能可以很好的解決這個(gè)問題。并且OOS支持模板嵌套執(zhí)行,那么我們只需要構(gòu)建一個(gè)傳入實(shí)例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": {} }創(chuàng)建一個(gè)執(zhí)行
執(zhí)行后看詳細(xì)信息,發(fā)現(xiàn)執(zhí)行已經(jīng)成功并且可以看到每個(gè)loop子task的狀態(tài)
由于子task是一個(gè)嵌套執(zhí)行,我們點(diǎn)擊可以看到嵌套的模板執(zhí)行情況
最后到機(jī)器組查看機(jī)器狀態(tài)OK說明已經(jīng)執(zhí)行成功
總結(jié)
以上我們介紹了如何使用資源編排OOS批量安裝SLS-Agent并加入到機(jī)器組中,更多場(chǎng)景待挖掘。目前運(yùn)維編排(OOS)處于內(nèi)測(cè)中,歡迎試用提意見
原文鏈接
本文為云棲社區(qū)原創(chuàng)內(nèi)容,未經(jīng)允許不得轉(zhuǎn)載。
總結(jié)
以上是生活随笔為你收集整理的运维编排场景系列----给实例加到SLS机器组的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 漫谈分布式计算框架
- 下一篇: 把握数据库发展趋势 DBA应如何避免“踩