forked from 9652040795/aws-policies
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild-AMI
More file actions
213 lines (159 loc) · 5.74 KB
/
Copy pathBuild-AMI
File metadata and controls
213 lines (159 loc) · 5.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
#!/bin/bash
# Purpose: Blue/Green Deployments with AWS CodeDeploy
# OS AmazonLinux
# Maintainer DevOps Muhammad Asim
######################
# Docker Installation
######################
yum update -y
yum install -y docker || amazon-linux-extras install docker -y
yum install -y nc jq tmux
systemctl start docker
systemctl enable docker
#################################
# Docker Compose v1 installation
#################################
curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
docker-compose --version
#################################
# Docker Compose V2 Installation
#################################
#########################################################################################
# 1 Run the following command to download the current stable release of Docker Compose
#########################################################################################
mkdir -p ~/.docker/cli-plugins/
curl -SL https://github.com/docker/compose/releases/download/v2.0.1/docker-compose-linux-x86_64 -o ~/.docker/cli-plugins/docker-compose
###############################################
# 2 Apply executable permissions to the binary
###############################################
chmod +x ~/.docker/cli-plugins/docker-compose
###############################################
# 3 Apply executable permissions to the binary
###############################################
docker compose version
################################
# CodeDeploy Agent Installation
################################
yum update -y
yum install ruby -y
yum install wget -y
cd /home/ec2-user
wget https://aws-codedeploy-us-east-1.s3.us-east-1.amazonaws.com/latest/install
chmod +x ./install
./install auto
./install auto -v releases/codedeploy-agent-###.rpm
service codedeploy-agent status
service codedeploy-agent start
systemctl enable codedeploy-agent
################################
# CloudWatch Agent Enable
################################
# Automation
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/identify_ec2_instances.html
yum install -y amazon-cloudwatch-agent
INSTANCE_ID=$(cat /sys/devices/virtual/dmi/id/board_asset_tag)
cat << EOF > /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml
[agent]
collection_jitter = "0s"
debug = false
flush_interval = "1s"
flush_jitter = "0s"
hostname = ""
interval = "60s"
logfile = "/opt/aws/amazon-cloudwatch-agent/logs/amazon-cloudwatch-agent.log"
logtarget = "lumberjack"
metric_batch_size = 1000
metric_buffer_limit = 10000
omit_hostname = false
precision = ""
quiet = false
round_interval = false
[inputs]
[[inputs.disk]]
fieldpass = ["used_percent"]
tagexclude = ["mode"]
[inputs.disk.tags]
metricPath = "metrics"
[[inputs.logfile]]
destination = "cloudwatchlogs"
file_state_folder = "/opt/aws/amazon-cloudwatch-agent/logs/state"
[[inputs.logfile.file_config]]
file_path = "/var/log/cfn-hup.log"
from_beginning = true
log_group_name = "EC2-CloudWatchLogs"
log_stream_name = "$INSTANCE_ID/cfn-hup.log"
pipe = false
timezone = "UTC"
[[inputs.logfile.file_config]]
file_path = "/var/log/cfn-init.log"
from_beginning = true
log_group_name = "EC2-CloudWatchLogs"
log_stream_name = "$INSTANCE_ID/cfn-init.log"
pipe = false
timezone = "UTC"
[[inputs.logfile.file_config]]
file_path = "/var/log/cfn-init-cmd.log"
from_beginning = true
log_group_name = "EC2-CloudWatchLogs"
log_stream_name = "$INSTANCE_ID/cfn-init-cmd.log"
pipe = false
timezone = "UTC"
[[inputs.logfile.file_config]]
file_path = "/var/log/cloud-init.log"
from_beginning = true
log_group_name = "EC2-CloudWatchLogs"
log_stream_name = "$INSTANCE_ID/cloud-init.log"
pipe = false
timezone = "UTC"
[[inputs.logfile.file_config]]
file_path = "/var/log/cloud-init-output.log"
from_beginning = true
log_group_name = "EC2-CloudWatchLogs"
log_stream_name = "$INSTANCE_ID/cloud-init-output.log"
pipe = false
timezone = "UTC"
[[inputs.logfile.file_config]]
file_path = "/var/log/cfn-wire.log"
from_beginning = true
log_group_name = "EC2-CloudWatchLogs"
log_stream_name = "$INSTANCE_ID/cfn-wire.log"
pipe = false
timezone = "UTC"
[inputs.logfile.tags]
metricPath = "logs"
[[inputs.mem]]
fieldpass = ["used_percent"]
[inputs.mem.tags]
metricPath = "metrics"
[outputs]
[[outputs.cloudwatch]]
force_flush_interval = "60s"
namespace = "CWAgent"
region = "us-east-1"
tagexclude = ["host", "metricPath"]
[outputs.cloudwatch.tagpass]
metricPath = ["metrics"]
[[outputs.cloudwatchlogs]]
force_flush_interval = "5s"
log_stream_name = "$INSTANCE_ID"
region = "us-east-1"
tagexclude = ["metricPath"]
[outputs.cloudwatchlogs.tagpass]
metricPath = ["logs"]
[processors]
[[processors.ec2tagger]]
ec2_metadata_tags = ["InstanceId"]
refresh_interval_seconds = "0s"
[processors.ec2tagger.tagpass]
metricPath = ["metrics"]
EOF
# https://stackoverflow.com/questions/10309968/sed-search-and-replace-strings-containing
LINE_OLD='/opt/aws/amazon-cloudwatch-agent/bin/start-amazon-cloudwatch-agent'
LINE_NEW='/opt/aws/amazon-cloudwatch-agent/bin/amazon-cloudwatch-agent -config /opt/aws/amazon-cloudwatch-agent/etc/amazon-cloudwatch-agent.toml'
sed -i "s%$LINE_OLD%$LINE_NEW%g" /etc/systemd/system/amazon-cloudwatch-agent.service
systemctl daemon-reload
systemctl start amazon-cloudwatch-agent
systemctl enable amazon-cloudwatch-agent
#END