โฌ๏ธ Main Note
https://docs.google.com/document/d/1xdJ0VVUDoXyaPY7ESq9DKnIpd8KiC2qjgZYxuffCaUU/edit
4 vCPU, 265GB, 100GB
=> Recommended default settings
High Availability : ๊ณ ๊ฐ์ฉ์ฑ
โค Two computers are operating. If one caught error, turn on the other computer so that the server doesn't stop
Instance ID: my-database02
Password: root
Database version: MySQL 8.0
์์ญ ๊ฐ์ฉ์ฑ: ๋จ์ผ ์์ญ (์ค์ production์์๋ ์ฌ๋ฌ ์์ญ์ผ๋ก ํ๊ธฐ)
โ ์ฌ๋ฌ ์์ญ์ด์ ๋ค๋ฅธ ๋ ์ง์ญ์ผ๋ก ์ค์ ํด์ผํจ (ํ ์ง์ญ์ ์ง์ง๋๋ฉด ๋ค๋ฅธ ์ง์ญ์ปดํจํฐ๋ฅผ ๋๋ ค์ผํจ)
Machine method: Standard 1 vCPU or 1 shared core
โ (ํ๋์ ์ปดํจํฐ๋ก ๋ฉ๋ชจ๋ฆฌ๋ฅผ ์กฐ๊ธ์ฉ ์ฌ๋ฌ๋ช
์ด ๋๋ ๊ฐ๋ ๊ฒ)
์ ์ฅ์ฉ๋ : 20GB
์ ์ฅ์ฉ๋ ์๋ ์ฆ๊ฐ ์ฌ์ฉ ์ค์ (๋์ค์ ์ค์ผ ์ ์์) ๋์คํฌ๋ฅผ ๋๋ฆฐ๋ค๋๊ฑด ํ๋์ฉ ๋ ์ฐ๊ฒฐ์ํจ๋ค๋๊ฑฐ์
โ (์์๊ฒ๋ค์ ๋๋ ค๋๊ฐ๋ ํ์)
Let's suppose that our service became a microservice.
โค Every single APIs are set to single services, and what kind of error occurs, the other APIs work normally and what we only have to do is fix that problometic API function and re-deploy.
Advantage
When user accesses to the server and requests an API, the computer turns on and inside that computer, the function is executed.
โค Conservation of money (GCP ๋น์ฉ ์ ์ฝ)
โค The computer isn't on 24/7, but it's only on when the user requests for an API. After the API is used, computer is automatically shut down.
Disadvantage
There exists a delay time for the computer to turn on and execute the function.
โค So when the user requests for the first time after the computer is off, it takes a long time for that person.
Cold start : The computer starts with off state.
For 4 to 5 seconds, the computer is live after it starts operating.
When the user sends during that time, that's warm start to that person.
โค Cold Start to Wram Start
: Request once a 4 sec
-------- New database should be made --------
Database access address: IP Address(from SQL)
1. SQL โ database โ create database โ name: myserver02
2. SQL Connection ๋ค์ด๊ฐ์ 0.0.0.0/0 network ์ถ๊ฐํ๊ธฐ
3. Go to DBeaver
์๋ก MySQL ์ฐ๊ฒฐํด์ server์ฃผ์๋ฅผ ์
๋ ฅํด์ฃผ๋๋ฐ ์ด๋ ์ฃผ์๋
SQL Overview โ connection test โ IP Address
โ If private IP Address, ์ธ๋ถ์ ์ ์ ๋ถ๊ฐ๋ฅ (๋ด๋ถ๋ง ์ ์ ๊ฐ๋ฅ)
โ If Public IP Address, ์ธ๋ถ์ ์ ์ ๊ฐ๋ฅ
// docker.compose.prod.yaml --> prod doesn't need my-database docker anymore.
// โค app.module --> host and database should be changed
If the IP is set as public, it has high possibility of being hacked.
โค So the database should be in private mode.
SQL Connection โ Private IP , Network: default(VPC)
VPC : Virtual Private Cloud (๋ด๋ถ ์์ดํผ ์ฌ์ฉ)
โค VPC ์์ ์ฌ๋ฌ ์ปดํจํฐ๋ค์ด ์๋๋ฐ ๊ทธ ์ปดํจํฐ๋ค์ด ์ฌ์ฉํ๋ IP๋ ๋ด๋ถIP์
โค ์ด ์ปดํจํฐ๋ค์ ๊ฐ๊ฐ์ ๋ฐฉํ๋ฒฝ์ ๊ฐ์ง๊ณ ์์
๊ทผ๋ฐ ๋ด๋ถ์์ ๋ด๋ถ๋ก ์ ์ํ๋๊ฑด ์ผ๋ฐ์ ์ผ๋ก ํ์ด์ ธ์์ (๊ทธ๋์ ๋ชจ๋๊ฐ ์ฝ๊ฒ ํต์ ๊ฐ๋ฅ)
์ธ๋ถ์์ ๋ค์ด์ค๋ ์ ์์ ๋ง๊ณ ์๋๊ฑฐ์ (์์ ์ ์ํด)
๊ทธ๋์ ๋์ด์ ์ธ๋ถ์์ ์ด ๋ด๋ถ ์์ดํผ๋ก ์ ์์ ํ ์ ์๊ฒ ๋จ
๊ธฐ๋ณธ์ ์ผ๋ก ๋ง๋ค์ด์ง๋ VPC : default VPC (์ด ๊ฐ์ default VPC๋ฅผ ์ค์ ์ด ๋์ด์๋ ์ปดํจํฐ์ ํ์์๋ ์๋ก์๋ก ๋ฐฉํ๋ฒฝ ์์ด ์ ๊ทผ์ด ๊ฐ๋ฅํจ) ์ด๋ ์ฌ์ฉ๋๋ IP๊ฐ ๋ด๋ถ ์์ดํผ
๋ฐ์์ ๋ค์ด์ฌ๋ ์ฐ๋ IP๊ฐ ์ธ๋ถ ์์ดํผ (๊ณต๊ฐIP)
๊ทธ๋์ ์ด์ VPC์์ ์๋ ์ปดํจํฐ๋ฐ์ DB์ ์ ์์ ๋ชปํจ (๊ฐ์ VPC ์ ๋ฐฑ์๋๊ฐ ์ ์ ํ ์ ์๋ค๋๊ฒ)
๊ทผ๋ฐ ์ด์ ์ฐ๋ฆฌ๊ฐ DBeaver๋ก ์ ์์ ๋ชปํจ (VPCํด์ ๋ฑ๋กํ ๊ฐ์ ๋ฐฑ์๋ ์ปดํจํฐ๋ DB์ ์ ์ ๊ฐ๋ฅ)
Compute Engine - VM Instance ๋ค์ด๊ฐ์ Network ๋ณด๋ฉด default VPC๋ก ๋์ด์์
(default๋ผ๋ ์ด๋ฆ์ VPC์)
๊ทธ๋์ ์ ๋ฆฌ๋ฅผ ํ์๋ฉด ์ฐ๋ฆฌ backend๋ default VPC, ๊ทธ๋ฆฌ๊ณ SQL๋ก ๋ง๋ database๋ ๋ค๋ฅธ VPC์ ์ํด ์์
์๋ก VPC๊ฐ ๋ค๋ฅด๋ฉด ๋ด๋ถ์์ดํผ๋ก ์ฐ๊ฒฐ์ด ์๋จ! ๊ทธ๋์ ๋๊ฐ๋ฅผ ํ๋๋ก ํฉ์ณ์ผํจ
โค VPC-peering
Default VPC์์ผ๋ก ์ด database๊ฐ ๋ค์ด์ค๊ฒ ๋จ
๊ทธ๋์ backend์ database๊ฐ ์ฐ๊ฒฐ๋จ (์ด๊ฑด ์๋์ผ๋ก ํด๋ฆญ ํ๋ฐฉ์ ์งํ๋๋ ๊ณผ์ ์)
โค so now on, able to connect with inner IP. (๊ทธ๋ฆฌ๊ณ ๋ค๋ฅธ ํฌํธ๋ ๋งํ์๊ณ 3000๋ฒ ํฌํธ๋ง ์ ์ ๊ฐ๋ฅ)
https: secured server
To secure the server, there should be an authentication about the server.
And that authentication is set inside load balancer.
Main purpose of load balancer is literally load balancing the request that is sent to itself. (์์ฒญ ๋ถ๋ฐฐ)
โค There exists diverse kinds of algorithms for load balancing: round-robin, least connection, etc...
Round-Robin : 1 goes to A, 2 goes to B, 3 goes to C, 4 goes to A, 5 goes to B, 6 goes to C, 7 goes to A...
Least Connection : Users are sent to the least-traffic server.
According to load balancer,
โค Frontend : Incoming request
โค Backend : outgoing respond
reverse-proxy = load balancer receiving the request instead
Http, https can be manipulated in the middle of the process
So instance group should be created on the base of instance template.
Health checker is attached to load balancer.
โค Health checker literally checks the status of computers inside the instance group. So if there is an unhealth computer or a dead computer, the health checker tells the load balancer not to load balance to that computer.
How health checking works
When the health checker sends requests to the computers, those computers who responded are normal.
If the request is sent multiple times but there aren't any responses, then that computer is considered dead.