首頁 > 軟體

CentOS 6.5安裝自動化工具Ansible和圖形化工具Tower

2020-06-16 17:20:07

一、CentOS 6.5安裝ansible並測試

1、檢視系統版本:

[root@ansible-server etc]# lsb_release -a

LSB Version:    :base-4.0-amd64:base-4.0-noarch:core-4.0-amd64:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-noarch:printing-4.0-amd64:printing-4.0-noarch

Distributor ID: CentOS

Description:    CentOS release 6.5 (Final)

Release:        6.5

Codename:      Final

2、安裝ansible設定yum設定

163源

[root@ansible-server yum.repos.d]# vi CentOS-Base.repo

[163base]

name=CentOS-$releasever - Base - 163.com

baseurl=http://mirrors.163.com/centos/$releasever/os/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#released updates

[163updates]

name=CentOS-$releasever - Updates - 163.com

baseurl=http://mirrors.163.com/centos/$releasever/updates/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful

[163extras]

name=CentOS-$releasever - Extras - 163.com

baseurl=http://mirrors.163.com/centos/$releasever/extras/$basearch/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras

gpgcheck=1

gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-6

epel源

[root@ansible-server yum.repos.d]# cat epel.repo

[epel]

name=CentOS-$releasever - epel

baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/6/x86_64/

#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os

gpgcheck=0

3、安裝ansible

[root@ansible-server ~]# yum install ansible

4、ansible安裝後測試

測試機器作為被控制端為SUSE11的虛擬機器

檢視組態檔

[root@ansible-server ~]# cd /etc/ansible/

[root@ansible-server ansible]# ls

ansible.cfg  hosts  roles

設定ansible hosts檔案

[root@ansible-server ansible]# vi hosts

[slave]

192.168.1.210  ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=suse

說明:

上面分別是被控制端IP地址、登陸使用者名稱、ssh協定埠以及登陸密碼

PING測試:

[root@ansible-server ansible]# ansible slave -m ping

paramiko: The authenticity of host '192.168.1.210' can't be established.

The ssh-rsa key fingerprint is 3eddc40386a9465452b12910a61a3c65.

Are you sure you want to continue connecting (yes/no)?

yes

