ansible安装部署_ansible UI管理工具awx安装实践

环境说明:

主机名os versionipdocker versiondocker-compose  versionansible versionawx version备注
ansible-awxCentos 7.6.1810172.27.34.50Docker 19.03.91.25.52.9.910.0.0管理节点
centos01Centos 7.6.1810172.27.34.28××××被管节点
centos02Centos 7.6.1810172.27.34.35××××被管节点
centos03Centos 7.3.1611172.27.34.161××××被管节点

一、简介

ansible简介

Ansible是一个非常简单的IT自动化平台,使程序和系统更易于部署。Ansible本质上是一个进行了封装的Shell,优点在于它是去中心化的工具,可以直接通过ssh管理远程主机,实现无Agent的部署。

AWX简介

AWX提供了一个基于web的用户界面、REST API和构建在Ansible之上的任务引擎。图形化的AWX 能够更方便的编排和部署 Ansible Playbook,并提供集中的日志记录、审计和系统跟踪。AWX是商业版Ansible Tower  的开源版本。

awx项目地址:https://github.com/ansible/awx/

二、ansible安装

1.安装EPEL源

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

ce703e679e7882b2e709d218b5d5d2a8.png

2.安装asnible

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

71b2b0f4c58ce9b2089071d253e0f514.png

默认为最新版

[root@ansible-awx ~]# ansible --version

c83960c1c2808bb3403335fdc80b5147.png

三、docker安装

1.安装依赖包

[root@ansible-awx ~]# yum install -y yum-utils   device-mapper-persistent-data   lvm2

17869f495576a73340fe85923c9778eb.png

2.设置docker源

[root@ansible-awx ~]# yum-config-manager     --add-repo     https://download.docker.com/linux/centos/docker-ce.repo

4a1a04b6493223a130a00203e7d4e356.png

docker安装版本查看

054fc08670ee348280365b339e4661b7.png

3.安装docker

[root@ansible-awx ~]# yum install -y docker-ce docker-ce-cli containerd.io

fe01fdbc2336d662f7243c9195b562e4.png

未指定版本,默认为最新版

4.启动docker

[root@ansible-awx ~]# systemctl start docker[root@ansible-awx ~]# systemctl enable docker

c40767f7451f8de2ae3700d8a41e6fd8.png

5. 命令补全

5.1 安装bash-completion
[root@ansible-awx ~]# yum -y install bash-completion
5.2 加载bash-completion
[root@ansible-awx ~]# source /etc/profile.d/bash_completion.sh

821662299dca32beea36ca7321a4f045.png

6. 镜像加速

由于Docker Hub的服务器在国外,下载镜像会比较慢,可以配置镜像加速器。主要的加速器有:Docker官方提供的中国registry mirror、阿里云加速器、DaoCloud 加速器,本文以阿里加速器配置为例。

6.1 登陆阿里云容器模块

登陆地址为:https://cr.console.aliyun.com ,未注册的可以先注册阿里云账户

6.2 配置镜像加速器

配置daemon.json文件

[root@centos7 ~]# mkdir -p /etc/docker[root@centos7 ~]# tee /etc/docker/daemon.json <{  "registry-mirrors": ["https://v16stybc.mirror.aliyuncs.com"]}EOF

重启服务

[root@centos7 ~]# systemctl daemon-reload[root@centos7 ~]# systemctl restart docker

90908a91e63d45f54978a3ddf82bb8f5.png

加速器配置完成

四、安装Python模块

1.安装pip3

[root@ansible-awx ~]# yum -y install python3-pip

7cb37164a8e34e75cfe6a41be0992ba8.png

2.安装 docker-compose 的Python模块

[root@ansible-awx ~]# pip3 install docker-compose

c65524fc94a6fd0c18004e2b92756af0.png

由于网络原因,安装过程中可能会失败,多试两次即可。

五、安装Docker Compose

1.下载二进制文件

各版本下载地址:https://github.com/docker/compose/releases

[root@ansible-awx ~]# curl -L "https://github.com/docker/compose/releases/download/1.25.5/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

a070a699cf460b9bbe864bdcbf9f3df6.png

2.赋权

[root@ansible-awx ~]# chmod +x /usr/local/bin/docker-compose

3.安装验证

[root@ansible-awx ~]# docker-compose --versiondocker-compose version 1.25.5, build 8a1c60f6

六、awx安装

1.下载awx

awx下载地址:https://github.com/ansible/awx/releases ,本文选择版本为10.0.0

[root@ansible-awx ~]# wget https://github.com/ansible/awx/archive/10.0.0.tar.gz

解压

[root@ansible-awx ~]# wget https://github.com/ansible/awx/archive/10.0.0.tar.gz[root@ansible-awx ~]# ll总用量 10736-rw-r--r--   1 root root 10983696 5月  21 14:36 10.0.0.tar.gz-rw-------.  1 root root     1322 5月  21 11:43 anaconda-ks.cfgdrwxrwxr-x  11 root root     4096 3月  31 00:42 awx-10.0.0

2.修改配置

