【Rundeck】将在Rundeck上创建的作业导入到另一个环境中(Centos8)

首先

我创建了一个能够通过单击按钮执行我在以下文章中描述的步骤的Rundeck Job。
为了完整起见,我还会在文章中介绍如何在新的EC2上搭建的Rundeck中导入该Job。
另外,我还发现在验证过程中,插件可以通过GUI界面进行安装,我也会一并介绍。

新闻

在CentOS8上,建立在EC2环境中部署Prometheus和Thanos。
实现无代理的AWS自动扩展监控。(CentOS8)

安装Rundeck

首先,建立一个用于导入Job的Rundeck。

安裝

yum install java-1.8.0
curl -s https://packagecloud.io/install/repositories/pagerduty/rundeck/script.rpm.sh | sudo bash
yum install rundeck-3.3.10.20210301-1.noarch

在此之前,屏幕已经显示出来,但屏幕转换不成功,所以请在下面的配置 “grails.serverURL” 中写入全局IP地址。

#loglevel.default is the default log level for jobs: ERROR,WARN,INFO,VERBOSE,DEBUG
loglevel.default=INFO
rdeck.base=/var/lib/rundeck

#rss.enabled if set to true enables RSS feeds that are public (non-authenticated)
rss.enabled=false
# change hostname here
grails.serverURL=http://[グローバルIP]:4440 ## ←ここ ##
dataSource.dbCreate = update
dataSource.url = jdbc:h2:file:/var/lib/rundeck/data/rundeckdb;MVCC=true

# Encryption for key storage
rundeck.storage.provider.1.type=db
rundeck.storage.provider.1.path=keys

rundeck.storage.converter.1.type=jasypt-encryption
rundeck.storage.converter.1.path=keys
rundeck.storage.converter.1.config.encryptorType=custom
rundeck.storage.converter.1.config.password=d6e9804ecce8647a
rundeck.storage.converter.1.config.algorithm=PBEWITHSHA256AND128BITAES-CBC-BC
rundeck.storage.converter.1.config.provider=BC

# Encryption for project config storage
rundeck.projectsStorageType=db

rundeck.config.storage.converter.1.type=jasypt-encryption
rundeck.config.storage.converter.1.path=projects
rundeck.config.storage.converter.1.config.password=d6e9804ecce8647a
rundeck.config.storage.converter.1.config.encryptorType=custom
rundeck.config.storage.converter.1.config.algorithm=PBEWITHSHA256AND128BITAES-CBC-BC
rundeck.config.storage.converter.1.config.provider=BC

rundeck.feature.repository.enabled=true

因为准备工作已经完成,所以开始运行服务。

service runeckd start

请注意,由于命令传达到启动需要一些时间,请耐心等待。

添加EC2插件

rundeck-ログイン.png
rundeck-findplugin.png
rundeck-ec2plugin.png
rundeck-install.png

创建项目

rundeck-create.png
rundeck-project.png
rundeck-project2.png
rundeck-plugin選択.png
rundeck-plugin設定.png

工作进口

将以下的工作复制并以任意文件名保存。
※没有扩展名限制,所以可以用任何喜欢的文件名。

