运维编排场景系列-----自动一键连通跳板机
跳板机是云盾提供的一个核心系统运维和安全审计管控平台。通过跳板机可以操作跳板机内连通的实例,并在跳板机内对实例进行免密连接操作。此文章构建的是一个简易的跳板机例文。
前提条件
- 实例状态为运行中(
Running
) - 在控制台查看准备的秘钥对或创建秘钥对
- 保存秘钥对中的私钥部分
模版说明:
父模版主要功能为:
- 获取实例
- 检查实例是否绑定了指定的公共秘钥否则绑定秘钥对
- 检查实例运行状态是否符合预期
- 检测选择执行公网Ip或者选择执行弹性公网Ip
- 将似钥存放进跳板机内并测试连接
- 检测选择是否执行测试连接弹性公网Ip
- 检测当前任务
FormatVersion: OOS-2019-06-01 Description: en: Connect the instance in the jumper instance. zh-cn: 连接跳板机内的实例。 Parameters: KeyPairName: Type: String Description: en: Key pair name. zh-cn: 秘钥对名称。 SecretKeys: Type: String Description: en: Path and file name of the private key stored in the springboard. zh-cn: 跳板机内存放私钥的路径及文件名称。 JumperInstanceId: Type: String Description: en: Jumper instance ID. zh-cn: 跳板机实例ID。 Targets: Type: Json AssociationProperty: Targets AssociationPropertyMetadata: ResourceType: 'ALIYUN::ECS::Instance' RateControl: Description: en: Concurrency ratio of task execution. zh-cn: 任务执行的并发比率。 Type: Json AssociationProperty: RateControl Default: Mode: Concurrency MaxErrors: 100 Concurrency: 10 OOSAssumeRole: Description: The RAM role to be assumed by OOS. Type: String Default: OOSServiceRole RamRole: '{{ OOSAssumeRole }}' Tasks: - Name: getInstance Description: en: Views the ECS instances. zh-cn: 获取ECS实例。 Action: 'ACS::SelectTargets' Properties: ResourceType: 'ALIYUN::ECS::Instance' Filters: - '{{ Targets }}' Outputs: instanceIds: Type: List ValueSelector: 'Instances.Instance[].InstanceId' - Name: checkInstanceHasInstalledKeyPair Action: 'ACS::Template' Description: en: 'Check if the instance has the specified public Secret, if not, install it.' zh-cn: 检查实例是否安装了指定的公共秘要,若无则安装。 Properties: TemplateName: CheckInstanceWetherInstallKeyPair Parameters: KeyPairName: '{{ KeyPairName }}' InstanceId: '{{ ACS::TaskLoopItem }}' Loop: RateControl: '{{ RateControl }}' Items: '{{ getInstance.instanceIds }}' - Name: checkInstanceReady Action: 'ACS::CheckFor' Description: en: Check the ECS instance is not Starting status.. zh-cn: 检查实例的状态不是Starting。 Properties: Service: ECS API: DescribeInstances Parameters: InstanceIds: - '{{ ACS::TaskLoopItem }}' NotDesiredValues: - Starting PropertySelector: 'Instances.Instance[].Status' Outputs: publicIpAddress: Type: String ValueSelector: 'Instances.Instance[].PublicIpAddress.IpAddress[]' eipAddress: Type: String ValueSelector: 'Instances.Instance[].EipAddress.IpAddress' Loop: RateControl: '{{ RateControl }}' Items: '{{ getInstance.instanceIds }}' Outputs: publicIpAddresses: AggregateType: 'Fn::ListJoin' AggregateField: publicIpAddress eipAddresses: AggregateType: 'Fn::ListJoin' AggregateField: eipAddress - Name: chooseEipOrPublicIp Action: 'ACS::Choice' Properties: DefaultTask: runCommandPublicIp Choices: - When: 'Fn::Equals': - - Null - '{{ checkInstanceReady.publicIpAddresses }}' NextTask: runCommandEIp - Name: runCommandPublicIp Action: 'ACS::ECS::RunCommand' Description: en: 'Try to connect the ECS instance in the jumper instance.' zh-cn: 测试连接跳板机内的实例。 Properties: commandContent: 'Fn::Join': - |+ - - 'echo ''{{ SecretKeys }}'' > ~/jumperInstance.pem' - chmod 600 ~/jumperInstance.pem - 'ssh root@{{ ACS::TaskLoopItem }} -i ~/jumperInstance.pem' - ifconfig -a instanceId: '{{ JumperInstanceId }}' commandType: RunShellScript Outputs: commandOutput: Type: String ValueSelector: invocationOutput Loop: RateControl: '{{ RateControl }}' Items: '{{ checkInstanceReady.publicIpAddresses }}' Outputs: commandOutputs: AggregateType: 'Fn::ListJoin' AggregateField: commandOutput - Name: chooseEipOrEnd Action: 'ACS::Choice' Properties: DefaultTask: runCommandEIp Choices: - When: 'Fn::Equals': - - Null - '{{ checkInstanceReady.eipAddresses }}' NextTask: listExecutions - Name: runCommandEIp Action: 'ACS::ECS::RunCommand' Description: en: 'Try to connect the ECS instance in the jumper instance.' zh-cn: 测试连接跳板机内的实例。 Properties: commandContent: 'Fn::Join': - |+ - - 'echo ''{{ SecretKeys }}'' > ~/jumperInstance.pem' - chmod 600 ~/jumperInstance.pem - 'ssh root@{{ ACS::TaskLoopItem }} -i ~/jumperInstance.pem' - ifconfig -a instanceId: '{{ JumperInstanceId }}' commandType: RunShellScript Outputs: commandOutput: Type: String ValueSelector: invocationOutput Loop: RateControl: '{{ RateControl }}' Items: '{{ checkInstanceReady.eipAddresses }}' Outputs: commandOutputs: AggregateType: 'Fn::ListJoin' AggregateField: commandOutput - Name: listExecutions Action: 'ACS::ExecuteAPI' Description: en: 'The execution springboard.' zh-cn: 执行跳板。 Properties: Service: OOS API: ListExecutions Parameters: ExecutionId: '{{ ACS::ExecutionId }}'
子模版
需将子模版命名为:CheckInstanceWetherInstallKeyPair
子模版主要功能:
- 检测是否绑定公共秘要
- 若无则将公共秘要绑定到实例上
- 重启实例
- 检测是否绑定秘要
FormatVersion: OOS-2019-06-01 Description: en: Check if the instance bind the specified key pair. zh-cn: 检查实例是否绑定了指定的秘钥对。 Parameters: InstanceId: Type: String Description: en: The ECS instance ID in the jumper instance need to binding. zh-cn: 跳板机内需要绑定的ECS实例ID。 KeyPairName: Type: String Description: en: The key pair name. zh-cn: 秘钥对的名称。 OOSAssumeRole: Description: The RAM role to be assumed by OOS. Type: String Default: OOSServiceRole RamRole: '{{ OOSAssumeRole }}' Tasks: - Name: checkInstanceHasKeyPair Action: 'ACS::CheckFor' Description: zh-cn: 查询实例是否绑定了给定的秘钥对。 en: Check if the instance bind the specified KeyPair. OnSuccess: checkInstanceHasKeyPairIsOnlyOne OnError: AttachKeyPair Properties: Service: ECS API: DescribeInstances Parameters: KeyPairName: '{{ KeyPairName }}' InstanceIds: - '{{ InstanceId }}' NotDesiredValues: - 0 PropertySelector: TotalCount - Name: AttachKeyPair Action: 'ACS::ExecuteAPI' Description: en: Bind the key pair to the instance. zh-cn: 将秘钥对绑定到实例上。 Properties: Service: ECS API: AttachKeyPair Parameters: InstanceIds: - '{{ InstanceId }}' KeyPairName: '{{ KeyPairName }}' - Name: rebootInstance Action: 'ACS::ECS::RebootInstance' Description: en: Restarts the ECS instances. zh-cn: 重启实例。 Properties: instanceId: '{{ InstanceId }}' - Name: checkInstanceHasKeyPairIsOnlyOne Action: 'ACS::CheckFor' Description: zh-cn: 查询实例是否绑定了给定的秘钥对。 en: Check if the instance bind the specified KeyPair. Properties: Service: ECS API: DescribeInstances Parameters: KeyPairName: '{{ KeyPairName }}' InstanceIds: - '{{ InstanceId }}' DesiredValues: - 1 PropertySelector: TotalCount
模版参数说明:
参数 | 说明 | 示例 |
---|---|---|
KeyPairName | 创建的秘钥对名称 | test-oos-jump |
SecretKeys | 秘钥对中的私钥 | usr/test.pem |
JumperInstanceId | 跳板机实例Id | |
Targets | 根据实例标签(tags)或实例ID(InstanceId)选定需要的实例。 | i-11111111111 |
RateControl | 固定参数。 - 速率控制类型:并发控制 - 并发速率:1 - 最大错误次数:0 | |
OOSAssumeRole | 可选参数。 - (默认设置)当前账号的已有权限:执行您使用的账号的权限动作。请确保您拥有创建自定义镜像涉及的所有ECS API调用权限。 - 指定RAM角色,使用该角色的权限:如果指定了RAM角色名称,OOS扮演该RAM角色执行运维任务。 | 当前账号的已有权限 |
操作步骤
- 请访问运维编排OOS的控制。
- 单击我的模版,单击创建模板按钮,选取空白模板。
- 先将上述提供的子模板粘贴到yaml栏,输入名称CheckInstanceWetherInstallKeyPair,点击创建模板。然后将父模版粘贴到yaml栏,输入名称ConnectJumperInstance,点击创建模版。
- 找到创建的父模版,单击创建执行。
- 保持基本信息的默认设置,单击下一步:设置参数。
- 完成参数设置填写,单击下一步:确认。
- 查看参数设置是否无误,确认无误后单击创建执行。
- 在执行管理中查看创建的运维任务。
- 执行结果
登陆跳板机,此时在跳板机内输入ssh root@11.xx.xx.xx -i ~/xxxx.pem就可以实现免密连接其下任意实例。
系列文章
主题文章
最佳实践
玩转运维编排服务的权限:Assume Role+Pass Role
阿里云运维编排新功能:一键批量克隆ECS
批量在多台ECS内执行命令
场景系列
运维编排场景系列----更新ECS镜像
运维编排场景系列----给ECS实例自动打TAG
运维编排场景系列----从实例中拷贝文件到OSS
运维编排场景系列----给实例加到SLS机器组
运维编排场景系列----检测MFA功能状态
运维编排场景系列----每日统计多Region实例的运行状态
运维编排场景系列----如何使用jq
运维编排场景系列----分批到机器上运行命令
运维编排场景系列----更新镜像后自动更新伸缩配置镜像
运维编排场景系列----向Linux实例上传文件
运维编排场景系列----运行远端shell脚本
运维编排场景系列----在ECS实例上运行Ansible-playbook
运维编排场景系列----下载JVM堆栈到OSS
运维编排系列场景----将实例的固定公网IP转换为其它新EIP
运维编排场景系列----自动定时升级临时带宽
运维编排场景系列----批量更新云助手客户端
运维编排系列场景----批量释放实例
运维编排场景系列----ECS实例系统快照下载到本地
运维编排场景系列----批量更换系统盘
运维编排场景系列----自动创建多个区域同类型存储空间
运维编排场景系列---一键批量重置实例密码
低调大师中文资讯倾力打造互联网数据资讯、行业资源、电子商务、移动互联网、网络营销平台。
持续更新报道IT业界、互联网、市场资讯、驱动更新,是最及时权威的产业资讯及硬件资讯报道平台。
转载内容版权归作者及来源网站所有,本站原创内容转载请注明来源。
- 上一篇
如何配置阿里云ECS服务器安全组?
在购买阿里云ECS服务器时,系统会要求用户设置安全组,如果不设置就指定默认的安全组。那么,这个安全组是什么呢?从名字上看是为了服务器安全设置的。安全组可以看做一道防火墙,可以让用户从端口、IP的角度来筛选对应服务器的访问者,从而形成一个云上的安全地域。 购买时默认安全组 不知道安全组的用户在新购服务器上部署网站,常常会发现不能正常访问。这是因为在购买阿里云ECS服务器的时候,默认安全组只放行了ICMP协议、SSH 22端口、RDP 3389端口三个端口,访问网站的80或443端口并没有放行。 如果需要网站访问,那么用户在购买ECS服务器时需要勾选http80端口和https 443端口。 购买后配置安全组 那么购买之后需要怎么更改安全组配置呢。以这台服务器为例,如何开通http80端口。 首先,需要在阿里云的控制台找到对应的ecs服务器实例。点击这个实例的管理进入实例的详情界面,然后进入本实例的安全组,再点击配置规则。 我们已经看到了默认的三条规则,我们点击添加安全组规则。 现在这台服务器是专用网络的,那这边的网卡类型的话就内网。如果您是一个经典网络的服务器,那么还需要选择外网入方向来...
- 下一篇
Nginx系列问题之Centos7 安装配置
一、下载安装Nginx 1. 创建文件夹 cd /root/ mkdir downloads #在root目录下创建downloads 文件夹 2.打开官网 浏览器打开:https://nginx.org/en/download.html下载最新的稳定版本.Nginx下载地址 选中红框单击右键,选择复制链接地址。 3.下载编译安装Nginx 下载&解压-在终端输入: wget https://nginx.org/download/nginx-1.17.1.tar.gz #下载文件 tar -zxvf nginx-1.17.1.tar.gz #解压文件 ls #得到nginx-1.17.1文件夹 编译安装 cd nginx-1.17.1 ./configure --prefix=/usr/local/nginx #安装到/usr/local/nginx目录 # 报错 ./configure: error: the HTTP rewrite module requires the PCRE library # 解决-安装pcre-devel yum install pcre-dev...
相关文章
文章评论
共有0条评论来说两句吧...
文章二维码
点击排行
推荐阅读
最新文章
- MySQL8.0.19开启GTID主从同步CentOS8
- Mario游戏-低调大师作品
- CentOS关闭SELinux安全模块
- CentOS7,CentOS8安装Elasticsearch6.8.6
- CentOS8安装MyCat,轻松搞定数据库的读写分离、垂直分库、水平分库
- Docker安装Oracle12C,快速搭建Oracle学习环境
- Red5直播服务器,属于Java语言的直播服务器
- CentOS8编译安装MySQL8.0.19
- SpringBoot2整合MyBatis,连接MySql数据库做增删改查操作
- Springboot2将连接池hikari替换为druid,体验最强大的数据库连接池