공유 AMI로부터 가상 머신 시작하기
이 워크샵 섹션에서는 워크샵의 뒷부분에서 분석을 실행하는 데 사용할 사전 제작된 AMI에서 자체 EC2 Linux 인스턴스를 설정하는 방법을 안내합니다.
여기서는 NUS와 GIS의 Chen Lab에서 구축한 이미지를 사용할 것입니다. 여기에는 박테리아(및 일반) 유전체학에 유용한 많은 공통 도구가 설치되어 있습니다. 이 AMI에 무엇이 있고 어떻게 설정되었는지는 함께 제공되는 GitHub 리포지토리에 문서화되어 있습니다. 이러한 지침은 다른 시스템에서 동일한 소프트웨어를 설정하려는 경우 유용할 수 있으며, 자신의 작업을 위해 다른 소프트웨어를 설치할 때 몇 가지 힌트를 얻을 수 있습니다.
구체적으로 다음과 같은 방법을 배웁니다:
a. AWS 관리 콘솔에 로그인하여 탐색합니다.
b. AMI에서 Amazon EC2 인스턴스를 생성합니다.
c. EC2 인스턴스에 SSH로 접속하여 Linux 명령을 실행합니다.
EC2 대시보드 시작
-
AWS 관리 콘솔 검색 창에 EC2를 입력합니다.
-
EC2를 선택하여 EC2 Dashboard를 엽니다.
대시보드의 레이아웃에 익숙해지는 데 몇 분 정도 시간을 할애하세요:
- 왼쪽 창: 저장된 Amazon 머신 이미지(AMI), 스토리지 볼륨 및 ssh 키와 같은 도구 및 기능입니다.
- 가운데: 리소스 목록 및 인스턴스 시작 기능.
- 오른쪽 창: 문서 및 가격 등의 일반 정보.
EC2 인스턴스 시작
이제 EC2 Linux 기반 인스턴스를 시작하겠습니다.
- Launch Instance 을 클릭한 다음 드롭다운 메뉴에서 Launch Instance을 다시 클릭합니다.
- Launch an instance 페이지에서 인스턴스의 원하는 이름을 지정할 수 있습니다.
- Add additional tags 를 클릭하고 "Add Tag"를 클릭합니다. 인스턴스에 대해 제공한 "Name"을 찾을 수 있습니다. 이제 키와 값을 입력합니다. 이 키(더 정확하게는 태그)는 인스턴스가 시작되면 콘솔에 나타납니다. 이를 통해 복잡한 환경에서 실행 중인 머신을 쉽게 추적할 수 있습니다. 이전에 키 쌍에 사용한 것과 유사한 태그를 추가로 생성하여 이 머신에 사용자와 부여 키를 지정하고 동일한 값을 입력합니다. 준비가 되면 Resource types 아래에서 Instances, Volumes, Network interfaces 선택합니다.
- Application and OS images (Amazon Machine Image) 아래에서 검색 상자에 교육용으로 공유된 AMI ID를 입력합니다. AMI는 사진과 다를 수 있으므로 강사의 안내를 참조하세요.
이 교육을 위해
CHENLAB-PUBLIC
을 검색하여 가장 최신 AMI 버전(2022년 9월 기준, IDami-0d36350156cb783e8
인 v2.10b)을 선택하시기 바랍니다.
- Community AMIs에서 결과를 클릭합니다.
검색 결과는 Community AMIs에 표시됩니다.
-
Select 버튼을 클릭하여 AMI를 선택합니다. 최신 버전의 AMI를 선택해야 합니다(위 4단계 참고 참조).
- Instance type에서 드롭다운 화살표를 클릭하고 검색창에 c5.4xlarge을 입력합니다.
- Key pair (login) 아래의 드롭다운 목록에서 이 실습의 시작 부분에서 만든 키 쌍을 선택합니다.
- 다음으로 Network settings에 대해 Edit을 클릭합니다. Subnet 및 Security group 세부 정보를 입력하라는 메시지가 표시됩니다. 보안 그룹은 방화벽 규칙이 됩니다. 앞 챕터에서 진행했다면 만들어진 보안 그룹을 사용할 수도 있습니다.
- Under Configure storage, you have the ability to modify or add storage and disk drives to the instance. For this lab, we will simply accept the storage defaults.
- Review your configuration under Summary and click Launch Instance.
Your instance will now start, which may take a moment. You will be shown the Launch Status page with the message Successfully initiated launch of instance.
- On the lower right of the page click on View all Instances to view the list of EC2 instances. Click on your instance. It will go through an initialization process. Once your instance has launched, you will see your Linux server as well as the Availability Zone the instance is in, and the publicly routable DNS name.
SSH into an EC2 instance
The operating system of your local computer determines the options that you have to connect from your local computer to your Linux instance. Here are directions to connect from Windows Using PuTTY or OpenSSH, From Linux & MacOS-X using ssh client and from Windows Subsystem for Linux (WSL) using ssh client.
Note: The premade CHENLAB-PUBLIC AMI is Ubuntu, so your username will be “ubuntu”
Connecting from Windows using PuTTY
We will now use the private .ppk file of the key pair generated earlier to open a SSH session to the EC2 instance.
-
Start the PuTTy application.
-
Enter in the IP address of the EC2 instance in the Host Name (or IP address) field.
-
To save the session (so we dont have to repeat the configuration everytime) provide a name in the Saved Sessions field.
-
In the left navigation pane under Connections clickon SSH and next click on Auth.
-
In the Private key file for authentication field click Browse and browse in the .ppk file downloaded when creating the key pair earlier.
-
Next in the left navgation pane click on Session (scroll up if you need to) and and further click on Save to save the session.
-
Next click on Open to start the SSH session.
-
PuTTy will now attempt to start an SSH Session.
NOTE: You will get a security Alert The Servers host key is not cached in the registry, click on Yes to continue.
-
You will now be presented with the login as prompt.
-
At the login as prompt type ec2-user if your image is Amazon Linux OS or ubuntu if your image is Ubuntu Linux OS and hit enter.
You would have now logged into the EC2 instance on AWS.
Connecting from Windows using MobaXterm
We will use the private .pem key pair to open an SSH session to the EC2 instance.
-
Start the MobaXterm application.
-
To open a session, click on Session in the top-left corner, then click SSH.
-
Enter in the IP address of the EC2 instance in the Host Name field.
-
To the right, select username and enter your username for the session.
NOTE: Username to be used here is ec2-user if your image is Amazon Linux OS and ubuntu if your image is Ubuntu Linux OS.
-
Below, click on Advanced Settings, and select private key (use your .pem file).
-
Click Ok.
MobaXterm will have logged you in to your EC2 instance.
Connecting from Windows using Windows Subsystem for Linux
We will now use the private .pem file of the key pair generated earlier to open a SSH session to the EC2 instance.
- Copy the private key from Windows to WSL - In a WSL terminal window, copy the .pem file (for the key pair that you specified when you launched the instance) from Windows to WSL. Note the fully-qualified path to the .pem file on WSL to use when connecting to your instance.
cp /mnt/<Windows drive letter>/path/my-key-pair.pem ~/WSL-path/my-key-pair.pem
- In a terminal window, use the ssh command to connect to the instance. You specify the path and file name of the private key (.pem), the user name for your instance, and the public DNS name or IP Address.
NOTE: Username to be used here is ec2-user if your image is Amazon Linux OS and ubuntu if your image is Ubuntu Linux OS.
sudo ssh -i /path/my-key-pair.pem ubuntu@<ip-address>
you will see the following response
The authenticity of host '<ip-address>'
can't be established.
RSA key fingerprint is 1f:51:ae:28:bf:89:e9:d8:1f:25:5d:37:2d:7d:b8:ca:9f:f5:f1:6f.
Are you sure you want to continue connecting (yes/no)?
- Enter Yes
you will now be logged into the EC2 Instance.
Connecting using SSH on Linux & MacOS and OpenSSH on Windows
We will now use the private .pem file of the key pair generated earlier to open a SSH session to the EC2 instance.
- In a terminal window, use the ssh command to connect to the instance. You specify the path and file name of the private key (.pem), the user name for your instance, and the public DNS name or IP Address of your instance.
NOTE: Username to be used here is ubuntu if your image is based on the Ubuntu Linux OS and ec2-user if your image is based on Amazon Linux OS. (See this page which covers many of the common AMI OSs.)
ssh -i /path/my-key-pair.pem ubuntu@<ip-address>
You see a response like the following:
The authenticity of host 'ec2-198-51-100-1.compute-1.amazonaws.com (198-51-100-1)' can't be established.
ECDSA key fingerprint is l4UB/neBad9tvkgJf1QZWxheQmR59WgrgzEimCG6kZY.
Are you sure you want to continue connecting (yes/no)?
- Enter Yes
You will now be logged into the Instance.
NOTE: you might need to change the permissions of the key file by running the chmod command as follows. Edit to match your path and key pair name.
sudo chmod 600 /path/my-key-pair.pem
For detailed directions on these please have a look at the following links:
PuTTY, Windows Susbsystem for Linux, MacOS-X ssh Client, Linux ssh client
예)