192.168.1.210 | SUCCESS => {

    "changed": false,

    "ping": "pong"

第一次登陸還需要手動輸入“yes”新增信任,如果避免這一步的話也可以,需要設定ansible的組態檔ansible.cfg

hosts檔案再新增一台機器

[root@ansible-server ansible]# vi hosts

[slave]

192.168.1.210  ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=suse

192.168.1.211  ansible_ssh_user=root ansible_ssh_port=22 ansible_ssh_pass=suse

修改組態檔,開啟host_key_checking這一行的注釋

[root@ansible-server ansible]# vi ansible.cfg

#host_key_checking = False

host_key_checking = False

測試如下所示

[root@ansible-server ansible]# ansible 192.168.1.211 -m ping

192.168.1.211 | SUCCESS => {

    "changed": false,

    "ping": "pong"

第一次登陸不需要手動輸入

二、安裝tower

1、資源下載

https://www.ansible.com/license

此連結下載免費控制10個機器的授權,需要填寫郵箱等資訊,授權檔案會發到你的郵箱,安裝tower後登陸到web介面新增授權檔案就可以開始你的tower之旅了

https://www.ansible.com/tower-trial

此連結是下載免費測試的tower安裝引導檔案,叫做安裝引導檔案是我自己想出的名字,因為安裝tower是由一大堆的ansible-playbook檔案組合到一塊去取網路資源安裝的

2、解壓縮tower引導檔案

[root@ansible-server ~]# cd /home/ansible/

[root@ansible-server ansible]# ls

ansible-tower-setup-latest.tar.gz

[root@ansible-server ansible]# tar zxf ansible-tower-setup-latest.tar.gz

[root@ansible-server ansible]# cd ansible-tower-setup-3.0.3/

[root@ansible-server ansible-tower-setup-3.0.3]# ls

ansible.cfg  group_vars  inventory  README.md    roles

backup.yml  install.yml  licenses  restore.yml  setup.sh

3、設定安裝tower的yum源

以centos系統預設的yum源替代163的yum源

[root@ansible-server yum.repos.d]# vi CentOS-Base.repo

[base]

name=CentOS-$releasever - Base

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os

#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#released updates

[updates]

name=CentOS-$releasever - Updates

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates

#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

#additional packages that may be useful

[extras]

name=CentOS-$releasever - Extras

mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras

#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/

gpgcheck=1

gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6

epel源不變

4、部署tower

解壓縮軟體包

tar -zxf ansible-tower-setup-latest.tar.gz

設定主機資訊

[root@ansible-server ansible]# cd ansible-tower-setup-3.0.3/

[root@ansible-server ansible-tower-setup-3.0.3]# ll

total 64

-rw-rw-r--.  1 1004 1004  203 Oct 31 21:58 ansible.cfg

-rw-rw-r--.  1 1004 1004  128 Oct 31 21:58 backup.yml

drwxrwxr-x.  2 1004 1004  4096 Oct 31 21:58 group_vars

-rw-rw-r--.  1 1004 1004  4781 Oct 31 21:58 install.yml

-rw-rw-r--.  1 1004 1004  194 Oct 31 21:58 inventory

-rw-r--r--.  1 root root  194 Dec 26 21:24 inventory.bak

drwxrwxr-x.  2 1004 1004 12288 Oct 31 21:58 licenses

-rw-rw-r--.  1 1004 1004  2510 Oct 31 21:58 README.md

-rw-rw-r--.  1 1004 1004  233 Oct 31 21:58 restore.yml

drwxrwxr-x. 18 1004 1004  4096 Oct 31 21:58 roles

-rwxrwxr-x.  1 1004 1004  9461 Oct 31 21:58 setup.sh

[root@ansible-server ansible-tower-setup-3.0.3]# sed -i "s#password=''#password='admin'#g" inventory

[root@ansible-server ansible-tower-setup-3.0.3]# sed -i "s#host=''#host='127.0.0.1'#g" inventory

[root@ansible-server ansible-tower-setup-3.0.3]# sed -i "s#port=''#port='5432'#g" inventory

設定軟體源

[root@ansible-serveransible-tower-setup-3.0.3]# sed -i 's#dl.Fedoraproject.org/pub#mirrors.ustc.edu.cn#g' roles/packages_el/defaults/main.yml

[root@ansible-server ansible-tower-setup-3.0.3]# sed -i 's/#baseurl=/baseurl=/g' roles/packages_el/files/epel-6.repo

[root@ansible-server ansible-tower-setup-3.0.3]# sed -i 's/mirrorlist=/#mirrorlist=/g' roles/packages_el/files/epel-6.repo

[root@ansible-server ansible-tower-setup-3.0.3]# sed -i 's#download.fedoraproject.org/pub#mirrors.ustc.edu.cn#g' roles/packages_el/files/epel-6.repo

[root@ansible-server ansible-tower-setup-3.0.3]# yum -y install centos-release-scl-rh centos-release-scl

[root@ansible-server ansible-tower-setup-3.0.3]# sed -i 's#mirror.centos.org#centos.ustc.edu.cn#g' /etc/yum.repos.d/CentOS-SCLo-scl.repo

[root@ansible-server ansible-tower-setup-3.0.3]# sed -i 's#mirror.centos.org#centos.ustc.edu.cn#g' /etc/yum.repos.d/CentOS-SCLo-scl-rh.repo

[root@ansible-server ansible-tower-setup-3.0.3]# yum -y install supervisor

安裝tower

為了防止出現記憶體過小的報錯,修改preflight的tasks檔案

[root@ansible-server ansible-tower-setup-3.0.3]# vi roles/preflight/tasks/main.yml

修改下面一行

minimum_var_space: 10000000000

把引數修改到盡量小

minimum_var_space: 100000000

default目錄下也是同理

[root@ansible-server ansible-tower-setup-3.0.3]# vi roles/preflight/defaults/main.yml

修改下面一行

minimum_var_space: 10000000000

把引數修改到盡量小

minimum_var_space: 100000000

安裝tower

[root@ansible-server ansible-tower-setup-3.0.3]#./setup.sh

如果出現preflight安裝的錯誤,刪除roles/preflight/tasks/main.yml檔案再嘗試

當然也可能因為網路的原因出現timeout的錯誤,不過沒關係再次嘗試

如果網路沒有問題的話還回出現類似於下面所示的報錯:

TASK [awx_install : Migrate the Tower database schema (may take awhile when upgrading).] ***

提示資料庫連線不上,解決辦法:

啟動postgresql

# service postgresql-9.4 initdb

# service postgresql-9.4 start

# chkconfig postgresql-9.4 on

建立使用者

# su - postgres

-bash-4.1$ psql

psql (8.4.20)

Type "help" for help.

postgres=# password postgres;

Enter new password:

Enter it again:

postgres=# CREATE ROLE awx CREATEDB PASSWORD 'admin' LOGIN;

CREATE ROLE

postgres-# q

[root@ansible-server ~]# sed -i 's#peer#md5#g' /var/lib/pgsql/data/pg_hba.conf

[root@ansible-server ~]# sed -i 's#ident#md5#g' /var/lib/pgsql/data/pg_hba.conf 

[root@ansible-server ~]# service postgresql-9.4 restart

Stopping postgresql service:                              [  OK  ]

Starting postgresql service:                              [  OK  ]

測試awx使用者連線,輸入密碼連線,並建立資料庫

[root@ansible-server pgsql]# psql -U awx -d postgres -h 127.0.0.1

Password for user awx:

psql (8.4.20)

Type "help" for help.

postgres=> create database awx;

CREATE DATABASE

postgres=> q

再次執行安裝過程

[root@ansible-server ansible-tower-setup-3.0.3]# ./setup.sh

最後出現安裝成功的提示說明tower安裝完成

三、匯入licenses

安裝完成後就可以通過https://IP/#來存取你的tower介面了,這裡的IP是安裝tower的伺服器IP

存取如下圖所示:

接下來匯入我們申請的license

提交後就可以進入tower的管理頁面了

下面關於Ansible的文章您也可能喜歡,不妨參考下:

使用Ansible批次管理遠端伺服器  http://www.linuxidc.com/Linux/2015-05/118080.htm

Ansible安裝設定與簡單使用  http://www.linuxidc.com/Linux/2015-07/120399.htm

在 CentOS 7 中安裝並使用自動化工具 Ansible  http://www.linuxidc.com/Linux/2015-10/123801.htm

Ansible和Docker的作用和用法  http://www.linuxidc.com/Linux/2014-11/109783.htm

CentOS 7上搭建Jenkins+Ansible服務  http://www.linuxidc.com/Linux/2016-12/138737.htm

Ansible批次搭建LAMP環境 http://www.linuxidc.com/Linux/2014-10/108264.htm

Ansible :一個設定管理和IT自動化工具  http://www.linuxidc.com/Linux/2014-11/109365.htm

Ansible基礎—安裝與常用模組  http://www.linuxidc.com/Linux/2017-02/140216.htm

自動化運維工具之 Ansible 介紹及安裝使用  http://www.linuxidc.com/Linux/2016-12/138104.htm

Ansible入門notify和handlers  http://www.linuxidc.com/Linux/2017-02/140871.htm


IT145.com E-mail:sddin#qq.com