[root@ansible-awx ~]# cd awx-10.0.0/installer/[root@ansible-awx installer]# ll总用量 16-rw-rw-r-- 1 root root  167 3月  31 00:42 build.yml-rw-rw-r-- 1 root root  437 3月  31 00:42 install.yml-rw-rw-r-- 1 root root 6131 3月  31 00:42 inventorydrwxrwxr-x 7 root root   99 3月  31 00:42 roles[root@ansible-awx installer]# sed -i.bak 's/env python/env python3/g' inventory[root@ansible-awx installer]# ll总用量 24-rw-rw-r-- 1 root root  167 3月  31 00:42 build.yml-rw-rw-r-- 1 root root  437 3月  31 00:42 install.yml-rw-rw-r-- 1 root root 6132 5月  21 14:41 inventory-rw-rw-r-- 1 root root 6131 3月  31 00:42 inventory.bakdrwxrwxr-x 7 root root   99 3月  31 00:42 roles

修改配置文件inventory,使用python3,其他保持默认配置。

3.下载镜像

3.1镜像下载
[root@ansible-awx ~]# docker pull registry.cn-hangzhou.aliyuncs.com/loong576/awx_web:10.0.0[root@ansible-awx ~]# docker pull registry.cn-hangzhou.aliyuncs.com/loong576/awx_task:10.0.0[root@ansible-awx ~]# docker pull registry.cn-hangzhou.aliyuncs.com/loong576/memcached:alpine[root@ansible-awx ~]# docker pull registry.cn-hangzhou.aliyuncs.com/loong576/postgres:10[root@ansible-awx ~]# docker pull registry.cn-hangzhou.aliyuncs.com/loong576/redis

awx的组件通过容器方式安装,分别下载对应版本镜像,,镜像下载需要些时间,请保持网络环境稳定。

3.2打tag
[root@ansible-awx ~]# docker tag registry.cn-hangzhou.aliyuncs.com/loong576/awx_task:10.0.0 ansible/awx_task:10.0.0[root@ansible-awx ~]# docker tag registry.cn-hangzhou.aliyuncs.com/loong576/awx_web:10.0.0 ansible/awx_web:10.0.0[root@ansible-awx ~]# docker tag registry.cn-hangzhou.aliyuncs.com/loong576/redis redis[root@ansible-awx ~]# docker tag registry.cn-hangzhou.aliyuncs.com/loong576/postgres:10 postgres:10[root@ansible-awx ~]# docker tag registry.cn-hangzhou.aliyuncs.com/loong576/memcached:alpine memcached:alpine
3.3删除多余镜像
[root@ansible-awx ~]# docker rmi registry.cn-hangzhou.aliyuncs.com/loong576/awx_web:10.0.0 registry.cn-hangzhou.aliyuncs.com/loong576/redis registry.cn-hangzhou.aliyuncs.com/loong576/postgres:10 registry.cn-hangzhou.aliyuncs.com/loong576/memcached:alpine
3.4镜像查看
[root@ansible-awx ~]# docker imagesREPOSITORY          TAG                 IMAGE ID            CREATED             SIZEredis               latest              987b78fc9e38        2 days ago          104MBpostgres            10                  d92854c53ed1        5 days ago          200MBmemcached           alpine              35acd9837d07        7 days ago          9.28MBansible/awx_task    10.0.0              a968a1c4d9fd        7 weeks ago         2GBansible/awx_web     10.0.0              2cc33f01ffa7        7 weeks ago         1.96GB

4.awx安装

[root@ansible-awx installer]# pwd/root/awx-10.0.0/installer[root@ansible-awx installer]# ansible-playbook -i inventory install.yml

acb26dbeb1b2b263fdccdb07e8255674.png

容器查看

[root@ansible-awx ~]# docker psCONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS              PORTS                  NAMES6cbcc91766c2        ansible/awx_task:10.0.0   "/tini -- /bin/sh -c…"   2 hours ago         Up About an hour    8052/tcp               awx_taskd5b698ef603f        ansible/awx_web:10.0.0    "/tini -- /bin/sh -c…"   2 hours ago         Up About an hour    0.0.0.0:80->8052/tcp   awx_web20f9e95f0c1c        postgres:10               "docker-entrypoint.s…"   2 hours ago         Up About an hour    5432/tcp               awx_postgres35133c5b8b5f        redis                     "docker-entrypoint.s…"   2 hours ago         Up About an hour    6379/tcp               awx_redis93d2bd24b6c5        memcached:alpine          "docker-entrypoint.s…"   2 hours ago         Up About an hour    11211/tcp              awx_memcached

七、登录awx

登陆地址:http://172.27.34.50

6f2ec3d34330fc7cc33f8fbece3a6a55.png

输入用户名admin,默认密码为password

2406050b6952d3eebc6f05b18d227448.png

八、awx实践

新增清单

a6e3fc4810c03688650df4e406cb71b6.png

清单名称为测试区

6d3d4292ceae627a324ce2a3d55237b5.png

创建主机

66f53b3e0d91f84cea9b4cdd72d08008.png

分别新增被管主机172.27.34.28/35/161,指定登录用户和密码

8c88e3aee8e0115c3800b2196a3bc4c5.png

主机新增完毕

b570e673020092d802202f6c25539262.png

执行命令

dc786fac3d4bdf1e1b2157525394d7ee.png

查看各被管主机用户

5ede4e5edea79fbacaf06388f199ac07.png

参数为:cat /etc/passwd|grep -v 'nologin|shutdown|sync|halt'|awk -F : '{print $1}'

4986367aedd8b7916d9a6015377f3a29.png

命令执行完成

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值