Notice
Recent Posts
Recent Comments
«   2025/08   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
Archives
Today
Total
관리 메뉴

ITFragile

[Ansible] 01. 작업 환경 구성 본문

Project

[Ansible] 01. 작업 환경 구성

경요 2023. 3. 15. 16:20

작업환경 : virtualbox / ubuntu 20.04 / ansible 2.9.6

 

Server Install List

webserver : apache2, php, php-mysql

dbserver: mariadb

LoadBalancer : haproxy

 

Control-node Info

control-node01 : 192.168.56.101

 

WEB Server Info

web-01 : 192.168.56.102

web-02 : 192.168.56.103

 

DB Server Info
db-m01 : 192.168.56.104
db-s02 : 192.168.56.105

 

LoadBalancer Info

lb-01 : 192.168.56.106

 


vagrant ssh control-node01

 

1. 레포리지 저장소 추가

sudo apt install -y epel-release

레포리지 저장소 경로

2. ansible 설치

sudo apt install -y ansible
ansible --version # ansible version 확인

3. 디렉토리 생성

4. 구성 파일 생성

- ansible.cfg : 작업 시 사용할 설정

[defaults]
inventory = inventory
remote_user = ansible # ansible 유저로 접속 허용
ask_pass = false # 해당 사용자로 접속시 패스워드 묻지 않음

[privilege_escalation]
become = true # 루트 사용자가 아니어도 권한 허용
become_ask_pass = false
become_user = root
become_method = sudo # sudo 권한 획득

- inventory : 작업 대상 지정

[web]
web-01
web-02

[db]
db-m01
db-s01

[lb]
lb-01

 

5. 사용자 생성 후 초기구성

- 각 호스트에서 ansible 사용자 생성

vagrant ssh host1
sudo useradd ansible
sudo passwd ansible # 패스워드 설정

 

- 각 호스트에서 /etc/sudoers.d/ansible 생성

sudo touch /etc/sudoers.d/ansible
sudo cp /etc/sudoers.d/vagrant /etc/sudoers.d/ansible
sudo chmod u+w /etc/sudoers.d/ansible

sudo vi /etc/sudoers.d/ansible 
ansible ALL=(ALL) NOPASSWD: ALL # 기본 사용자인 vagrant를 ansible로 변경

sudo mkdir /home/ansible
sudo chown ansible: /home/ansible

 

6. 컨트롤 노드에서 키 생성

ssh-keygen

7. 컨트롤노드에서 ssh-key 복사

ssh-copy-id ansible@web-01
ssh-copy-id ansible@web-02
ssh-copy-id ansible@db-m01
ssh-copy-id ansible@db-s01
ssh-copy-id ansible@lb-01

8. ansible 실행

ping 확인

 

'Project' 카테고리의 다른 글

[Ansible] 03. HAProxy 설정  (0) 2023.03.16
[Ansible] 02. Playbook 작성  (0) 2023.03.15
[Linux] 04. WEB - DB 로드밸런싱  (0) 2023.03.15
[Linux] 03. DB 이중화  (0) 2023.03.15
[Linux] 02. WEB - DB 연동  (0) 2023.03.15