IT/CLOUD(AWS,Azure,GCP,Docker)

CentOS 7에 Ansible AWX를 설치하는 방법

알콩달콩아빠 2023. 11. 11. 20:37
728x90
반응형

이 튜토리얼은 다음 OS 버전에 대해 존재합니다.

  • 센트OS 8
  • 센트OS 7

이 페이지에서

  1. AWX 서버의 최소 시스템 요구 사항\n
  2. Ansible AWX 설치
  3. Nginx 구성
  4. AWX 서버에서 비밀번호 없는 로그인 구성\n
  5. 참조

이전 튜토리얼에서 Docker를 통해 Ansible AWX를 배포하는 방법을 보여드렸습니다. 그동안 AWX용 rpm 패키지를 빌드하는 두 개의 프로젝트를 찾았습니다. 따라서 이 튜토리얼에서는 CentOS 7의 RPM 파일에서 Ansible AWX를 설치하는 방법을 보여드리겠습니다. Ansible AWX는 Ansible Tower 소프트웨어의 오픈소스 버전입니다.

저는 CentOS 7 최소 설치와 허용 모드의 SELinux로 3개의 서버를 사용할 것입니다.

  • 192.168.1.25 AWX 서버
  • 192.168.1.21 클라이언트1
  • 192.168.1.22 클라이언트2

AWX Server의 최소 시스템 요구 사항

  • 최소 4GB의 메모리
  • 적어도 2개의 cpu 코어
  • 최소 20GB의 공간
  • Docker, Openshift 또는 Kubernetes 실행\n

SELinux 구성을 확인하세요.

[ ~]# sestatus
SELinux status:                 enabled
SELinuxfs mount:                /sys/fs/selinux
SELinux root directory:         /etc/selinux
Loaded policy name:             targeted
Current mode:                   permissive
Mode from config file:          permissive
Policy MLS status:              enabled
Policy deny_unknown status:     allowed
Max kernel policy version:      28
[ ~]#

다음에 호스트 항목을 추가하십시오.

/etc/hosts
[ ~]# cat /etc/hosts
192.168.1.25    awx.sunil.cc awx
192.168.1.21    client1.sunil.cc client1
192.168.1.22    client2.sunil.cc client2
[ ~]#

방화벽 규칙 추가

[ ~]# systemctl enable firewalld
Created symlink from /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service to /usr/lib/systemd/system/firewalld.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/firewalld.service to /usr/lib/systemd/system/firewalld.service.
[ ~]# systemctl start firewalld
[ ~]# firewall-cmd --add-service=http --permanent;firewall-cmd --add-service=https --permanent
success
success
[ ~]# systemctl restart firewalld
[ ~]#

CentOS EPEL 리포지토리를 활성화합니다.

[ ~]# yum install -y epel-release

AWX를 설치하려면 postgresql 9.6이 필요합니다.

postgreSQL 저장소를 활성화합니다.

[ ~]# yum install -y https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-7-x86_64/pgdg-centos96-9.6-3.noarch.rpm

postgreSQL 설치.

[ ~]# yum install postgresql96-server -y

필요한 다른 rpm을 설치합니다.

[ ~]# yum install -y rabbitmq-server wget memcached nginx ansible

Ansible AWX 설치

AWX 저장소를 추가합니다.

[ ~]# wget -O /etc/yum.repos.d/awx-rpm.repo https://copr.fedorainfracloud.org/coprs/mrmeee/awx/repo/epel-7/mrmeee-awx-epel-7.repo

RPM 설치

[ ~]# yum install -y awx

데이터베이스 초기화

[ ~]# /usr/pgsql-9.6/bin/postgresql96-setup initdb
Initializing database ... OK

[ ~]#

Rabbitmq 서비스 시작

[ ~]# systemctl start rabbitmq-server
[ ~]# systemctl enable rabbitmq-server
Created symlink from /etc/systemd/system/multi-user.target.wants/rabbitmq-server.service to /usr/lib/systemd/system/rabbitmq-server.service.
[ ~]#

PostgreSQL 서비스 시작

[ ~]# systemctl enable postgresql-9.6
Created symlink from /etc/systemd/system/multi-user.target.wants/postgresql-9.6.service to /usr/lib/systemd/system/postgresql-9.6.service.
[ ~]# systemctl start postgresql-9.6

Memcached 서비스 시작

[ ~]# systemctl enable memcached
Created symlink from /etc/systemd/system/multi-user.target.wants/memcached.service to /usr/lib/systemd/system/memcached.service.
[ ~]# systemctl start memcached

Postgres 사용자 생성

