<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
    <channel>
        <title>joo_oonu.log</title>
        <link>https://velog.io/</link>
        <description>Cloud, Infra, DevOps에 관심많은 학부생</description>
        <lastBuildDate>Tue, 23 Apr 2024 08:24:41 GMT</lastBuildDate>
        <docs>https://validator.w3.org/feed/docs/rss2.html</docs>
        <generator>https://github.com/jpmonette/feed</generator>
        <image>
            <title>joo_oonu.log</title>
            <url>https://velog.velcdn.com/images/joo_oonu/profile/55d0c1bd-93c1-47d4-8f9b-4d8009967bfd/image.jpg</url>
            <link>https://velog.io/</link>
        </image>
        <copyright>Copyright (C) 2019. joo_oonu.log. All rights reserved.</copyright>
        <atom:link href="https://v2.velog.io/rss/joo_oonu" rel="self" type="application/rss+xml"/>
        <item>
            <title><![CDATA[[Terraform] Block 사용법 - 1 (테라폼 블록, 리소스 블록)]]></title>
            <link>https://velog.io/@joo_oonu/Terraform-%EB%B8%94%EB%A1%9D-%EC%82%AC%EC%9A%A9%EB%B2%95-1%ED%85%8C%EB%9D%BC%ED%8F%BC-%EB%B8%94%EB%A1%9D-%EB%A6%AC%EC%86%8C%EC%8A%A4-%EB%B8%94%EB%A1%9D</link>
            <guid>https://velog.io/@joo_oonu/Terraform-%EB%B8%94%EB%A1%9D-%EC%82%AC%EC%9A%A9%EB%B2%95-1%ED%85%8C%EB%9D%BC%ED%8F%BC-%EB%B8%94%EB%A1%9D-%EB%A6%AC%EC%86%8C%EC%8A%A4-%EB%B8%94%EB%A1%9D</guid>
            <pubDate>Tue, 23 Apr 2024 08:24:41 GMT</pubDate>
            <description><![CDATA[<p>Terraform을 활용한 본격적인 인프라를 구성에 앞서, 
TF 파일 작성을 위한 문법 및 구성 요소, 사용법에 대해 정리해보려 한다.<br/></p>
<h3 id="블록의-종류">블록의 종류</h3>
<p><img src="https://velog.velcdn.com/images/joo_oonu/post/0ff2f117-811f-41ab-9a90-00a53c883aa8/image.png" alt=""></p>
<p>사진과 같이 다양한 블록들이 있다. 그중 가장 많이 사용하게 되는 것들을 위주로 설명해보려한다.
<br/></p>
<h2 id="1-테라폼-블록">1. 테라폼 블록</h2>
<pre><code>terraform {
  required_version = &quot;&gt;= 1.8.0&quot;  # terraform 버전

  required_providers {           # provider 버전

    aws = {
      source  = &quot;hashicorp/aws&quot;
      version = &quot;~&gt; 5.45.0&quot;
    }

    azurerm = {
      source  = &quot;hashicorp/azurerm&quot;
      version = &quot;&gt;= 2.99.0&quot;
    }
  }

}</code></pre><ul>
<li>테라폼의 구성 명시 (테라폼 버전, 프로바이더 버전...)</li>
<li>terraform, provider의 버전은 자동으로 설정됨</li>
<li><strong>버전 및 필요조건</strong>을 명시적으로 선언하는 경우</li>
<li><blockquote>
<p><em>타인과 작업시 오류 최소화를 위해</em> </p>
</blockquote>
</li>
</ul>
<br/>

<h3 id="1-1-테라폼-버전">1-1. 테라폼 버전</h3>
<ul>
<li>테라폼 블록의 <strong>required_version</strong>에 정의</li>
</ul>
<blockquote>
</blockquote>
<p> <strong>&quot;&gt;= 1.0.0&quot; *<em>: 테라폼 v1.0.0 이상 모든 버전 허용
 *</em>&quot;~&gt; 1.0.0&quot;</strong> : 테라폼 v1.0.0 포함 ~ v1.0.x 버전 허용, v1.x.x 비허용
 <strong>&quot;&gt;= 1.0 &lt; 2.0.0&quot;</strong> : 테라폼 v1.0.0 이상 v2.0.0미만 버전 허용</p>
<br/>

<h3 id="1-2-프로바이더-버전">1-2. 프로바이더 버전</h3>
<ul>
<li>테라폼 블록의 <strong>required_providers</strong> 에 정의</li>
<li>전엔 provider 블록에 함께 버전 명시 하였음</li>
<li>프로바이더 버전은 <a href="https://registry.terraform.io/browse/providers">https://registry.terraform.io/browse/providers</a> 에서 확인 가능</li>
</ul>
<p>ex)</p>
<pre><code>required_providers {           # provider 버전

    aws = {
      source  = &quot;hashicorp/aws&quot;
      version = &quot;~&gt; 5.45.0&quot;
    }

    azurerm = {
      source  = &quot;hashicorp/azurerm&quot;
      version = &quot;&gt;= 2.99.0&quot;
    }
  }</code></pre><br/>

<h3 id="1-3-백엔드-블록">1-3. 백엔드 블록</h3>
<ul>
<li>테라폼 실행시 저장되는 <strong>State 파일(상태 파일)</strong> 의 저장 위치 선언</li>
<li>주의 : <strong>하나의 백엔드만 허용!!</strong></li>
<li>기본 백엔드 : local -&gt; 협업 시 외부 벡엔드 저장소(공유 스토리지) 필요</li>
</ul>
<blockquote>
<h3 id="state-상태-파일"><strong>State (상태 파일)</strong></h3>
</blockquote>
<ul>
<li>테라폼은 <strong>State의 데이터</strong>를 사용해 코드로 관리된 리소스를 탐색 및 추적</li>
<li>민감한 정보 포함(PW, 인증서 정보..) -&gt; State 접근 제어 필요!</li>
<li>State 관리시, lock.info 파일 생성으로 잠금 처리 -&gt; 동시 사용 제한</li>
<li>벡엔드 전환 = State 관리 저장소 선택</li>
<li>벡엔드 변경시 terraform init 으로 State 위치 재설정 필요 </li>
</ul>
<p>ex)</p>
<pre><code>backend &quot;local&quot; {
  path = &quot;state/terraform.tfstate&quot;
}</code></pre><p><br/><br/></p>
<h2 id="2-리소스-블록">2. 리소스 블록</h2>
<pre><code>resource &quot;&lt;프로바이더이름_리소스 유형&gt;&quot; &quot;&lt;이름&gt;&quot; {
  &lt;인수&gt; = &lt;값&gt;
}

