-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy path3rd-Bootstrap_Photon-3-HVM.sh
595 lines (457 loc) · 24.6 KB
/
3rd-Bootstrap_Photon-3-HVM.sh
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
#!/bin/bash -v
set -e -x
# Logger
exec > >(tee /var/log/user-data_3rd-bootstrap.log || logger -t user-data -s 2> /dev/console) 2>&1
#-------------------------------------------------------------------------------
# Set UserData Parameter
#-------------------------------------------------------------------------------
if [ -f /tmp/userdata-parameter ]; then
source /tmp/userdata-parameter
fi
if [[ -z "${Language}" || -z "${Timezone}" || -z "${VpcNetwork}" ]]; then
# Default Language
Language="en_US.UTF-8"
# Default Timezone
Timezone="Asia/Tokyo"
# Default VPC Network
VpcNetwork="IPv4"
fi
# echo
echo $Language
echo $Timezone
echo $VpcNetwork
#-------------------------------------------------------------------------------
# Parameter Settings
#-------------------------------------------------------------------------------
# Parameter Settings
CWAgentConfig="https://raw.githubusercontent.com/usui-tk/amazon-ec2-userdata/master/Config_AmazonCloudWatchAgent/AmazonCloudWatchAgent_Photon-3-HVM.json"
#-------------------------------------------------------------------------------
# Acquire unique information of Linux distribution
# - Photon OS 3
# https://vmware.github.io/photon/
# https://vmware.github.io/photon/#documentation
#
# https://github.com/vmware/photon
# https://github.com/vmware/photon/wiki
#
#-------------------------------------------------------------------------------
# Cleanup repository information
tdnf clean all
# Show Linux Distribution/Distro information
if [ $(command -v lsb_release) ]; then
lsb_release -a
fi
# Show Linux System Information
uname -a
# Show Linux distribution release Information
cat /etc/os-release
# Default installation package [rpm command]
rpm -qa --qf="%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}\n" | sort > /tmp/command-log_rpm_installed-package.txt
# Default installation package [tdnf command]
tdnf list installed > /tmp/command-log_tdnf_installed-package.txt
# Default repository package [tdnf command]
tdnf list all > /tmp/command-log_tdnf_repository-package-list.txt
# Default repository list [tdnf command]
tdnf repolist all > /tmp/command-log_tdnf_repository-list.txt
# systemd unit files
systemctl list-unit-files --all --no-pager > /tmp/command-log_systemctl_list-unit-files.txt
# systemd service config
systemctl list-units --type=service --all --no-pager > /tmp/command-log_systemctl_list-service-config.txt
#-------------------------------------------------------------------------------
# Default Package Update
#-------------------------------------------------------------------------------
# Cleanup repository information
tdnf clean all
# Default Package Update (Packages Related to tdnf)
tdnf update -y tdnf
# Checking repository information
tdnf repolist all
# Get tdnf Repository List (Exclude tdnf repository related to "beta, debug, source, test, iso")
# repolist=$(tdnf repolist all --quiet | grep -ie "enabled" -ie "disabled" | grep -ve "beta" -ve "debug" -ve "source" -ve "test" -ve "iso" | awk '{print $1}' | awk '{ sub("/.*$",""); print $0; }' | sort)
# Cleanup repository information
tdnf clean all
# Default Package Update
tdnf update -y
#-------------------------------------------------------------------------------
# Custom Package Installation
#-------------------------------------------------------------------------------
# Package Install Photon Linux-Kernel Modules and Tools (from VMware Photon OS Official Repository)
tdnf install -y linux-aws-oprofile
# Package Install Photon System Administration Tools (from VMware Photon OS Official Repository)
tdnf install -y bc bcc bcc-tools blktrace curl dstat ebtables ethtool expect hdparm intltool iotop jq kexec-tools lsof lvm2 man-pages mlocate nvme-cli parted pmd pmd-cli pmd-python3 psmisc rsync strace sysstat tcpdump traceroute tree unzip wget xfsprogs zip zsh
tdnf install -y cifs-utils nfs-utils
tdnf install -y lsscsi sg3_utils
# Package Install Python 3 Runtime (from VMware Photon OS Official Repository)
tdnf install -y python3 python3-devel python3-pip python3-setuptools python3-test python3-tools python3-virtualenv
tdnf install -y python3-asn1crypto python3-bcc python3-curses python3-dateutil python3-docutils python3-jmespath python3-jsonschema python3-pyasn1 python3-pyasn1-modules python3-PyYAML python3-requests python3-simplejson python3-six python3-urllib3 python3-websocket-client
#-------------------------------------------------------------------------------
# Get AWS Instance MetaData Service (IMDS v1, v2)
# https://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html
# https://docs.aws.amazon.com/ja_jp/AWSEC2/latest/UserGuide/instancedata-data-retrieval.html
#-------------------------------------------------------------------------------
# Getting an Instance Metadata Service v2 (IMDS v2) token
TOKEN=`curl -X PUT "http://169.254.169.254/latest/api/token" -H "X-aws-ec2-metadata-token-ttl-seconds: 21600"`
if [ -n "$TOKEN" ]; then
#-----------------------------------------------------------------------
# Retrieving Metadata Using the Instance Metadata Service v2 (IMDS v2)
#-----------------------------------------------------------------------
# Instance MetaData
Az=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s "http://169.254.169.254/latest/meta-data/placement/availability-zone")
AzId=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s "http://169.254.169.254/latest/meta-data/placement/availability-zone-id")
Region=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s "http://169.254.169.254/latest/meta-data/placement/region")
InstanceId=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s "http://169.254.169.254/latest/meta-data/instance-id")
InstanceType=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s "http://169.254.169.254/latest/meta-data/instance-type")
PrivateIp=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s "http://169.254.169.254/latest/meta-data/local-ipv4")
AmiId=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s "http://169.254.169.254/latest/meta-data/ami-id")
# IAM Role & STS Information
if [ $(compgen -ac | sort | uniq | grep -x jq) ]; then
RoleArn=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s "http://169.254.169.254/latest/meta-data/iam/info" | jq -r '.InstanceProfileArn')
RoleName=$(echo $RoleArn | cut -d '/' -f 2)
fi
if [ -n "$RoleName" ]; then
StsCredential=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s "http://169.254.169.254/latest/meta-data/iam/security-credentials/$RoleName")
if [ $(compgen -ac | sort | uniq | grep -x jq) ]; then
StsAccessKeyId=$(echo $StsCredential | jq -r '.AccessKeyId')
StsSecretAccessKey=$(echo $StsCredential | jq -r '.SecretAccessKey')
StsToken=$(echo $StsCredential | jq -r '.Token')
fi
fi
# AWS Account ID
if [ $(compgen -ac | sort | uniq | grep -x jq) ]; then
AwsAccountId=$(curl -H "X-aws-ec2-metadata-token: $TOKEN" -s "http://169.254.169.254/latest/dynamic/instance-identity/document" | jq -r '.accountId')
fi
else
#-----------------------------------------------------------------------
# Retrieving Metadata Using the Instance Metadata Service v1 (IMDS v1)
#-----------------------------------------------------------------------
# Instance MetaData
Az=$(curl -s "http://169.254.169.254/latest/meta-data/placement/availability-zone")
AzId=$(curl -s "http://169.254.169.254/latest/meta-data/placement/availability-zone-id")
Region=$(curl -s "http://169.254.169.254/latest/meta-data/placement/region")
InstanceId=$(curl -s "http://169.254.169.254/latest/meta-data/instance-id")
InstanceType=$(curl -s "http://169.254.169.254/latest/meta-data/instance-type")
PrivateIp=$(curl -s "http://169.254.169.254/latest/meta-data/local-ipv4")
AmiId=$(curl -s "http://169.254.169.254/latest/meta-data/ami-id")
# IAM Role & STS Information
if [ $(compgen -ac | sort | uniq | grep -x jq) ]; then
RoleArn=$(curl -s "http://169.254.169.254/latest/meta-data/iam/info" | jq -r '.InstanceProfileArn')
RoleName=$(echo $RoleArn | cut -d '/' -f 2)
fi
if [ -n "$RoleName" ]; then
StsCredential=$(curl -s "http://169.254.169.254/latest/meta-data/iam/security-credentials/$RoleName")
if [ $(compgen -ac | sort | uniq | grep -x jq) ]; then
StsAccessKeyId=$(echo $StsCredential | jq -r '.AccessKeyId')
StsSecretAccessKey=$(echo $StsCredential | jq -r '.SecretAccessKey')
StsToken=$(echo $StsCredential | jq -r '.Token')
fi
fi
# AWS Account ID
if [ $(compgen -ac | sort | uniq | grep -x jq) ]; then
AwsAccountId=$(curl -s "http://169.254.169.254/latest/dynamic/instance-identity/document" | jq -r '.accountId')
fi
fi
#-------------------------------------------------------------------------------
# Custom Package Installation [AWS-CLI v2]
# https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2-linux.html
#-------------------------------------------------------------------------------
# Package download AWS-CLI v2 Tools (from Bundle Installer)
curl -sS "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "/tmp/awscliv2.zip"
unzip -oq "/tmp/awscliv2.zip" -d /tmp/
# Package Install AWS-CLI v2 Tools (from Bundle Installer)
/tmp/aws/install -i "/opt/aws/awscli" -b "/usr/bin" --update
aws --version
# Setting AWS-CLI default Region & Output format
aws configure << __EOF__
${Region}
json
__EOF__
# Setting AWS-CLI Logging
aws configure set cli_history enabled
# Setting AWS-CLI Pager settings
aws configure set cli_pager ''
# Getting AWS-CLI default Region & Output format
aws configure list
cat ~/.aws/config
#------------------------------------------------------------------------------
# Getting information about AWS services
#------------------------------------------------------------------------------
# Get AWS Security Token Service (AWS STS) Information
if [ -n "$RoleName" ]; then
echo "# Get AWS Security Token Service (AWS STS) Information"
aws sts get-caller-identity --output json
fi
# Get AWS Region List
if [ -n "$RoleName" ]; then
echo "# Get AWS Region List"
aws ec2 describe-regions --region ${Region} > "/var/log/user-data_aws-cli_aws-services_describe-regions.txt"
fi
# Get Amazon EC2 Instance Type List
if [ -n "$RoleName" ]; then
echo "# Get Amazon EC2 Instance Type List"
aws ec2 describe-instance-types --query 'InstanceTypes[?Hypervisor==`nitro`]' --output json --region ${Region} > "/var/log/user-data_aws-cli_aws-services_describe-instance-types_nitro-hypervisor.txt"
aws ec2 describe-instance-types --query 'InstanceTypes[?Hypervisor==`xen`]' --output json --region ${Region} > "/var/log/user-data_aws-cli_aws-services_describe-instance-types_xen-hypervisor.txt"
fi
#------------------------------------------------------------------------------
# Getting information about Amazon EC2 Instance
#------------------------------------------------------------------------------
# Get Amazon EC2 Instance Information
if [ -n "$RoleName" ]; then
echo "# Get Amazon EC2 Instance Information"
aws ec2 describe-instances --instance-ids ${InstanceId} --output json --region ${Region} > "/var/log/user-data_aws-cli_amazon-ec2-instance_describe-instances.txt"
fi
# Get Amazon EC2 Instance Type Information
if [ -n "$RoleName" ]; then
echo "# Get Amazon EC2 Instance Type Information"
aws ec2 describe-instance-types --query "InstanceTypes[?InstanceType==\`${InstanceType}\`]" --output json --region ${Region} > "/var/log/user-data_aws-cli_amazon-ec2-instance_describe-instance-types.txt"
fi
# Get Amazon EC2 Instance attached EBS Volume Information
if [ -n "$RoleName" ]; then
echo "# Get Amazon EC2 Instance attached EBS Volume Information"
aws ec2 describe-volumes --filters Name=attachment.instance-id,Values=${InstanceId} --output json --region ${Region} > "/var/log/user-data_aws-cli_amazon-ec2-instance_describe-volumes.txt"
fi
# Get Amazon EC2 Instance attached VPC Security Group Information
if [ -n "$RoleName" ]; then
echo "# Get Amazon EC2 Instance attached VPC Security Group Information"
aws ec2 describe-security-groups --group-ids $(aws ec2 describe-instances --instance-id ${InstanceId} --query "Reservations[].Instances[].SecurityGroups[].GroupId[]" --output text --region ${Region}) --output json --region ${Region} > "/var/log/user-data_aws-cli_amazon-ec2-instance_describe-security-groups.txt"
fi
# Get AMI information of this Amazon EC2 instance
if [ -n "$RoleName" ]; then
echo "# Get AMI information of this Amazon EC2 instance"
aws ec2 describe-images --image-ids ${AmiId} --output json --region ${Region} > "/var/log/user-data_aws-cli_amazon-ec2-instance_describe-images.txt"
fi
#------------------------------------------------------------------------------
# Getting information about Amazon EC2 Instance Attribute
# [Network Interface Performance Attribute]
#------------------------------------------------------------------------------
# - Summary of Networking and Storage Features
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html#instance-type-summary-table
# - ENA (Elastic Network Adapter)
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/enhanced-networking-ena.html
# - ENA Express (Elastic Network Adapter Express)
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ena-express.html
# - Elastic Fabric Adapter (EFA)
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/efa.html
# - Single-root I/O virtualization (SR-IOV)
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/sriov-networking.html
#------------------------------------------------------------------------------
# Get EC2 Instance Attribute [Network Interface Performance Attribute]
if [ -n "$RoleName" ]; then
echo "# Get EC2 Instance Attribute [Network Interface Performance Attribute]"
# Get EC2 Instance Attribute [Network Interface Performance Attribute - ENA (Elastic Network Adapter)]
if [[ $(aws ec2 describe-instance-types --filters "Name=instance-type,Values=${InstanceType}" --query "InstanceTypes[].NetworkInfo.EnaSupport" --output text --region ${Region}) == "required" ]]; then
echo "EnaSupport is available for $InstanceType"
echo "# Get EC2 Instance Attribute [Network Interface Performance Attribute - ENA (Elastic Network Adapter)]"
aws ec2 describe-instance-types --filters "Name=instance-type,Values=${InstanceType}" --query "InstanceTypes[].NetworkInfo" --output json --region ${Region} > "/var/log/user-data_aws-cli_amazon-ec2-instance_describe-instance-types_NetworkInfo_ENA.txt"
# Get Linux Kernel Module(modinfo ena)
echo "# Get Linux Kernel Module(modinfo ena)"
if [ $(lsmod | awk '{print $1}' | grep -x ena) ]; then
modinfo ena
if [ $(command -v nmcli) ]; then
# Get Network Interface Information
ethtool -S $(nmcli -t -f DEVICE device | grep -v lo)
ethtool -c $(nmcli -t -f DEVICE device | grep -v lo)
fi
fi
fi
# Get EC2 Instance Attribute [Network Interface Performance Attribute - ENA Express (Elastic Network Adapter Express)]
if [[ $(aws ec2 describe-instance-types --filters "Name=instance-type,Values=${InstanceType}" --query "InstanceTypes[].NetworkInfo.EnaSrdSupported" --output text --region ${Region}) == "true" ]]; then
echo "EnaSrdSupported is available for $InstanceType"
echo "# Get EC2 Instance Attribute [Network Interface Performance Attribute - ENA Express (Elastic Network Adapter Express)]"
aws ec2 describe-instance-types --filters "Name=instance-type,Values=${InstanceType}" --query "InstanceTypes[].NetworkInfo" --output json --region ${Region} > "/var/log/user-data_aws-cli_amazon-ec2-instance_describe-instance-types_NetworkInfo_ENA_Express.txt"
# Get Linux Kernel Module(modinfo ena)
echo "# Get Linux Kernel Module(modinfo ena)"
if [ $(lsmod | awk '{print $1}' | grep -x ena) ]; then
modinfo ena
if [ $(command -v nmcli) ]; then
# Get Network Interface Information
ethtool -S $(nmcli -t -f DEVICE device | grep -v lo)
ethtool -c $(nmcli -t -f DEVICE device | grep -v lo)
fi
fi
fi
# Get EC2 Instance Attribute [Network Interface Performance Attribute - Elastic Fabric Adapter (EFA)]
if [[ $(aws ec2 describe-instance-types --filters "Name=instance-type,Values=${InstanceType}" --query "InstanceTypes[].NetworkInfo.EfaSupported" --output text --region ${Region}) == "true" ]]; then
echo "EfaSupported is available for $InstanceType"
echo "# Get EC2 Instance Attribute [Network Interface Performance Attribute - Elastic Fabric Adapter (EFA)]"
aws ec2 describe-instance-types --filters "Name=instance-type,Values=${InstanceType}" --query "InstanceTypes[].NetworkInfo" --output json --region ${Region} > "/var/log/user-data_aws-cli_amazon-ec2-instance_describe-instance-types_NetworkInfo_EFA.txt"
fi
# Get EC2 Instance Attribute [Network Interface Performance Attribute - Single-root I/O virtualization (SR-IOV)]
if [[ $(aws ec2 describe-instance-attribute --instance-id $InstanceId --attribute sriovNetSupport --query 'SriovNetSupport.Value' --output text --region ${Region}) == "simple" ]]; then
echo "SriovNetSupport is available for $InstanceType"
echo "# Get EC2 Instance Attribute [Network Interface Performance Attribute - Single-root I/O virtualization (SR-IOV)]"
aws ec2 describe-instance-attribute --instance-id $InstanceId --attribute sriovNetSupport --output json --region ${Region} > "/var/log/user-data_aws-cli_amazon-ec2-instance_describe-instance-types_NetworkInfo_SR-IOV.txt"
# Get Linux Kernel Module(modinfo ixgbevf)
echo "# Get Linux Kernel Module(modinfo ixgbevf)"
if [ $(lsmod | awk '{print $1}' | grep -x ixgbevf) ]; then
modinfo ixgbevf
if [ $(command -v nmcli) ]; then
# Get Network Interface Information
ethtool -S $(nmcli -t -f DEVICE device | grep -v lo)
ethtool -c $(nmcli -t -f DEVICE device | grep -v lo)
fi
fi
fi
fi
#------------------------------------------------------------------------------
# Getting information about Amazon EC2 Instance Attribute
# [Storage Interface Performance Attribute]
#------------------------------------------------------------------------------
# - Summary of Networking and Storage Features
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html#instance-type-summary-table
# - EBS Optimized Instance
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSOptimized.html
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/EBSPerformance.html
# - Nitro-based Instances
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-types.html#ec2-nitro-instances
# - Amazon EBS and NVMe Volumes
# http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/nvme-ebs-volumes.html
# - SSD Instance Store Volumes
# https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ssd-instance-store.html
#------------------------------------------------------------------------------
# Get EC2 Instance Attribute [Storage Interface Performance Attribute]
if [ -n "$RoleName" ]; then
echo "# Get EC2 Instance Attribute [Storage Interface Performance Attribute]"
# Get EC2 Instance Attribute [Storage Interface Performance Attribute - EBS Optimized Instance]
if [[ $(aws ec2 describe-instance-types --filters "Name=instance-type,Values=${InstanceType}" --query "InstanceTypes[].EbsInfo.EbsOptimizedSupport" --output text --region ${Region}) == "default" ]]; then
echo "EbsOptimizedSupport is available for $InstanceType"
echo "# Get EC2 Instance Attribute [Storage Interface Performance Attribute - EBS Optimized Instance]"
aws ec2 describe-instance-types --filters "Name=instance-type,Values=${InstanceType}" --query "InstanceTypes[].EbsInfo" --output json --region ${Region} > "/var/log/user-data_aws-cli_amazon-ec2-instance_describe-instance-types_EbsInfo.txt"
fi
# Get EC2 Instance Attribute [Storage Interface Performance Attribute - Amazon EBS and NVMe Volumes]
if [[ $(aws ec2 describe-instance-types --filters "Name=instance-type,Values=${InstanceType}" --query "InstanceTypes[].EbsInfo.NvmeSupport" --output text --region ${Region}) == "required" ]]; then
echo "NvmeSupport is available for $InstanceType"
# Get Linux Kernel Module(modinfo nvme)
echo "# Get Linux Kernel Module(modinfo nvme)"
if [ $(lsmod | awk '{print $1}' | grep -x nvme) ]; then
modinfo nvme
fi
# Get NVMe Device(nvme list)
# http://www.spdk.io/doc/nvme-cli.html
# https://github.com/linux-nvme/nvme-cli
if [ $(command -v nvme) ]; then
echo "# Get NVMe Device(nvme list)"
nvme list
fi
fi
fi
# Get PCI-Express Device(lspci -v)
if [ $(command -v lspci) ]; then
echo "# Get PCI-Express Device(lspci -v)"
lspci -v
fi
# Get Disk[MountPoint] Information (lsblk -a)
if [ $(command -v lsblk) ]; then
echo "# Get Disk[MountPoint] Information (lsblk -a)"
lsblk -a
fi
# Get Linux Block Device Read-Ahead Value(blockdev --report)
if [ $(command -v blockdev) ]; then
echo "# Get Linux Block Device Read-Ahead Value(blockdev --report)"
blockdev --report
fi
#-------------------------------------------------------------------------------
# Custom Package Installation [AWS Systems Manager agent (aka SSM agent)]
# http://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/sysman-install-ssm-agent.html
# https://github.com/aws/amazon-ssm-agent
#-------------------------------------------------------------------------------
curl -sS "https://s3.amazonaws.com/ec2-downloads-windows/SSMAgent/latest/linux_amd64/amazon-ssm-agent.rpm" -o "/tmp/amazon-ssm-agent.rpm"
rpm -ivh /tmp/amazon-ssm-agent.rpm
rpm -qi amazon-ssm-agent
systemctl daemon-reload
systemctl restart amazon-ssm-agent
systemctl status -l amazon-ssm-agent
# Configure AWS Systems Manager Agent software (Start Daemon awsagent)
if [ $(systemctl is-enabled amazon-ssm-agent) = "disabled" ]; then
systemctl enable amazon-ssm-agent
systemctl is-enabled amazon-ssm-agent
fi
ssm-cli get-instance-information
#-------------------------------------------------------------------------------
# Custom Package Installation [Amazon EC2 Rescue for Linux (ec2rl)]
# http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/Linux-Server-EC2Rescue.html
# https://github.com/awslabs/aws-ec2rescue-linux
#-------------------------------------------------------------------------------
# Package Amazon EC2 Administration Tools (from S3 Bucket)
curl -sS "https://s3.amazonaws.com/ec2rescuelinux/ec2rl-bundled.tgz" -o "/tmp/ec2rl-bundled.tgz"
mkdir -p "/opt/aws"
rm -rf /opt/aws/ec2rl*
tar -xzf "/tmp/ec2rl-bundled.tgz" -C "/opt/aws"
mv --force /opt/aws/ec2rl* "/opt/aws/ec2rl"
cat > /etc/profile.d/ec2rl.sh << __EOF__
export PATH=\$PATH:/opt/aws/ec2rl
__EOF__
source /etc/profile.d/ec2rl.sh
# Check Version
/opt/aws/ec2rl/ec2rl version
/opt/aws/ec2rl/ec2rl list
# Required Software Package
/opt/aws/ec2rl/ec2rl software-check
# Diagnosis [dig modules]
# /opt/aws/ec2rl/ec2rl run --only-modules=dig --domain=amazon.com
#-------------------------------------------------------------------------------
# Custom Package Installation [Ansible]
#-------------------------------------------------------------------------------
# Package Install Photon System Administration Tools (from VMware Photon OS Official Repository)
# tdnf install -y ansible
# ansible --version
# ansible localhost -m setup
# Package Install Ansible (from Python Package Index (PyPI) Repository)
pip3 install ansible
pip3 show ansible
which ansible
ansible --version
ansible localhost -m setup
#-------------------------------------------------------------------------------
# Custom Package Clean up
#-------------------------------------------------------------------------------
tdnf clean all
#-------------------------------------------------------------------------------
# System information collection
#-------------------------------------------------------------------------------
# CPU Information [cat /proc/cpuinfo]
cat /proc/cpuinfo
# CPU Information [lscpu]
lscpu
lscpu --extended
# Memory Information [cat /proc/meminfo]
cat /proc/meminfo
# Memory Information [free]
free
# Disk Information(Partition) [parted -l]
parted -l
# Disk Information(MountPoint) [lsblk -f]
lsblk -f
# Disk Information(File System) [df -khT]
df -khT
# Network Information(Network Interface) [ip addr show]
ip addr show
# Network Information(Routing Table) [ip route show]
ip route show
#-------------------------------------------------------------------------------
# System Setting
#-------------------------------------------------------------------------------
# Setting SystemClock and Timezone
if [ "${Timezone}" = "Asia/Tokyo" ]; then
echo "# Setting SystemClock and Timezone -> $Timezone"
date
timedatectl status --all --no-pager
timedatectl set-timezone Asia/Tokyo
timedatectl status --all --no-pager
date
elif [ "${Timezone}" = "UTC" ]; then
echo "# Setting SystemClock and Timezone -> $Timezone"
date
timedatectl status --all --no-pager
timedatectl set-timezone UTC
timedatectl status --all --no-pager
date
else
echo "# Default SystemClock and Timezone"
timedatectl status --all --no-pager
date
fi
#-------------------------------------------------------------------------------
# Reboot
#-------------------------------------------------------------------------------
# Instance Reboot
reboot