Week8 - Selesfia/ComputerNetwork GitHub Wiki
-
Perplexity AI -> If you want ask a question and you want to get the answer directly. URL
-
XAnswer -> URL
- Go to GCP console and go to SQL
- Create new sql instance
- Choose SQL edition "Enterprise plus" -> Edition preset "Development" -> Choose database version "8.0"
- Give a name "mydb" -> Set password "12345678"
- Choose region "asia-east1 (Taiwan)" -> zonal availability "Single zone"
- Click create
- Edit your SQL database -> Connection
- Disable the public IP and enable the private IP
- Save the changes that you made
- Connect to cloud shell
- Go to Cloud SQL Admin API and enable the API
- Connect to cloud shell ->
mysql -h “10.0.80.3” -u root -p
, change the ip to your db private ip -> enter password
- Connect to your db using the above step
- Run the following code step by step
show databases;
create database testdb;
use testdb;
create table addrbook(name varchar(50) not null, phone char(10));
insert into addrbook(name, phone) values ("jessline", "(tel:0937711339)");
insert into addrbook(name, phone) values ("celine", "(tel:0971660435)");
select name,phone from addrbook;
- Connect to cloud shell
- Run the following code
$ sudo apt install apache2 php libapache2-mod-php php-mysql
$ sudo systemctl restart apache2
$ cd /var/www/html
$ sudo vim testdb.php
- Paste the following text (Change to your db IP addr, esc :wq to exit and save vim)
<?php
$servername="10.0.80.3";
$username="root";
$password="12345678";
$dbname="testdb";
$conn = new mysqli($servername, $username, $password, $dbname);
if($conn->connect_error){
die("connection failed: " . $conn->connect_error);
}
else{
echo "connect OK!" . "<br>";
}
$sql="select name,phone from addrbook";
$result=$conn->query($sql);
if($result->num_rows>0){,
while($row=$result->fetch_assoc()){
echo "name: " . $row["name"] . "\tphone: " . $row["phone"] . "<br>";
}
} else {
echo "0 record";
}
?>
- Open the web using external IP Addr and add "/testdb.php"
- Create 2 VM instance "ww1", "ww2". When creating both vm paste the below text at "Automation"
#! /bin/bash
apt update
apt -y install apache2
cat <<EOF > /var/www/html/index.html
<html><body><p>Linux startup script added directly. $(hostname -f) </p></body></html>
- Go to Instance Group and create new
- Go to load balancing and create new
- Type of load balancer "Application Load Balancer (HTTP/HTTPS)" -> Public facing or internal "Public facing (external)" -> Global or single region deployment "Best for regional workloads" -> Configure
- Give name "mylb" -> choose region "asia-east1 (Taiwan)" -> Network "default"
- Frontend configuration -> give a name "myfrontend" -> protocol "HTTP" -> port "80" -> ip addr "ephemeral" -> click done
- Backend configuration -> create backend service -> give a name "mybackend" -> Instance group "www-group" -> port "80" -> create new health check "myhealthcheck" -> click create
- Check your load balancer ip addr and try to open in a 2 different web
PS : Remember to delete the resources that you created if you don't use it anymore.
29/10/2024