resource &quot;local_file&quot; &quot;abc&quot; {      # local 파일
  content = &quot;123!&quot;
  filename = &quot;${path.module}/abc.txt&quot;
}

resource &quot;aws_instance&quot; &quot;web&quot; {     # aws ec2 인스턴스
  ami = &quot;ami-a1b2c3d4&quot;
  instance_type = &quot;t2.micro&quot;
}</code></pre><ul>
<li>자원에 대한 정의 (AWS 자원 등...)</li>
<li>선언된 자원을 생성하는 동작 수행<br/>




</li>
</ul>
<h3 id="2-1-리소스-종속성">2-1. 리소스 종속성</h3>
<ul>
<li>각 요소의 생성 순서를 구분</li>
<li>다른 리소스에서 값을 참조해 불러올 경우, 생성 선후 관계에 따라 자동으로 연관 관계 정의 (암시적 종속성)</li>
<li><strong>depends_on</strong> : 강제로 리소스간 명시적 종속성 부여 인수</li>
<li>특정 리소스 속성 값이 필요한 경우, 리소스 우선 생성이 필요
-&gt; 종속성 발생 = 프로비저닝 순서 발생</li>
</ul>
<p>ex)</p>
<pre><code>resource &quot;local_file&quot; &quot;abc&quot; {      
  content = &quot;123!&quot;
  filename = &quot;${path.module}/abc.txt&quot;
}

resource &quot;local_file&quot; &quot;def&quot; {      
  content = local_file.abc.content       # 암시적 종속성 발생  
  filename = &quot;${path.module}/def.txt&quot;
}

resource &quot;local_file&quot; &quot;xyz&quot; {      
  depends_on = [        # 명시적 종속성 발생
    local_file.abc
  ]
  content = &quot;789!&quot; 
  filename = &quot;${path.module}/xyz.txt&quot;
}</code></pre><ul>
<li>암시적 종속성: abc.txt -&gt; def.txt 생성</li>
<li>명시적 종속성: abc.txt -&gt; xyz.txt 생성<br/>