[ ~]# sudo -u postgres createuser -S awx
could not change directory to "/root": Permission denied
[ ~]#

데이터베이스 생성

[ ~]# sudo -u postgres createdb -O awx awx
could not change directory to "/root": Permission denied
[ ~]#

데이터를 데이터베이스로 가져오기

[ ~]# sudo -u awx /opt/awx/bin/awx-manage migrate

AWX 구성 초기화

[', 'password')" | sudo -u awx /opt/awx/bin/awx-manage shell
[ ~]# sudo -u awx /opt/awx/bin/awx-manage create_preload_data
Default organization added.
Demo Credential, Inventory, and Job Template added.
[ ~]# sudo -u awx /opt/awx/bin/awx-manage provision_instance --hostname=$(hostname)
Successfully registered instance awx.sunil.cc
(changed: True)
[ ~]# sudo -u awx /opt/awx/bin/awx-manage register_queue --queuename=tower --hostnames=$(hostname)
Creating instance group tower
Added instance awx.sunil.cc to tower
(changed: True)
[ ~]#

Nginx 구성

nginx.conf를 백업하십시오.

[ ~]# cd /etc/nginx/
[ nginx]# pwd
/etc/nginx
[ nginx]# cp nginx.conf nginx.conf.bkp

nginx conf 파일 교체

[ nginx]# wget -O /etc/nginx/nginx.conf https://raw.githubusercontent.com/sunilsankar/awx-build/master/nginx.conf

nginx 서비스 활성화 및 시작

[ ~]# systemctl start nginx
[ ~]# systemctl enable nginx

awx 서비스 시작

[ ~]# systemctl start awx-cbreceiver
[ ~]# systemctl start awx-celery-beat
[ ~]# systemctl start awx-celery-worker
[ ~]# systemctl start awx-channels-worker
[ ~]# systemctl start awx-daphne
[ ~]# systemctl start awx-web

다시 시작하는 동안 서비스가 시작되었는지 확인하십시오.

[ ~]# systemctl enable awx-cbreceiver
Created symlink from /etc/systemd/system/multi-user.target.wants/awx-cbreceiver.service to /usr/lib/systemd/system/awx-cbreceiver.service.
[ ~]# systemctl enable awx-celery-beat
Created symlink from /etc/systemd/system/multi-user.target.wants/awx-celery-beat.service to /usr/lib/systemd/system/awx-celery-beat.service.
[ ~]# systemctl enable awx-celery-worker
Created symlink from /etc/systemd/system/multi-user.target.wants/awx-celery-worker.service to /usr/lib/systemd/system/awx-celery-worker.service.
[ ~]# systemctl enable awx-channels-worker
Created symlink from /etc/systemd/system/multi-user.target.wants/awx-channels-worker.service to /usr/lib/systemd/system/awx-channels-worker.service.
[ ~]# systemctl enable awx-daphne
Created symlink from /etc/systemd/system/multi-user.target.wants/awx-daphne.service to /usr/lib/systemd/system/awx-daphne.service.
[ ~]# systemctl enable awx-web
Created symlink from /etc/systemd/system/multi-user.target.wants/awx-web.service to /usr/lib/systemd/system/awx-web.service.
[ ~]#

AWX 서버에서 비밀번호 없는 로그인 구성

3개의 호스트 모두에서 사용자를 생성합니다.

이 튜토리얼에서는 3개 서버 모두에서 ansible 사용자를 생성합니다.

[ ~]# useradd ansible
[ ~]# useradd ansible
[ ~]# useradd ansible

awx 서버에서 ssh 키 생성

[ nginx]# su - ansible
[ ~]$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ansible/.ssh/id_rsa):
Created directory '/home/ansible/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ansible/.ssh/id_rsa.
Your public key has been saved in /home/ansible/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:RW/dhTsxcyGicleRI0LpLm+LyhAVinm0xktapodc8gY 
The key's randomart image is:
+---[RSA 2048]----+
|   . .  ..o. +ooo|
|  = o .  +.oo+*.o|
| E @ . ..oo.+ o*.|
|. # o   oo..  o  |
| = *    S      . |
|  o .  . .       |
|   .    o        |
|    o   .o       |
|     o.....      |
+----[SHA256]-----+
[ ~]$

3개 서버 모두에 sudoers 항목을 파일의 마지막 항목으로 추가

[ nginx]# visudo
ansible ALL=(ALL) NOPASSWD: ALL

id_rsa.pub의 콘텐츠를 3개 서버 모두의 authorized_keys에 복사합니다.

