[root@localhost ~]# git clone https://github.com/hali-linux/azure_set.git
[root@localhost azure_set]# terraform output -raw tls_private_key > azure-key.pem
[root@localhost azure_set]# terraform output public_ip_address
"20.214.236.120"
[root@localhost azure_set]# ssh -i azure-key.pem azureuser@20.214.236.120
[root@localhost ~]# mkdir gcp_cli && cd $_
[root@localhost gcp_cli]# tee -a /etc/yum.repos.d/google-cloud-sdk.repo << EOM
[google-cloud-cli]
name=Google Cloud CLI
baseurl=https://packages.cloud.google.com/yum/repos/cloud-sdk-el8-x86_64
enabled=1
gpgcheck=1
repo_gpgcheck=0
gpgkey=https://packages.cloud.google.com/yum/doc/yum-key.gpg
https://packages.cloud.google.com/yum/doc/rpm-package-key.gpg
EOM
[root@localhost gcp_cli]# yum install -y google-cloud-cli
[root@localhost gcp_cli]# gcloud --version
[root@localhost gcp_cli]# gcloud init --console-only
βοΈμλ λ§ν¬ μ§μ
Do you want to configure a default Compute Region and Zone? (Y/n)? y
Which Google Compute Engine zone would you like to use as project default?
If you do not specify a zone via a command line flag while working with Compute
Engine resources, the default is assumed.
...
[47] asia-northeast2-a
[48] asia-northeast2-b
[49] asia-northeast2-c
[50] asia-northeast3-a
Did not print [54] options.
Too many options [104]. Enter "list" at prompt to print choices fully.
Please enter numeric choice or text value (must exactly match list item): 50
-> μλ£
# gcloud compute networks create new-vpc --subnet-mode=custom
# gcloud compute networks subnets create new-subnet --network=new-vpc --range=192.168.0.0/16 --region=asia-northeast3
# gcloud compute networks subnets list
# gcloud compute firewall-rules list
# gcloud compute firewall-rules create new-vpc-allow-ssh --allow=tcp:22 --description="Allow incoming traffic on TCP port 22" --direction=INGRESS --network=new-vpc --source-ranges 0.0.0.0/0
# gcloud compute firewall-rules create new-vpc-allow-http --allow=tcp:80 --description="Allow incoming traffic on TCP port 80" --direction=INGRESS --network=new-vpc --source-ranges 0.0.0.0/0
# gcloud compute images list | grep centos-cloud
# gcloud compute images describe centos-7-v20220621 \
--project=centos-cloud
# gcloud compute machine-types list --filter="zone:( asia-northeast3-a )"
# vi httpd-gcp.txt
#!/bin/bash
yum install -y httpd
systemctl enable --now httpd
echo "Hello GCP CLI" > /var/www/html/index.html
# gcloud compute instances create web01 \
--image=centos-7-v20220621 \
--image-project=centos-cloud \
--machine-type=e2-micro \
--network=new-vpc \
--subnet=new-subnet \
--tags http-server,https-server \
--zone=asia-northeast3-a \
--metadata-from-file=startup-script=httpd-gcp.txt
βοΈGCP λΈλΌμ°μ μμ λ‘κ·ΈμΈ - νλ‘μ νΈ ID νμΈ
!-- μ¬μ©μ μ΄λ¦ μμ(lovemj)λ‘ λ΄κ° λ£κΈ° --!
[root@localhost gcp_cli]# ssh-keygen -t rsa -f /root/.ssh/lovemj -C lovemj -b 2048
# vi /root/.ssh/lovemj.pub
lovemj:ssh-rsa ~~ blahblah
# gcloud compute os-login ssh-keys add \
--key-file=/root/.ssh/lovemj.pub \
--project=gcp-lovemj2022 \
--ttl=365d
# gcloud compute instances add-metadata web01 --metadata-from-file ssh-keys=/root/.ssh/lovemj.pub
# gcloud compute instances describe web01
# curl 34.64.48.211
# ssh -i /root/.ssh/lovemj lovemj@34.64.48.211
# gcloud compute instances delete web01
# gcloud compute firewall-rules list
# gcloud compute firewall-rules delete new-vpc-allow-http
# gcloud compute firewall-rules delete new-vpc-allow-ssh
# gcloud compute networks subnets delete new-subnet
# gcloud compute networks delete new-vpc
# git clone https://github.com/hali-linux/gcp_set.git
# vi provider.tf
provider "google" {
credentials = file("credentials.json")
project = "gcp-lovemj2022"
region = "asia-northeast3"
zone = "asia-northeast3-a"
}
# vi main.tf
resource "google_compute_network" "custom-test" {
name = "new-vpc"
auto_create_subnetworks = false
}
resource "google_compute_subnetwork" "network-with-private-ip-ranges" {
name = "new-subnet"
ip_cidr_range = "192.168.0.0/16"
region = "asia-northeast3"
network = google_compute_network.custom-test.id
}
resource "google_compute_instance" "default" {
name = "vm-from-terraform"
machine_type = "e2-micro"
zone = "asia-northeast3-a"
boot_disk {
initialize_params {
image = "debian-cloud/debian-9"
}
}
network_interface {
network = "new-vpc"
subnetwork = "new-subnet"
access_config {
// Include this section to give the VM an external ip address
}
}
metadata_startup_script = file("/root/gcp_set/script.txt")
// Apply the firewall rule to allow external IPs to access this instance
tags = ["http-server","ssh-server"]
}
resource "google_compute_firewall" "http-server" {
name = "default-allow-http-terraform"
network = "new-vpc"
allow {
protocol = "tcp"
ports = ["80"]
}
// Allow traffic from everywhere to instances with an http-server tag
source_ranges = ["0.0.0.0/0"]
target_tags = ["http-server"]
}
resource "google_compute_firewall" "ssh-server" {
name = "default-allow-ssh-terraform"
network = "new-vpc"
allow {
protocol = "tcp"
ports = ["22"]
}
// Allow traffic from everywhere to instances with an http-server tag
source_ranges = ["0.0.0.0/0"]
target_tags = ["ssh-server"]
}
# vi output.tf
output "ip" {
value = "${google_compute_instance.default.network_interface.0.access_config.0.nat_ip}"
}
JSON - λ§λ€κΈ° - νμΌμ΄λ¦ : credentials.JSON
# terraform init
# terraform plan
# terraform apply
# terraform output ip
# gcloud compute instances add-metadata vm-from-terraform --metadata-from-file ssh-keys=/root/.ssh/lovemj.pub
# ssh -i /root/.ssh/lovemj lovemj@34.64.48.211
# terraform destroy
SSH μ μμ΄ κ°λ₯ν μνμ¬μΌν¨.(μ°λ¦¬κ° μ격μ μ μν΄μ μ€μΉνλκ±°λ κ°μ μ리)
centos-node01
centos-node02
ununtu-node01
ununtu-node02
(centosλ μ΄λ―Έ μμ)
βοΈλ§λ€κΈ° ν΄λ¦
βοΈμλ¨ λ©λ΄μμ μ€μ ν΄λ¦ - λμ€νλ μ΄ : λΉλμ€λ©λͺ¨λ¦¬ : 9MB(μ΄λ‘μμμ μ΅λν μκ²) - μ μ₯μ : λΉμ΄μμμ ubuntu18.04.4 μ
ν
- μ€λμ€ : μ¬μ©νκΈ° ν΄μ - λ€νΈμν¬ : μ΄λν°μ λΈλ¦Ώμ§ - USB : 컨νΈλ‘€λ¬ μ¬μ©μν¨
βοΈ μΈμ΄ english λ‘μΌμ΄μ asia korea, ν€λ³΄λ korea 101/104 - μ¬μ΄μ λ λμ€λλ° no - host name: ubuntu κ·Έλλ‘ - μ¬μ©μκ³μ μνλ ID ; mj - account ID ;mj - password λλ²μ λ ₯ - timezone νμΈ ν yes or no - partitioning method : use entire disk - λμ€ν¬ νμΈ ν yes - http proxy? blank ( κ·Έλ₯ μν° ) - no automaitc update - openSSH server μ€νμ΄μ€ μν°- boot record: yes - continue
βοΈ μλ²μ§μ ν΄μ ipνμΈ ν mobaxtermμΌλ‘ μ§μ
mj@ubuntu:~$ sudo vi /etc/ssh/sshd_config
[sudo] password for mj:
#LoginGraceTime 2m
PermitRootLogin yes
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
mj@ubuntu:~$ sudo su -
root@ubuntu:~# passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
mj@ubuntu:~$ sudo systemctl restart sshd
πβοΈβοΈπ’βοΈπ
[root@localhost gcp_set]# ssh -i /root/.ssh/lovemj lovemj@34.64.48.211
key_load_public: invalid format
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:Jrzlnn4WHpyzdHsEtoi740IoZWtJe2tbygx0zRNh3JM.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /root/.ssh/known_hosts:4
ECDSA host key for 34.64.48.211 has changed and you have requested strict checking.
Host key verification failed.
-> know_hostsνμΌμ΄ κΌ¬μ¬μ λ¬Έμ λ°μ μ§μμ ν΄κ²°νμ.
->μ¬μ§μ
ν΄μ yesνλ©΄ λ¬Έμ μμ.
[root@localhost gcp_set]# rm /root/.ssh/known_hosts