博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
运维编排场景系列----给实例加到SLS机器组
阅读量:2401 次
发布时间:2019-05-10

本文共 6175 字,大约阅读时间需要 20 分钟。

场景简介

我们经常会有这样的运维场景,扩容一批机器需要配置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": {}}

创建一个执行

6544f1616418e2cc7da0effc7325e3656c1.jpg

执行后看详细信息,发现执行已经成功并且可以看到每个loop子task的状态

dd7080e5d0934f39b8273403ecf7130cd22.jpg

由于子task是一个嵌套执行,我们点击可以看到嵌套的模板执行情况

f5f6ab1c458ca3a15f32995850611927ad0.jpg

最后到机器组查看机器状态OK说明已经执行成功

657c394966a3615525e2421957024b64915.jpg

总结

以上我们介绍了如何使用资源编排OOS批量安装SLS-Agent并加入到机器组中,更多场景待挖掘。目前运维编排(OOS)处于内测中,欢迎试用提意见

本文为云栖社区原创内容,未经允许不得转载。

转载于:https://my.oschina.net/u/1464083/blog/3071493

你可能感兴趣的文章
修改linux主机名!(网络上存在一些错误)
查看>>
edora core 5 办公环境安装配置,fc5不完全指南(十三)我在飞,加快fc5的启动速度(zt)...
查看>>
Linux启动过程综述(ibm)
查看>>
过并行化 Linux 系统服务来提高引导速度(zt)
查看>>
浙江省公务员考试录用系统
查看>>
ORACLE-BASE - Oracle DBA and development articles
查看>>
Congfu Xu's HomePage
查看>>
samba出错!
查看>>
oracle-base blog
查看>>
pgrep 查询进程的工具
查看>>
终止进程的工具 kill 、killall、pkill、xkill
查看>>
服务器的提示!
查看>>
biti_rainy
查看>>
系统安装到用raid做成的逻辑驱动器上不能启动的一个原因!
查看>>
tahiti.oracle.com
查看>>
系统安装到用raid做成的逻辑驱动器上不能启动的一个原因!
查看>>
informix 10.0 extent size 的大小限制和数量限制
查看>>
zhouwf0726
查看>>
Oracle字符集问题总结(转贴)
查看>>
SuSE Linux 10.0安装oracle的时候老是提示检查操作系统版本
查看>>