[ .ssh]$ cat id_rsa.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDStB8JGsVsSLppwYWdnEPLE4xwFqRDn7xE/d3hjBQ6A0JGm1t+GtHB3GPIEjANFTnxQwHpR+cRttbL3mlQvpIYqCZOMZds9XA7VI5qgs0aSGUU8cNYKjmmrMpJa9sB4WVtj3M4u2fEXt9FKKCtjMMpOfiQxIkEhYZ+2GoAX5sHXan7TPcgwb5r7WW6j43aaPc6g9XWN63nonQz6KeMSFZ/y0o2HJMh1FEkktZw6A1HVfn+JNWoQb1glyqGjO1ync+Sok8yXpqakEEWpXNQSQYs4eBEwfkKql5EuolQMIbF9VYhpEcR9LfbMvYdq/RPKWN3mmRMWfPZ2dTZl515XBdV 
[ .ssh]$
[ .ssh]$ cat authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDStB8JGsVsSLppwYWdnEPLE4xwFqRDn7xE/d3hjBQ6A0JGm1t+GtHB3GPIEjANFTnxQwHpR+cRttbL3mlQvpIYqCZOMZds9XA7VI5qgs0aSGUU8cNYKjmmrMpJa9sB4WVtj3M4u2fEXt9FKKCtjMMpOfiQxIkEhYZ+2GoAX5sHXan7TPcgwb5r7WW6j43aaPc6g9XWN63nonQz6KeMSFZ/y0o2HJMh1FEkktZw6A1HVfn+JNWoQb1glyqGjO1ync+Sok8yXpqakEEWpXNQSQYs4eBEwfkKql5EuolQMIbF9VYhpEcR9LfbMvYdq/RPKWN3mmRMWfPZ2dTZl515XBdV 
[ .ssh]$ chmod 600 authorized_keys

클라이언트1

[ ~]# su - ansible
[ ~]$ mkdir .ssh
[ ~]$ chmod 700 .ssh
[ ~]$ cat .ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDStB8JGsVsSLppwYWdnEPLE4xwFqRDn7xE/d3hjBQ6A0JGm1t+GtHB3GPIEjANFTnxQwHpR+cRttbL3mlQvpIYqCZOMZds9XA7VI5qgs0aSGUU8cNYKjmmrMpJa9sB4WVtj3M4u2fEXt9FKKCtjMMpOfiQxIkEhYZ+2GoAX5sHXan7TPcgwb5r7WW6j43aaPc6g9XWN63nonQz6KeMSFZ/y0o2HJMh1FEkktZw6A1HVfn+JNWoQb1glyqGjO1ync+Sok8yXpqakEEWpXNQSQYs4eBEwfkKql5EuolQMIbF9VYhpEcR9LfbMvYdq/RPKWN3mmRMWfPZ2dTZl515XBdV 
[ ~]$ chmod 600 .ssh/authorized_keys

클라이언트2

[ ~]# su - ansible
[ ~]$ mkdir .ssh
[ ~]$ chmod 700 .ssh
[ ~]$ cat .ssh/authorized_keys
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDStB8JGsVsSLppwYWdnEPLE4xwFqRDn7xE/d3hjBQ6A0JGm1t+GtHB3GPIEjANFTnxQwHpR+cRttbL3mlQvpIYqCZOMZds9XA7VI5qgs0aSGUU8cNYKjmmrMpJa9sB4WVtj3M4u2fEXt9FKKCtjMMpOfiQxIkEhYZ+2GoAX5sHXan7TPcgwb5r7WW6j43aaPc6g9XWN63nonQz6KeMSFZ/y0o2HJMh1FEkktZw6A1HVfn+JNWoQb1glyqGjO1ync+Sok8yXpqakEEWpXNQSQYs4eBEwfkKql5EuolQMIbF9VYhpEcR9LfbMvYdq/RPKWN3mmRMWfPZ2dTZl515XBdV 
[ ~]$ chmod 600 .ssh/authorized_keys

AWX 서버에서 비밀번호 없는 로그인을 확인하세요.

[ ~]$ ssh client1
Last login: Sun Mar 11 13:14:06 2018 from 192.168.1.25
[ ~]$ exit
logout
Connection to client1 closed.
[ ~]$ ssh client2
Last login: Sun Mar 11 12:50:14 2018 from 192.168.1.25
[ ~]$

로그인 확인:

로그인 세부 정보는 다음과 같습니다.

사용자 이름: "admin"
비밀번호: "password"

다음 자습서에서는 플레이북을 추가하고 작업을 실행하는 방법을 보여줍니다.

 

출처 : CentOS 7에 Ansible AWX를 설치하는 방법 (linux-console.net)

728x90
반응형