</li>
</ul>
<h3 id="2-2-수명주기lifecycle">2-2. 수명주기(lifecycle)</h3>
<blockquote>
<h3 id="수명주기-옵션-인수">수명주기 옵션 인수</h3>
<p><strong>create_before_destroy (bool)</strong> : 리소스 수정시 신규 리소스 우선 생성 후 기존 리소스 삭제
<strong>prevent_destroy (bool)</strong> : 해당 리소스 삭제(destroy)시 명시적으로 거부
<strong>ignore_changes (list)</strong> : 리소스 요소에 선언된 인수 변경사항을 테라폼 실행 시 무시
<strong>precondition</strong> : 리소스 요소에 선언된 인수의 조건 검증
<strong>postcondition</strong> : plan 과 apply 이후 결과를 속성 값으로 검증</p>
</blockquote>
<p>ex)</p>
<pre><code>resource &quot;local_file&quot; &quot;abc&quot; {      
  content = &quot;123!&quot;
  filename = &quot;${path.module}/abc.txt&quot;

  lifecycle {
    create_before_destroy = true     # 신규 리소스 생성후 기존 리소스 삭제
  }

}</code></pre><p><br/><br/>
출처 : [한빛미디어] 테라폼으로 시작하는 IaC </p>
]]></description>
        </item>
        <item>
            <title><![CDATA[[Terraform] 테라폼 기초 명령어]]></title>
            <link>https://velog.io/@joo_oonu/Terraform-%ED%85%8C%EB%9D%BC%ED%8F%BC-%EA%B8%B0%EC%B4%88-%EB%AA%85%EB%A0%B9%EC%96%B4</link>
            <guid>https://velog.io/@joo_oonu/Terraform-%ED%85%8C%EB%9D%BC%ED%8F%BC-%EA%B8%B0%EC%B4%88-%EB%AA%85%EB%A0%B9%EC%96%B4</guid>
            <pubDate>Thu, 18 Apr 2024 04:35:30 GMT</pubDate>
            <description><![CDATA[<h3 id="1-init--초기화">1. init : 초기화</h3>
<pre><code>terraform init</code></pre><ul>
<li>루트모듈 구성 - 작업디렉토리 초기화</li>
</ul>
<blockquote>
</blockquote>
<ul>
<li><strong>모듈</strong> : 테라폼이 실행되는 디렉토리 - tf 파일, 변수 정의 파일(tfvars) 포함</li>
<li><strong>루트 모듈</strong> : 기본 작업 디렉터리에 정의된 파일 집합, 다른 모듈 호출 가능</li>
<li><strong>자식 모듈</strong> : 루트 모듈이 호출하는 다른 모듈</li>
</ul>
<br/>

<h3 id="2-validate--유효성-체크">2. validate : 유효성 체크</h3>
<pre><code>terraform validate</code></pre><ul>
<li>테라폼 파일(.tf) 유효성 체크 - 문법검사
<br/><br/></li>
</ul>
<h3 id="3-plan--실행-계획-생성">3. plan : 실행 계획 생성</h3>
<pre><code>terraform plan</code></pre><ul>
<li>apply 하기 전에 이상적인 상태와 실제 상태를 비교해 둘을 동일하게 만들기 위해서 해야할 일을 찾아내는 작업 <br/>


</li>
</ul>
<pre><code>terraform plan -out=tfplan </code></pre><ul>
<li>실행 계획 별도 저장(파일 생성)</li>
<li>실행 계획 파일은 확장자 없이 사용<br/>


</li>
</ul>
<pre><code>terraform plan -destroy -out=tf-rm-plan</code></pre><ul>
<li>삭제 계획 &amp; 삭제 계획 파일 생성
<br/><br/></li>
</ul>
<h3 id="4-apply--적용">4. apply : 적용</h3>
<pre><code>terraform apply</code></pre><ul>
<li>실제 상태를 이상적인 상태와 동일하게 만드는 것</li>
<li>계획 파일 지정 없이 실행시, 자동으로 plan 실행 후 apply 진행<br/>

</li>
</ul>
<pre><code>terraform apply tfplan</code></pre><ul>
<li>계획 파일 기반으로 apply - (yes/no 질문 X)<br/>

</li>
</ul>
<pre><code>terraform apply -replace=local_file.txt
terraform apply -replace=aws_instance.example</code></pre><ul>
<li><strong>replace</strong> : 특정 리소스 재생성 옵션 (삭제후 재생성)
<br/><br/></li>
</ul>
<h3 id="5-destroy--모든-개체-제거">5. destroy : 모든 개체 제거</h3>
<pre><code>terraform destroy   # = terraform apply -destroy</code></pre><ul>
<li>계획 파일 지정 없이 실행시, 자동으로 plan 실행 후 destroy 진행<br/>

</li>
</ul>
<pre><code>terraform destroy -auto-approve</code></pre><ul>
<li><strong>auto-approve</strong> : 자동 승인 옵션 (yum install -y라고 생각)
  -&gt; 조심하여 사용
<br/><br/></li>
</ul>
<h3 id="6-fmt--구성-파일tf-표준-스타일-적용">6. fmt : 구성 파일(.tf) 표준 스타일 적용</h3>
<pre><code>terraform fmt</code></pre><ul>
<li>tf 파일에 작성된 테라폼 코드 가독성을 높이는 작업</li>
<li>정렬, 빈칸, 내려쓰기 등의 규칙이 다른 경우 사용</li>
<li>최종적으로 코드 공유 시스템에 업로드전 실행하여 코드 중복 처리 및 업데이트 최소화<br/>

</li>
</ul>
<pre><code>terraform fmt -recursive</code></pre><ul>
<li><strong>recursive</strong> : 하위 디렉토리의 구성 파일 모두 포함 적용
<br/><br/></li>
</ul>
<h2 id="그-외-명령어">그 외 명령어</h2>
<h3 id="console--기능-및-문법-확인">console : 기능 및 문법 확인</h3>
<h3 id="state--상태-관리">state : 상태 관리</h3>
<h3 id="workspace--작업-공간-관리">workspace : 작업 공간 관리</h3>
<h3 id="import--상태-가져오기">import : 상태 가져오기</h3>
<ul>
<li>테라폼 코드로 생성되지 않은 리소스를 관리하기 위해 상태를 가져오기</li>
</ul>
<h3 id="login-logout--terraform-cloudenterprise-인증-정보-관리">login, logout : terraform cloud/enterprise 인증 정보 관리</h3>
<p><br/><br/>
출처 : [한빛미디어] 테라폼으로 시작하는 IaC </p>
]]></description>
        </item>
        <item>
            <title><![CDATA[Amazon Linux 2023 MySQL 설치]]></title>
            <link>https://velog.io/@joo_oonu/Amazon-Linux-2023-MySQL-%EC%84%A4%EC%B9%98</link>
            <guid>https://velog.io/@joo_oonu/Amazon-Linux-2023-MySQL-%EC%84%A4%EC%B9%98</guid>
            <pubDate>Wed, 17 Apr 2024 08:06:12 GMT</pubDate>
            <description><![CDATA[<p>Amazon Linux 2023에서 MySQL 설치시, 기본적으로 설정이 되어있지 않아 추가적인 설정이 필요하다.
<br/></p>
<p>트러블 슈팅을 통해 찾아낸 설치 방법을 정리해봤다.</p>
<br/>

<h3 id="1-rpm-파일-다운로드">1. RPM 파일 다운로드</h3>
<pre><code>sudo wget https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm</code></pre><br/>

<h3 id="2-gpg-퍼블릭-키-설정">2. GPG 퍼블릭 키 설정</h3>
<pre><code>sudo dnf install mysql80-community-release-el9-1.noarch.rpm -y</code></pre><ul>
<li>mysql 설치를 위해서 퍼블릭키를 import 해야함<pre><code>sudo dnf update -y</code></pre><br/>

</li>
</ul>
<h3 id="3-mysql-설치">3. MySQL 설치</h3>
<h4 id="3-1-mysql-client-설치">3-1 mysql-client 설치</h4>
<pre><code>sudo dnf install mysql-community-client -y</code></pre><br/>

<h4 id="3-2-mysql-server-설치">3-2 mysql-server 설치</h4>
<pre><code>sudo dnf install mysql-community-server -y</code></pre>]]></description>
        </item>
        <item>
            <title><![CDATA[[Centos] 자주 사용하는 firewall-cmd 명령어 정리]]></title>
            <link>https://velog.io/@joo_oonu/Centos7-firewall-cmd-%EB%AA%85%EB%A0%B9%EC%96%B4-%EC%A0%95%EB%A6%AC</link>
            <guid>https://velog.io/@joo_oonu/Centos7-firewall-cmd-%EB%AA%85%EB%A0%B9%EC%96%B4-%EC%A0%95%EB%A6%AC</guid>
            <pubDate>Mon, 11 Mar 2024 09:49:08 GMT</pubDate>
            <description><![CDATA[<p>실무에서 자주 사용했던 방화벽 관련 firewall-cmd 명령어를 간단하게 정리해보았다.
<br/></p>
<h3 id="기본-명령어">기본 명령어</h3>
<h4 id="방화벽-상태-확인">방화벽 상태 확인</h4>
<pre><code>firewall-cmd --state </code></pre><h4 id="설정된-목록-확인">설정된 목록 확인</h4>
<pre><code>firewall-cmd --list-all </code></pre><h4 id="방화벽-리로드">방화벽 리로드 </h4>
<pre><code>firewall-cmd --reload</code></pre><ul>
<li>설정 변경 후엔 꼭 리로드하기</li>
</ul>
<p>_--permanent 설정 유지 속성 _
<br></p>
<h3 id="서비스-추가제거">서비스 추가/제거 </h3>
<h4 id="서비스-추가">서비스 추가</h4>
<pre><code>firewall-cmd --permanent --add-service=ftp</code></pre><h4 id="서비스-삭제">서비스 삭제</h4>
<pre><code>firewall-cmd --permanent --remove-service=ftp</code></pre><br>

<h3 id="포트-추가제거">포트 추가/제거 </h3>
<h4 id="포트-추가">포트 추가</h4>
<pre><code>firewall-cmd --permanent --add-port=21/tcp </code></pre><h4 id="포트-삭제">포트 삭제</h4>
<pre><code>firewall-cmd --permanent --remove-port=21/tcp </code></pre><h4 id="포트-범위로-열기">포트 범위로 열기</h4>
<pre><code>firewall-cmd --permanent --add-port=8000-8100/tcp</code></pre><br>

<h3 id="아이피-허용삭제">아이피 허용/삭제</h3>
<h4 id="아이피-허용">아이피 허용</h4>
<pre><code>firewall-cmd --add-source=192.168.1.1</code></pre><h4 id="아이피-삭제">아이피 삭제</h4>
<pre><code>firewall-cmd --remove-source=192.168.1.1 </code></pre><h4 id="아이피--포트-허용">아이피 / 포트 허용</h4>
<pre><code>firewall-cmd --permanent --add-rich-rule=&#39;rule family=&quot;ipv4&quot; source address=192.168.1.1 port port=&quot;80&quot; protocol=&quot;tcp&quot; accept&#39; </code></pre><p> </p>
<h4 id="아이피--포트-허용-1">아이피 / 포트 허용</h4>
<pre><code>firewall-cmd --permanent --remove-rich-rule=&#39;rule family=&quot;ipv4&quot; source address=192.168.1.1 port port=&quot;80&quot; protocol=&quot;tcp&quot; accept&#39; </code></pre><br>
출처 : https://rootjs.tistory.com/101
]]></description>
        </item>
        <item>
            <title><![CDATA[Notion에서 Velog로..]]></title>
            <link>https://velog.io/@joo_oonu/Notion%EC%97%90%EC%84%9C-Velog%EB%A1%9C</link>
            <guid>https://velog.io/@joo_oonu/Notion%EC%97%90%EC%84%9C-Velog%EB%A1%9C</guid>
            <pubDate>Mon, 08 Jan 2024 04:19:18 GMT</pubDate>
            <description><![CDATA[<h2 id="notion에서-velog로">Notion에서 Velog로</h2>
<p>이제까지 나는 공부했던 지식들을 Notion에 정리해왔었다.</p>
<p>혼자 공부하기에는 부족함이 없었지만 오랜만에 정리를 하다보니,
시간이 지나 잊어버린 지식들도 꽤 있었고 정리가 필요한 부분들이 있어보였다.</p>
<br/>


<h2 id="앞으로">앞으로</h2>
<p>내가 지금까지 쌓았던 지식들을 정리할 기회로 생각하며 Notion 에 정리했던 내용들을 다시 한 번 정리하여 Velog 에 포스팅 하려한다.</p>
]]></description>
        </item>
    </channel>
</rss>