環境說明:python
主機名 | os version | ip | docker version | docker-compose version | ansible version | awx version | 備註 |
---|---|---|---|---|---|---|---|
ansible-awx | Centos 7.6.1810 | 172.27.34.50 | Docker 19.03.9 | 1.25.5 | 2.9.9 | 10.0.0 | 管理節點 |
centos01 | Centos 7.6.1810 | 172.27.34.28 | × | × | × | × | 被管節點 |
centos02 | Centos 7.6.1810 | 172.27.34.35 | × | × | × | × | 被管節點 |
centos03 | Centos 7.3.1611 | 172.27.34.161 | × | × | × | × | 被管節點 |
Ansible是一個很是簡單的IT自動化平臺,使程序和系統更易於部署。Ansible本質上是一個進行了封裝的Shell,優勢在於它是去中心化的工具,能夠直接經過ssh管理遠程主機,實現無Agent的部署。linux
AWX提供了一個基於web的用戶界面、REST API和構建在Ansible之上的任務引擎。 圖形化的AWX 可以更方便的編排和部署 Ansible Playbook,並提供集中的日誌記錄、審計和系統跟蹤。AWX是商業版Ansible Tower 的開源版本。git
awx項目地址:https://github.com/ansible/awx/github
[root@ansible-awx ~]# yum -y install epel-release
[root@ansible-awx ~]# yum -y install ansible
默認爲最新版web
[root@ansible-awx ~]# ansible --version
[root@ansible-awx ~]# yum install -y yum-utils device-mapper-persistent-data lvm2
[root@ansible-awx ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
docker安裝版本查看redis
[root@ansible-awx ~]# yum install -y docker-ce docker-ce-cli containerd.io
未指定版本,默認爲最新版docker
[root@ansible-awx ~]# systemctl start docker [root@ansible-awx ~]# systemctl enable docker
[root@ansible-awx ~]# yum -y install bash-completion
[root@ansible-awx ~]# source /etc/profile.d/bash_completion.sh
因爲Docker Hub的服務器在國外,下載鏡像會比較慢,能夠配置鏡像加速器。主要的加速器有:Docker官方提供的中國registry mirror、阿里雲加速器、DaoCloud 加速器,本文以阿里加速器配置爲例。json
登錄地址爲:https://cr.console.aliyun.com ,未註冊的能夠先註冊阿里雲帳戶centos
配置daemon.json文件bash
[root@centos7 ~]# mkdir -p /etc/docker [root@centos7 ~]# tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://v16stybc.mirror.aliyuncs.com"] } EOF
重啓服務
[root@centos7 ~]# systemctl daemon-reload [root@centos7 ~]# systemctl restart docker
加速器配置完成
[root@ansible-awx ~]# yum -y install python3-pip
[root@ansible-awx ~]# pip3 install docker-compose
因爲網絡緣由,安裝過程當中可能會失敗,多試兩次便可。
各版本下載地址: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
[root@ansible-awx ~]# chmod +x /usr/local/bin/docker-compose
[root@ansible-awx ~]# docker-compose --version docker-compose version 1.25.5, build 8a1c60f6
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.cfg drwxrwxr-x 11 root root 4096 3月 31 00:42 awx-10.0.0
[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 inventory drwxrwxr-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.bak drwxrwxr-x 7 root root 99 3月 31 00:42 roles
修改配置文件inventory,使用python3,其餘保持默認配置。
[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的組件經過容器方式安裝,分別下載對應版本鏡像,,鏡像下載須要些時間,請保持網絡環境穩定。
[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
[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
[root@ansible-awx ~]# docker images REPOSITORY TAG IMAGE ID CREATED SIZE redis latest 987b78fc9e38 2 days ago 104MB postgres 10 d92854c53ed1 5 days ago 200MB memcached alpine 35acd9837d07 7 days ago 9.28MB ansible/awx_task 10.0.0 a968a1c4d9fd 7 weeks ago 2GB ansible/awx_web 10.0.0 2cc33f01ffa7 7 weeks ago 1.96GB
[root@ansible-awx installer]# pwd /root/awx-10.0.0/installer [root@ansible-awx installer]# ansible-playbook -i inventory install.yml
容器查看
[root@ansible-awx ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 6cbcc91766c2 ansible/awx_task:10.0.0 "/tini -- /bin/sh -c…" 2 hours ago Up About an hour 8052/tcp awx_task d5b698ef603f 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_web 20f9e95f0c1c postgres:10 "docker-entrypoint.s…" 2 hours ago Up About an hour 5432/tcp awx_postgres 35133c5b8b5f redis "docker-entrypoint.s…" 2 hours ago Up About an hour 6379/tcp awx_redis 93d2bd24b6c5 memcached:alpine "docker-entrypoint.s…" 2 hours ago Up About an hour 11211/tcp awx_memcached
登錄地址:http://172.27.34.50
輸入用戶名admin,默認密碼爲password
新增清單
清單名稱爲測試區
建立主機
分別新增被管主機172.27.34.28/35/161,指定登陸用戶和密碼
主機新增完畢
執行命令
查看各被管主機用戶
參數爲:cat /etc/passwd|grep -v 'nologin|shutdown|sync|halt'|awk -F : '{print $1}'
命令執行完成
本文全部介質和配置文件已上傳:ansible-awx