리전이 해안가에 몰려있는 이유: 해저 광 케이블 때문
#!/bin/bash
yum update -y
amazon-linux-extras install -y lamp-mariadb10.2-php7.2 php7.2
yum install -y httpd mariadb-server
systemctl start httpd
systemctl enable httpd
systemctl start mariadb.service
systemctl enable mariadb.service
usermod -a -G apache ec2-user
chown -R ec2-user:apache /var/www
chmod 2775 /var/www
find /var/www -type d -exec chmod 2775 {} \;
find /var/www -type f -exec chmod 0664 {} \;
echo "<?php phpinfo(); ?>" > /var/www/html/phpinfo.php
systemctl status httpd
를 입력했을 때 actvie (running)
을 확인할 수 있다.[ec2-user@ip-172-31-1-108 ~]$ vi index.php
[ec2-user@ip-172-31-1-108 ~]$ sudo cp index.php /var/www/html/index.php
<html>
<head>
<title>AWS EC2 http Running Sample App</title>
<style>body {margin-top: 40px; background-color: #333;} </style>
<meta http-equiv="refresh" content="3" >
</head>
<body>
<div style=color:white;text-align:center>
<h1> AWS EC2 http Application. </h1>
<h2> Great Works! </h2>
<p>Application is now good running on a AWS EC2 http.</p>
</div>
</body>
</html>
👻 EC2의 MySQL을 워크벤치로 연결하자
[ec2-user@ip-172-31-1-108 ~]$ sudo /usr/bin/mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
Enter current password for root (enter for none): [Enter]
OK, successfully used password, moving on...
Set root password? [Y/n] Y
New password: [1234]
Re-enter new password: [1234]
Password updated successfully!
Remove anonymous users? [Y/n] Y
... Success!
Disallow root login remotely? [Y/n] n
... skipping.
Remove test database and access to it? [Y/n] Y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!
Reload privilege tables now? [Y/n] Y
... Success!
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB! 🥳 설정 끝 !
[ec2-user@ip-172-31-1-108 ~]$ mysql -u root -p
Enter password: [1234]
Welcome to the MariaDB monitor. Commands end with ; or \g.
🐣 이제 워크벤치 실행가능 !
아래와 같이 설정합니다.
create database prod;
use prod;
create table product (prod_id int, prod_name varchar(30));
insert into product values (100, 'AWS');
insert into product values (200, 'GCP');
select * from product;
<?php
$mysql_hostname = 'ip-172-31-1-108.ap-northeast-2.compute.internal';
$mysql_username = 'root';
$mysql_password = '1234';
$mysql_database = 'prod';
$connect = mysqli_connect($mysql_hostname, $mysql_username, $mysql_password, $mysql_database);
if(!$connect){
echo '[connection fail] : '.mysql_error().'';
die('MySQL 접속 실패.');
} else {
echo "[yji Web:첫 번째 EC2 에서 MySQL 서버 접근 성공!]\n";
}
$sql = "SELECT * FROM product";
$result = mysqli_query($connect, $sql);
echo "Table query result : ";
var_dump($result->num_rows);
$result2 = mysqli_query($connect,"SELECT * FROM product");
echo "<table border='1'> <tr> <th>prod_id</th> <th>prod_name</th>";
$n = 1;
while($row = mysqli_fetch_array($result2)){
echo "<tr>";
echo "<td>" . $row['prod_id'] . "</td>";
echo "<td>" . $row['prod_name'] . "</td>";
echo "</tr>";
$n++;
}
echo "</table>";
mysqli_close($conn);
?>
create table books (
ISBN int(13),
Title varchar(100),
Author varchar(100),
Format varchar(100));
insert into books values (9182932465265, 'Cloud Computing Concepts', 'Wilson, Joe', 'Paperback');
insert into books values (3142536475869, 'The Database Guru', 'Gomez, Maria', 'eBook');
create table departments (
department_id int(4) PRIMARY KEY,
department_name varchar(30),
manager_id int(6),
location_id int(4));
create table employees (
employee_id int(6) PRIMARY KEY,
first_name varchar(20),
last_name varchar(25),
email varchar(25),
phone varchar(20),
hire_date date,
job_id varchar(10),
salary int(8),
commission_pct int(2),
manager_id int(6),
department_id int(4),
CONSTRAINT dept_fk FOREIGN KEY (department_id) REFERENCES departments (department_id)
);
🐣 열쇠 : PK
하늘색 마름모 : UK
주황색 마름모 : FK
1) 임시 SSH key 발급(from root) -> 접근
2) ppk를 이용한 SSH 접근 -> 내장된 key-pair 접근 (putty~)
SSM을 이용한 사용자 계정 생성 !
관리자가 IAM -> AuthN + AuthZ 제공
Audit-log
여기까지 했으면 역할 생성 버튼 클릭
여기까지하고 버킷생성
여기서 CloudWatch랑 S3를 enable해주어야한다.
여기까지하고 생성
성공 !
이 로그가 bucket에 올라올거다(시간이 좀 걸림) -> 이 로그를 확인하는 것이 목적 !
S3 버킷에 올라온 로그를 다운받기 위해 퍼블릭 액세스 기능을 부여해야한다.
버킷 정책을 다음과 같이 수정
{
"Version": "2012-10-17",
"Id": "Policy1655711680123",
"Statement": [
{
"Sid": "Stmt1655711673132",
"Effect": "Allow",
"Principal": "*",
"Action": [
"s3:DeleteObject",
"s3:GetObject",
"s3:PutObject"
],
"Resource": "arn:aws:s3:::[버킷명]/*"
}
]
}
세션에 연결한 뒤에 실행했던 명령어들이 모두 로그로 기록되어있다.
Script started on 2022-10-14 07:37:15+0000
cd
source ./.bash_profile
user=$(whoami)
echo "Welcome $user"'!'
[?1034hsh-4.2$ cd
sh-4.2$ source ./.bash_profile
]0;@ip-172-31-1-108:~[ec2-user@ip-172-31-1-108 ~]$ user=$(whoami)
]0;@ip-172-31-1-108:~[ec2-user@ip-172-31-1-108 ~]$ echo "Welcome $user"'!'
Welcome ec2-user!
]0;@ip-172-31-1-108:~[ec2-user@ip-172-31-1-108 ~]$
[K[ec2-user@ip-172-31-1-108 ~]$
]0;@ip-172-31-1-108:~[ec2-user@ip-172-31-1-108 ~]$ dkss[K[K[K[Ke[Ke[Kecho hello
hello
]0;@ip-172-31-1-108:~[ec2-user@ip-172-31-1-108 ~]$
[K[ec2-user@ip-172-31-1-108 ~]$
[K[ec2-user@ip-172-31-1-108 ~]$ echo hello[K[K[K[K[Kㅓㅑ[K[Kd[Kmr my yesterday~
mr my yesterday~
]0;@ip-172-31-1-108:~[ec2-user@ip-172-31-1-108 ~]$
[K[ec2-user@ip-172-31-1-108 ~]$
[K[ec2-user@ip-172-31-1-108 ~]$
]0;@ip-172-31-1-108:~[ec2-user@ip-172-31-1-108 ~]$
]0;@ip-172-31-1-108:~[ec2-user@ip-172-31-1-108 ~]$
]0;@ip-172-31-1-108:~[ec2-user@ip-172-31-1-108 ~]$
]0;@ip-172-31-1-108:~[ec2-user@ip-172-31-1-108 ~]$
Script done on 2022-10-14 07:37:15+0000
🥳 여기까지 하면 끝
s3 bucket 로그 삭제
s3 bucket 버킷 삭제
CloudWatch에서 로그 그룹 삭제
IAM 역할 kakaoRoleforSSM 삭제
ec2 종료
⭐ 📘 📗 💭 🤔 📕 📔 🐳 ✍ 🥳 ⭐ 🐣 👻
on-demand spot saving plans 예약 인스턴스의 차이점