brunch

You can make anything
by writing

C.S.Lewis

by Master Seo Mar 03. 2023

4. 구글 클라우드 - 클라우드 스토리지,SQL

<1> 클라우드 스토리지와 클라우드 SQL을 알아보자.

<2> cloud sql 만들기



<1> 클라우드 스토리지와 클라우드 SQL을 알아보자.

1

구글은 앞에 클라우드를 붙인다.

예) 클라우드 스토리지,  , 클라우드 SQL 


2

cloud shell 로  cloud storage 만들기

구글 cloud shell을 사용하면 $DEVSHELL_PROJECT_ID는 자동으로 기억한다.


export LOCATION=ASIA

gsutil mb -l $LOCATION gs://$DEVSHELL_PROJECT_ID


3

샘플 이미지 복사

gsutil cp gs://cloud-training/gcpfci/my-excellent-blog.png my-excellent-blog.png

gsutil cp my-excellent-blog.png gs://$DEVSHELL_PROJECT_ID/my-excellent-blog.png


4

모든 사용자가 권한 가지기

gsutil acl ch -u allUsers:R gs://$DEVSHELL_PROJECT_ID/my-excellent-blog.png




<2> cloud sql 만들기



0

sql 접속할 vm 하나 만들기




VM 생성시 APACHE 와 PHP 자동 설치

스크립트에 적용






1

sql 선택

인스턴스 ID에는 blog-db

암호 입력 goxxxx




2

개발로 변경

생성


vm

공인ip 확인

34.106.22.169


3

vm 서버에서 SQL 서버 접속이라  허용 VM서버 IP 입력 ?

sql

34.173.24.175/32





4

허용 사용자 추가 ?

Users

사용자 계정 추가

blogdbuser

암호 goxxxxxx


5

컨트롤 누르거 메뉴를 누르면  별도 탭으로 생성된다.  새 탭이라 작업하기 편하다.

vm

ssh  클릭


6

db접속 테스트하기


cd /var/www/html


vi  index.php

<html>

<head><title>Welcome to my excellent blog</title></head>

<body>

<h1>Welcome to my excellent blog</h1>

<?php

 $dbserver = "CLOUDSQLIP";

$dbuser = "blogdbuser";

$dbpassword = "DBPASSWORD";

// In a production blog, we would not store the MySQL

// password in the document root. Instead, we would store it in a

// configuration file elsewhere on the web server VM instance.

$conn = new mysqli($dbserver, $dbuser, $dbpassword);

if (mysqli_connect_error()) {

        echo ("Dtabase connection failed: " . mysqli_connect_error());

} else {

        echo ("Database connection succeeded.");

}

?>

</body></html>


sudo service apache2 restart


34.106.22.169/index.php


접속 안됨.




7

암호 입력하여 다시 접속 하기


vi index.php


CLOUDSQLIP   sql

DBPASSWORD


sudo service apache2 restart


성공

Database connection succeeded.



8

스토리지 이미지 불러오는 실습도 해보기


cd /var/www/html


vi index.php

<img src='https://storage.googleapis.com/qwiklabs-gcp-01-2c30bd92b58e/my-excellent-blog.png'>


9

sudo service apache2 restart



10

접속 테스트




https://brunch.co.kr/@topasvga/3094


감사합니다.

매거진의 이전글 3. 구글 클라우드 - 방화벽 규칙과 VPC 네트워크

작품 선택

키워드 선택 0 / 3 0

댓글여부

afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari