如何在CentOS 7上安装Ansible AWX

如何在CentOS 7上安装Ansible AWX

之前的教程中 ,我向您展示了如何通过docker部署Ansible AWX。 同时,我发现了两个为AWX构建rpm包的项目。 因此,在本教程中,我将向您展示如何在CentOS 7上从RPM文件安装Ansible AWX。Ansible AWX是Ansible Tower软件的开源版本。

我将在宽松模式下使用3台服务器, CentOS 7最低安装和SELinux。

  • 192.168.1.25 AWX服务器
  • 192.168.1.21 client1
  • 192.168.1.22 client2

AWX服务器的最低系统要求

  • 至少4GB的内存
  • 至少2个cpu核心
  • 至少20GB的空间
  • 运行Docker,Openshift或Kubernetes

检查SELinux配置。

[root@awx ~]# 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
[root@awx ~]#

添加主机条目

/etc/hosts
[root@awx ~]# 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
[root@awx ~]#

添加防火墙规则

[root@awx ~]# 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.
[root@awx ~]# systemctl start firewalld
[root@awx ~]# firewall-cmd --add-service=http --permanent;firewall-cmd --add-service=https --permanent
success
success
[root@awx ~]# systemctl restart firewalld
[root@awx ~]#

启用CentOS EPEL存储库。

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

我们需要postgresql 9.6来安装AWX。

启用postgreSQL回购。

[root@awx ~]# 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。

[root@awx ~]# yum install postgresql96-server -y

安装其他必要的RPM。

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

安装Ansible AWX

添加AWX回购。

[root@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

[root@awx ~]# yum install -y awx

初始化数据库

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

[root@awx ~]#

开始Rabbitmq服务

[root@awx ~]# systemctl start rabbitmq-server
[root@awx ~]# 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.
[root@awx ~]#

启动PostgreSQL服务

[root@awx ~]# 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.
[root@awx ~]# systemctl start postgresql-9.6

启动Memcached服务

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

创建Postgres用户

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

忽略错误

创建数据库

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

忽略错误

将数据导入数据库

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

初始化AWX的配置

[root@awx ~]# echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'root@localhost', 'password')" | sudo -u awx /opt/awx/bin/awx-manage shell
[root@awx ~]# sudo -u awx /opt/awx/bin/awx-manage create_preload_data
Default organization added.
Demo Credential, Inventory, and Job Template added.
[root@awx ~]# sudo -u awx /opt/awx/bin/awx-manage provision_instance --hostname=$(hostname)
Successfully registered instance awx.sunil.cc
(changed: True)
[root@awx ~]# 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)
[root@awx ~]#

配置Nginx

采取nginx.conf的备份

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

替换nginx conf文件

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

启用并启动nginx服务

[root@awx ~]# systemctl start nginx
[root@awx ~]# systemctl enable nginx

启动awx服务

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

确保服务在重启过程中启动

[root@awx ~]# 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.
[root@awx ~]# 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.
[root@awx ~]# 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.
[root@awx ~]# 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.
[root@awx ~]# 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.
[root@awx ~]# 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.
[root@awx ~]#

从AWX服务器配置无密码登录

在所有3台主机上创建一个用户。

在本教程中,我将在所有3台服务器上创建一个用户。

[root@awx ~]# useradd ansible
[root@client1 ~]# useradd ansible
[root@clien2 ~]# useradd ansible

在awx服务器中生成ssh密钥

[root@awx nginx]# su - ansible
[ansible@awx ~]$ 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 ansible@awx.sunil.cc
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]-----+
[ansible@awx ~]$

在所有3台服务器上添加sudoers条目作为该文件的最后一个条目

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

将所有3台服务器上的id_rsa.pub的内容复制到authorized_keys

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

客户端1

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

客户端2

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

检查来自AWX服务器的无密码登录。

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

验证登录:

登录详细信息是:

用户名:“ admin
密码:“ 密码

在接下来的教程中将展示如何添加剧本并运行作业。

参考

赞(52) 打赏
未经允许不得转载:优客志 » 系统运维
分享到:

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