Using the AWS-CLI to set instance
Using the AWS-CLI to set instance
- CS615
- Ankai Liang
- 10411998
- link: http://www.cs.stevens.edu/~jschauma/615/s17-hw2.html
Run 1
Use script
to log
1 | KKs-MacBook-Air:~ kk$ Script -ar timestamps |
Create two AWS instances of a given OS (First time I choose OmniOS)
Using the infomation in Assignment1
1 | bash-3.2$ aws ec2 run-instances --image-id ami-50ecc847 --count 2 --instance-type t1.micro --key-name keypair3 --security-groups mysg |
Get the info of my two instances
1 | bash-3.2$ aws ec2 describe-instances --filters "Name=image-id,Values=ami-50ecc847" |
Create a 1GB volume and attach it to one of the instances
According to the above infomation, I knew the instances-id and public DNS of my two running OmniOs instances:
- i-0ab15f53de99f4dff ec2-52-55-98-238.compute-1.amazonaws.com
- i-0f177e140a2d45383 ec2-54-166-108-26.compute-1.amazonaws.com
Because I used to reboot the second instance, the public DNS has changed. It’s not a necessary step, I omit that part.
And their “AvailabilityZone” is “us-east-1d”
I create the colume and attach it to the first instance “/dev/sdf”.
1 | bash-3.2$ aws ec2 create-volume --no-dry-run --size 1 --availability-zone us-east-1d --volume-type gp2 --no-encrypted |
Create the file system in the volume, mount it to the first instance then create a file.
In this section, I met a lot of troubles to create the file system. After command format
, I got the DISK device-name is ‘c1t2144d0’.
But I cannot run by command newfs c1t2144d0
or newfs /devices/xpvd/xdf@2144
. CLI told me “it’s not a raw device”. After searching lots of blog and tutorial, I knew that newfs parameter ‘address’ should locate into /dev/rdsk
. But under the directory /dev/rdsk
, there isn’t file whose name is ‘c1t2144d0’. By comparing the example command and the files name in /dev/rdsk
, I realized that the volume has been divided into slices, and I should use the ‘c1t2144d0s0’ as the part of parameter.
In the OmniOS, I create a UFS file system. The OmniOS also support ZFS, but the creation of ZFS is more complecate than UFS.
Using the command newfs
. newfs
is a friendly front-end command of mkfs
. It could caculate the properly parameters then transfer to mkfs
to run.
1 | root@ip-10-152-178-106.ec2.internal:/root# format |
Create a file(testfile).
1 | root@ip-10-152-178-106.ec2.internal:/# cd / |
Terminate the first OmniOS instace
1 | bash-3.2$ aws ec2 terminate-instances --instance-ids i-0ab15f53de99f4dff |
Attach the volume to the second instance
The volume id is: vol-0a3064debd17cede4
The second instance id is: i-0f177e140a2d45383
The second instance public DNS is: ec2-54-166-108-26.compute-1.amazonaws.com
Check the state of this volume.
1 | bash-3.2$ aws ec2 describe-volumes --filters Name=volume-id,Values=vol-0a3064debd17cede4 |
We find that its state is available.
1 | bash-3.2$ aws ec2 attach-volume --volume-id vol-0a3064debd17cede4 --instance-id i-0f177e140a2d45383 --device /dev/sdf |
SSH to the seconde instance, mount the volume and retrieve the file we just created.
1 | bash-3.2$ pwd |
Retrieve the file.
Then we use scp
to retrieve the file.
1 | root@ip-172-31-51-44:/data# exit |
Run 2
Use script
to log
1 | KKs-MacBook-Air:~ kk$ Script -ar timestamps |
Create two AWS instances of a given OS (First time I choose Linux)
1 | bash-3.2$ aws ec2 run-instances --image-id ami-0b33d91d --count 1 --instance-type t2.micro --key-name keypair3 --security-groups mysg |
Get the info of my two instances
1 | bash-3.2$ aws ec2 describe-instances --filters "Name=image-id,Values=ami-0b33d91d" |
Create a 1GB volume and attach it to one of the instances
According to the above infomation, I knew the instance id and public DNS of my two running Linux instances:
i-0892e3a2148d40757 ec2-54-242-31-152.compute-1.amazonaws.com
i-03c597e94f5bd3809 ec2-54-165-167-87.compute-1.amazonaws.com
And their “AvailabilityZone” is “us-east-1d”
I create the colume and attach it to the first instance “/dev/sdf”.
1 | bash-3.2$ aws ec2 create-volume --no-dry-run --size 1 --availability-zone us-east-1b --volume-type gp2 --no-encrypted |
Create the new file system on the first linux instance
- Use lsblk to view available disk devices and their mount points.
- Determine whether we need to create a file system on the volume. In Linux, use the sudo file -s device command to list special information.
- Make a new file system by using command mkfs.
- Check again on step 2.
- Create a mount point directory for the volume.
- Mount the volume at the location we just created.
In Linux, I create a exts4 type file system. Using the command mkfs
, we could use -t
to point out which type we want to create.
1 | bash-3.2$ ssh -i p.pem ec2-user@ec2-54-242-31-152.compute-1.amazonaws.com |
Then we create a file (‘TestFile’) in this volume
1 | [ec2-user@ip-172-31-26-132 ~]$ sudo chmod 777 data |
Terminate the first Linux instace
1 | [ec2-user@ip-172-31-26-132 data]$ exit |
Attach the volume to the second instance
The volume id is: vol-020bf1f8883a55593
The second instance id is:i-03c597e94f5bd3809
The second instance public DNS is: ec2-54-165-167-87.compute-1.amazonaws.com
Check the state of this volume.
1 | bash-3.2$ aws ec2 describe-volumes --filters Name=volume-id,Values=vol-020bf1f8883a55593 |
We find that its state is available. Attach it to the second instance.
1 | bash-3.2$ aws ec2 attach-volume --volume-id vol-020bf1f8883a55593 --instance-id i-03c597e94f5bd3809 --device /dev/sdf |
SSH to the seconde instance, mount the volume and retrieve the file we just created.
1 | bash-3.2$ pwd |
Then we use scp
to retrieve the file.
1 | bash-3.2$ scp -i p.pem ec2-user@ec2-54-165-167-87.compute-1.amazonaws.com:~/data/TestFile ~/Documents/Testfile |
#Run 3
Test Can I use the same volume / filesystem across different OS instances
The volume id we create in OmniOS: vol-0a3064debd17cede4
unmount the volume
1 | bash-3.2$ cd Documents |
Reboot the instance of OmniOS
1 | root@ip-172-31-51-44:/root# shutdown -y -i6 -g0 |
Detach it
1 | bash-3.2$ aws ec2 detach-volume --volume-id vol-0a3064debd17cede4 |
OH! After I detach the volume, the volume immediately was terminated… I would try to create another one with file system in OmniOS.
Wait…I don’n know what happen. The volume state change from terminated
to running
. Never mind, keep test.
Check the state of this volume.
1 | bash-3.2$ aws ec2 describe-volumes --filters Name=volume-id,Values=vol-0a3064debd17cede4 |
Creat a linux instance in us-east-1d
1 | bash-3.2$ aws ec2 run-instances --image-id ami-0b33d91d --count 1 --instance-type t2.micro --placement AvailabilityZone=us-east-1d --key-name keypair3 --security-groups mysg |
Get the info of this instance
1 | bash-3.2$ aws ec2 describe-instances --filters "Name=instance-id,Values=i-0e28b8fb27b75b707" |
Attach the volume to the instance
We knew:
The volume id is: vol-0a3064debd17cede4
instance-id = i-0e28b8fb27b75b707
public DNS = ec2-52-70-181-33.compute-1.amazonaws.com
1 | bash-3.2$ aws ec2 attach-volume --volume-id vol-0a3064debd17cede4 --instance-id i-0e28b8fb27b75b707 --device /dev/sdf |
SSH to the instance of Linux, mount the volume and check the file.
1 | bash-3.2$ pwd |
Conclusion
We can use the same volume / filesystem across different OS instances.
But the volumn was write-protected state, mounting read-only.
I found something in this web:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/monitoring-volume-status.html
“When Amazon EBS determines that a volume’s data is potentially inconsistent, it disables I/O to the volume from any attached EC2 instances by default. This causes the volume status check to fail, and creates a volume status event that indicates the cause of the failure.”
Check the Attribute of autoEnableIO
1 | bash-3.2$ aws ec2 describe-volume-attribute --volume-id vol-0a3064debd17cede4 --attribute autoEnableIO |
Active the AutoEnableIO.
1 | bash-3.2$ aws ec2 modify-volume-attribute --volume-id vol-0a3064debd17cede4 --auto-enable-io |
But after setting and reboot the instance, mounting still is read-only…
I check the mount
1 | [ec2-user@ip-172-31-48-166 data]$ mount | grep xvdf |
I think the reason why volume lock is that this ufstype is too old… So this Linux cann’t support.