1. Prometheus安装
– 默认标签:节点
描述:
<描述>
# 进行Prometheus的安装。
执行启用:是
ID:6fae508b-2883-4910-a4a2-710507fdfbb9
日志级别:INFO
名称:1. Prometheus安装
节点过滤器可编辑:否
节点过滤器:
调度:
排除优先:是
继续执行:否
排序顺序:升序
空节点过滤器成功:否
线程数:’1′
过滤器:.*
默认选择的节点:是
插件:
ExecutionLifecycle:空
计划启用:是
序列:
命令:
– 描述:添加packagecloud仓库
执行:curl -s https://packagecloud.io/install/repositories/prometheus-rpm/release/script.rpm.sh
| sudo bash
– 描述:安装Prometheus
执行:sudo yum install -y prometheus2-2.25.2-1.el8.x86_64
– 描述:安装node_exporter
执行:’sudo yum install -y node_exporter-1.1.2-1.el8.x86_64′
– 描述:创建prometheus.yml
脚本:”sudo tee /etc/prometheus/prometheus.yml << ‘EOF’ > /dev/null \n# my\
\ global config\nglobal:\n scrape_interval: 60s # Set the scrape interval\
\ to every 15 seconds. Default is every 1 minute.\n evaluation_interval:\
\ 60s # Evaluate rules every 15 seconds. The default is every 1 minute.\n\
\ # scrape_timeout is set to the global default (10s).\n\n external_labels:\n\
\ cluster: prometheus\n\n# Alertmanager configuration\nalerting:\n alertmanagers:\n\
\ – static_configs:\n – targets:\n # – alertmanager:9093\n\n# Load\
\ rules once and periodically evaluate them according to the global ‘evaluation_interval’.\n\
\ rule_files:\n # – \”first_rules.yml\”\n # – \”second_rules.yml\”\n\n# A\
\ scrape configuration containing exactly one endpoint to scrape:\n# Here\
\ it’s Prometheus itself.\nscrape_configs:\n # The job name is added as a\
\ label `job=` to any timeseries scraped from this config.\n -\
\ job_name: ‘prometheus’\n\n # metrics_path defaults to ‘/metrics’\n \
\ # scheme defaults to ‘http’.\n\n static_configs:\n – targets: [‘localhost:9090’]\n\
\n – job_name: node\n static_configs:\n – targets: [‘localhost:9100’]\n\
EOF”
– 描述:注册node_exporter服务
执行:sudo systemctl enable node_exporter
– 描述:注册prometheus服务
执行:sudo systemctl enable prometheus
– 描述:启动node_exporter服务
执行:sudo systemctl start node_exporter
– 描述:启动prometheus服务
执行:sudo systemctl start prometheus
继续执行:否
策略:以节点为先
UUID:6fae508b-2883-4910-a4a2-710507fdfbb9
2. 安装thanos
– 默认选项卡:nodes
描述:|
<描述>
# 进行thanos的安装。
### 具有设置访问密钥/秘密密钥所需的S3访问权限的策略如下。“`
{
“Version”: “2012-10-17”,
“Statement”: [
{
“Sid”: “Statement”,
“Effect”: “Allow”,
“Action”: [
“s3:ListBucket”,
“s3:GetObject”,
“s3:DeleteObject”,
“s3:PutObject”
],
“Resource”: [
“arn:aws:s3:::[bucket-name]/*”,
“arn:aws:s3:::[bucket-name]”
]
}
]
}
“`
executionEnabled: true
id: 7840b836-8c04-423f-9480-dece53d75e96
loglevel: INFO
name: 2.thanosインストール
nodeFilterEditable: false
nodefilters:
dispatch:
excludePrecedence: true
keepgoing: false
rankOrder: ascending
successOnEmptyNodeFilter: false
threadcount: ‘1’
filter: .*
nodesSelectedByDefault: true
options:
– description: 指定thanos使用的S3存储桶名称。
name: S3bucketname
required: true
– description: 设置thanos使用的IAM用户的访问密钥。
name: thanos_accesskey
required: true
secure: true
value: XXXXXXXXXXXXXXXXXXXX
valueExposed: true
– description: 指定thanos使用的IAM用户的秘密密钥。
name: thanos_secretkey
required: true
secure: true
value: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
valueExposed: true
plugins:
ExecutionLifecycle: null
scheduleEnabled: true
sequence:
commands:
– description: 安装thanos
exec: sudo yum install -y thanos-0.18.0-1.el8.x86_64
– description: 创建S3配置
script: |-
sudo tee /etc/prometheus/s3.conf << ‘EOF’
type: S3
config:
bucket: “@option.S3bucketname@”
endpoint: “s3.amazonaws.com”
region: “ap-northeast-1”
access_key: “@option.thanos_accesskey@”
insecure: false
signature_version2: false
secret_key: “@option.thanos_secretkey@”
put_user_metadata: {}
http_config:
response_header_timeout: 2m
insecure_skip_verify: false
trace:
enable: false
list_objects_version: “”
part_size: 67108864
sse_config:
type: “”
kms_key_id: “”
kms_encryption_context: {}
encryption_key: “”
EOF
– description: 创建thanos-sidecar启动文件
exec: echo “THANOS_SIDECAR_OPTS=\’–tsdb.path=/var/lib/prometheus/data –prometheus.url=http://localhost:9090 –objstore.config-file /etc/prometheus/s3.conf\'” | sudo tee /etc/default/thanos-sidecar
– description: 创建thanos-query启动文件
exec: echo “THANOS_QUERY_OPTS=\’–http-address=0.0.0.0:10904 –grpc-address=0.0.0.0:10903 –store=localhost:10901\'” | sudo tee /etc/default/thanos-query
– description: 创建thanos-store启动文件
exec: echo “THANOS_STORE_OPTS=\’–data-dir=/var/lib/thanos/store –http-address=0.0.0.0:10906 –grpc-address=0.0.0.0:10905 –objstore.config-file /etc/prometheus/s3.conf\'” | sudo tee /etc/default/thanos-store
– description: 创建thanos-compact启动文件
exec: echo “THANOS_COMPACT_OPTS=\’–data-dir=/var/lib/thanos/compact –http-address=0.0.0.0:10912 –objstore.config-file /etc/prometheus/s3.conf\'” |sudo tee /etc/default/thanos-compact
– description: 更改prometheus启动文件
exec: echo “PROMETHEUS_OPTS=\’–config.file=/etc/prometheus/prometheus.yml –storage.tsdb.path=/var/lib/prometheus/data –storage.tsdb.min-block-duration=1d –storage.tsdb.max-block-duration=1d\'” | sudo tee /etc/default/prometheus
– description: 重新启动prometheus服务
exec: sudo systemctl restart prometheus
– description: 注册thanos-sidecar服务
exec: sudo systemctl enable thanos-sidecar
– description: 注册thanos-query服务
exec: sudo systemctl enable thanos-query
– description: 注册thanos-store服务
exec: sudo systemctl enable thanos-store
– description: 注册thanos-compact服务
exec: sudo systemctl enable thanos-compact
– description: 启动thanos-sidecar服务
exec: sudo systemctl start thanos-sidecar
– description: 启动thanos-query服务
exec: sudo systemctl start thanos-query
– description: 启动thanos-store服务
exec: sudo systemctl start thanos-store
– description: 启动thanos-compact服务
exec: sudo systemctl start thanos-compact
keepgoing: false
strategy: node-first
uuid: 7840b836-8c04-423f-9480-dece53d75e96

3.安装yace
– 默认标签:节点
描述:
<描述>
# 安装yace。
### 需要设置Accesskey/Secretkey的yace访问权限如下所示。“`
{
“Version”: “2012-10-17”,
“Statement”: [
{
“Sid”: “VisualEditor0”,
“Effect”: “Allow”,
“Action”: [
“tag:GetResources”,
“cloudwatch:GetMetricData”,
“cloudwatch:GetMetricStatistics”,
“cloudwatch:ListMetrics”
],
“Resource”: “*”
}
]
}
“`
启用执行:是
ID:f6dfdffb-d809-4ff5-8dd7-0b780f67dc39
日志级别:信息
名称:3.安装yace
可编辑节点筛选:否
节点筛选:
调度:
排除优先级:是
继续执行:否
排序顺序:升序
空节点筛选成功:否
线程数量:1
筛选:.*
默认选择节点:是
选项:
– 描述:请指定yace使用的IAM用户的Accesskey。
名称:yace_accesskey
必填:是
安全:是
值:XXXXXXXXXXXXXXXXXXXXXXXXXX
暴露值:是
– 描述:请指定yace使用的IAM用户的Secretkey。
名称:yace_secretkey
必填:是
安全:是
值:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
暴露值:是
插件:
ExecutionLifecycle:null
启用计划:是
序列:
命令:
– 描述:禁用selinux
执行:sudo sed -i “s/SELINUX=enforcing/SELINUX=disabled/” /etc/selinux/config
– 配置:
命令:ssh ${node.username}@${node.hostname} ‘sudo reboot & exit 0’
描述:重新启动实例
节点步骤:是
类型:localexec
– 配置:
循环次数:1
间隔:3s
显示进度:true
描述:等待重新启动
节点步骤:是
类型:nixy-waitfor-sleep-workflow-node-step
– 配置:
主机:${node.hostname}
间隔:60
最大尝试次数:10
端口:22
描述:等待重新启动完成
节点步骤:是
类型:nixy-waitfor-local-port-open
– 描述:安装pip
执行:sudo yum install -y python3-pip
– 描述:安装awscli
执行:sudo pip3 install awscli
– 描述:创建aws配置
脚本:|-
sudo su – root -c”aws configure set aws_access_key_id @option.yace_accesskey@”
sudo su – root -c”aws configure set aws_secret_access_key @option.yace_secretkey@”
sudo su – root -c”aws configure set default.region ap-northeast-1″
– 描述:安装wget
执行:sudo yum install -y wget
– 描述:获取yace
执行:wget https://github.com/ivx/yet-another-cloudwatch-exporter/releases/download/v0.26.3-alpha/yet-another-cloudwatch-exporter_0.26.3-alpha_Linux_x86_64.tar.gz
– 描述:解压yace
执行:tar -zxf yet-another-cloudwatch-exporter_0.26.3-alpha_Linux_x86_64.tar.gz
– 描述:移动yace
脚本:|-
sudo mv yace /usr/local/
sudo chown root:root /usr/local/yace
– 描述:创建yace配置
脚本:|-
sudo tee /etc/prometheus/yace.conf << ‘EOF’ > /dev/null
discovery:
exportedTagsOnMetrics:
ec2:
– Name
jobs:
– type: ec2
regions:
– ap-northeast-1
period: 60
length: 300
delay: 60
nilToZero: true
searchTags:
– key: Name
value: .*
metrics:
– name: CPUUtilization
statistics:
– Maximum
– name: DiskReadBytes
statistics:
– Maximum
– name: DiskWriteBytes
statistics:
– Maximum
– name: NetworkIn
statistics:
– Sum
– name: NetworkOut
statistics:
– Sum
EOF
– 描述:将yace配置为服务
脚本:|-
sudo tee /usr/lib/systemd/system/yace.service << ‘EOF’ > /dev/null
[Unit]
Description=yace
After=network.target

[Service]
Type=simple
User=root
ExecStart=/usr/local/yace -config.file /etc/prometheus/yace.conf

[Install]
WantedBy=multi-user.target
EOF
– 描述:注册yace服务
执行:sudo systemctl enable yace
– 描述:启动yace服务
执行:sudo systemctl start yace
– 描述:添加到prometheus.yml
脚本:|-
sudo tee -a /etc/prometheus/prometheus.yml << ‘EOF’ > /dev/null

– job_name: cloudwatch
static_configs:
– targets: [‘localhost:5000’]
EOF
– 描述:重新启动prometheus
执行:sudo systemctl restart prometheus
继续执行:否
策略:节点优先
UUID:f6dfdffb-d809-4ff5-8dd7-0b780f67dc39

rundeck-job.png
rundeck-jobupload.png
rundeck-jobsuccess.png

职业样本

rundeck-thanos4.png

本篇只提供一种汉语翻译选项,如下所示:

附言

这次我第一次充分利用了Description等,创建了工作,完成后的易读性真是太棒了。
(在现场没有时间花在这方面)
虽然还有一些不足之处,想要更加贴合用户需求,但仅仅通过写Description就能得到这样的结果。
这样一来,即便是不喜欢基础设施的人或者一般职位的人也可能会看到内容,感觉到了传递教材或引导方面的潜力。
另外,由于当前环境无法执行”3.yace安装”,将会在以后的另一篇文章中进行介绍。

广告
将在 10 秒后关闭
bannerAds