linux

ansible 설치 및 ansible로 nginx 설치

sysman 2021. 5. 31. 01:20

파이썬 버전 확인

[root@master ~]# python --version

외부 패키지 설치

[root@master ~]# yum install -y epel-release

패키지 업데이트

[root@master ~]# yum repolist

앤서블 설치

[root@master ~]# yum install -y ansible

앤서블 버전확인

[root@master ~]# ansible --version
ansible 2.9.21

... 생략

 

worker node 접속확인

[root@master ~]# ssh root@192.168.200.151

...

root@192.168.200.151's password:
Last login: Mon May 31 00:28:51 2021
[root@answorker ~]#exit

 

앤서블 호스트 작성

[root@master ~]# vi /etc/ansible/hosts

.. 

맨 아래쪽에 작성

[nginx]
192.168.200.151

worker node 핑테스트

[root@master ~]# ansible all -m ping -k
SSH password:
192.168.200.151 | SUCCESS => {
    "ansible_facts": {
        "discovered_interpreter_python": "/usr/bin/python"
    },
    "changed": false,
    "ping": "pong"
}
[root@master ~]#

 

nginx 설치 야믈 코드 작성

[root@master ~]# vi ans_nginx.yml

---
- name: Install nginx on linux
  hosts: nginx
  gather_facts: no

  tasks:
    - name: install epel-release
      yum: name=epel-release state=latest
    - name: install nginx web server
      yum: name=nginx state=present
    - name: upload default index.html for web server
      get_url: url=https://www.nginx.com dest=/usr/share/nginx/html/ mode=0644
    - name: start nginx web server
      service: name=nginx state=started

 

nginx 야믈 코드 실행

[root@master ~]# ansible-playbook ans_nginx.yml -k
SSH password:
PLAY [Install nginx on linux] **********************************************************************************
TASK [install epel-release] *********************************************************************************************
changed: [192.168.200.151]

TASK [install nginx web server] *********************************************************************************
changed: [192.168.200.151]

TASK [upload default index.html for web server] ***************************************************************
changed: [192.168.200.151]

TASK [start nginx web server] **********************************************************************************
changed: [192.168.200.151]

PLAY RECAP ***************************************************************************************************
192.168.200.151            : ok=4    changed=4    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

[root@master ~]#

 

확인

[root@master ~]# curl 192.168.200.151
<!DOCTYPE html>
<html lang="en-US">
<head>

  <script>
  //some global vars. DO NOT change these variables names. These variables are being used in GTM.
  var NX_GDPR_FUNCTIONAL_COOKIE_CONSENT = NX_GDPR_FUNCTIONAL_COOKIE_CONSENT || "no"; // possible values are 'yes' and 'no'
  var NX_GDPR_SOCIAL_COOKIE_CONSENT = NX_GDPR_SOCIAL_COOKIE_CONSENT || "no"; // possible values are 'yes' and 'no'
  //end global vars
  </script>

 

[root@master ~]# ssh root@192.168.200.151
root@192.168.200.151's password:
Last login: Mon May 31 01:16:32 2021 from 192.168.200.150

rpm 확인

[root@answorker ~]# rpm -qa | grep nginx
nginx-mod-stream-1.16.1-3.el7.x86_64
nginx-mod-http-image-filter-1.16.1-3.el7.x86_64
nginx-mod-http-perl-1.16.1-3.el7.x86_64
nginx-filesystem-1.16.1-3.el7.noarch
nginx-mod-mail-1.16.1-3.el7.x86_64
nginx-mod-http-xslt-filter-1.16.1-3.el7.x86_64
nginx-1.16.1-3.el7.x86_64
nginx-all-modules-1.16.1-3.el7.noarch

 

nginx 데몬 확인
[root@answorker ~]# systemctl status nginx
* nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Mon 2021-05-31 00:57:43 KST; 20min ago
  Process: 2044 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 2041 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 2039 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 2046 (nginx)
   CGroup: /system.slice/nginx.service
           |-2046 nginx: master process /usr/sbin/nginx
           |-2047 nginx: worker process
           `-2048 nginx: worker process

May 31 00:57:43 answorker systemd[1]: Starting The nginx HTTP and reverse proxy server...
May 31 00:57:43 answorker nginx[2041]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
May 31 00:57:43 answorker nginx[2041]: nginx: configuration file /etc/nginx/nginx.conf test is successful
May 31 00:57:43 answorker systemd[1]: Started The nginx HTTP and reverse proxy server.
[root@answorker ~]#

 

웹에서도 확인