在Debian 10上安装Apache Tomcat 9,带有Ansible

时间:2020-02-23 14:32:56  来源:igfitidea点击:

Apache Tomcat是一个免费和开源的HTTP服务器,旨在为Java网页提供服务。
Tomcat是Java Servlet,JavaServer Pages,Java表达式语言和Java WebSocket技术的实现。
它被广泛部署并为世界各地的各种关键任务Web应用程序提供支持。
本教程将讨论如何在Debian 10 Linux上轻松安装Tomcat,使用Ansible。

第1步:安装Ansible

对工作站的主要依赖性是Ansible。
使用下面共享的命令在Linux系统上安装Ansible。

###### CentOS  ######
sudo yum -y install epel-release && sudo yum -y install ansible
###### Fedora  ######
sudo dnf -y install ansible
###### Ubuntu/Linux Mint ######
sudo apt-get install -y  software-properties-common
sudo apt-add-repository --yes --update ppa:ansible/ansible
sudo apt-get update
sudo apt-get install -y ansible
###### Debian ######
sudo apt-get install -y software-properties-common
echo "deb http://ppa.launchpad.net/ansible/ansible/ubuntu trusty main" | sudo tee /etc/apt/sources.list.d/ansible.list
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 93C4A3FD7BB9C367
sudo apt update
sudo apt install ansible
###### Arch/Manjaro ######
$sudo pacman -S ansible
###### macOS ######
sudo easy_install pip
sudo pip install ansible

确认Ansible安装:

$ansible --version 
ansible 2.9.2
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/debian/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python2.7/dist-packages/ansible
  executable location = /usr/bin/ansible
  python version = 2.7.16 (default, Apr  6 2019, 01:42:57) [GCC 8.3.0]

第2步:克隆Github的ansible角色

Tomcat Ansible在GitHub上公开提供使用。
将其克隆到工作站上。

cd /tmp/
git clone https://github.com/jmutai/tomcat-ansible.git
cd tomcat-ansible

更新库存,例如:

$vim hosts
[tomcat-nodes]
192.168.20.55 # Add Server IP address, one line per server

PlayBook文件中的更新变量 - 设置Tomcat版本,远程用户和Tomcat UI访问凭据

$vim tomcat-setup.yml
- name: Tomcat deployment playbook
  hosts: tomcat-nodes       # Inventory hosts group/server to act on
  become: yes               # If to escalate privilege
  become_method: sudo       # Set become method
  remote_user: root         # Update username for remote server
  vars:
    tomcat_ver: 9.0.30                          # Tomcat version to install
    ui_manager_user: manager                    # User who can access the UI manager section only
    ui_manager_pass: Hyman@theitroad      # UI manager user password
    ui_admin_username: admin                    # User who can access bpth manager and admin UI sections
    ui_admin_pass: Hyman@theitroad          # UI admin password
  roles:
    - tomcat

使用非Root远程用户时,必须成为必要的变成_method。

become: yes
become_method: sudo

第3步:使用Ansible在Debian 10上安装Apache Tomcat 9

更新所有值后,我们可以将PlayBook运行在节点上。

播放簿作为root用户执行 - 使用ssh键:

$ansible-playbook -i hosts tomcat-setup.yml

PlayBook作为root用户执行 - 密码:

$ansible-playbook -i hosts tomcat-setup.yml --ask-pass

Playbook作为sudo用户执行 - 密码:

$ansible-playbook -i hosts tomcat-setup.yml --ask-pass --ask-become-pass

PlayBook作为Sudo用户执行 - 使用SSH密钥和sudo密码:

$ansible-playbook -i hosts tomcat-setup.yml --ask-become-pass

PlayBook作为Sudo用户执行 - SSH密钥和无密码sudo:

$ansible-playbook -i hosts tomcat-setup.yml --ask-become-pass

成功的安装输出将显示与下面类似的输出。

PLAY [Tomcat deployment playbook] ** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ****
TASK [Gathering Facts] ** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ***
ok: [deb01]
TASK [tomcat : Add the OS specific variables] ** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ****
ok: [deb01] => (item=/tmp/tomcat-ansible/roles/tomcat/vars/Debian.yml)
TASK [tomcat : include_tasks] ** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ****
included: /tmp/tomcat-ansible/roles/tomcat/tasks/tomcat-setup-Debian.yml for deb01
TASK [tomcat : Ensure the system can use the HTTPS transport for APT.] ** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ***
ok: [deb01]
TASK [tomcat : Install APT HTTPS transport.] ** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** *****
skipping: [deb01]
TASK [tomcat : Install basic packages] ** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ***
[WARNING]: Updating cache and auto-installing missing dependency: python-apt
changed: [deb01]
TASK [tomcat : Install Default Java (Debian/Ubuntu)] ** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** *****
changed: [deb01]
TASK [tomcat : Add tomcat group] ** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** *****
changed: [deb01]
TASK [tomcat : Add "tomcat" user] ** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ****
changed: [deb01]
TASK [tomcat : Download Tomcat] ** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **
changed: [deb01]
TASK [tomcat : Create a tomcat directory] ** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ****
changed: [deb01]
TASK [tomcat : Extract tomcat archive] ** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ***
changed: [deb01]
TASK [tomcat : Copy tomcat service file] ** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** *****
changed: [deb01]
TASK [tomcat : Start and enable tomcat] ** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **
changed: [deb01]
PLAY RECAP ** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** **** ***
deb01                      : ok=13   changed=9    unreachable=0    failed=0    skipped=1    rescued=0    ignored=0

第4步:在Debian上测试Tomcat安装

访问端口8080上的服务器URL。
以测试Tomcat安装和配置。

Tomcat Web应用程序管理器仪表板: http://<domain_or_IP_address>:8080/manager/htmlTomcat Virtual Host Manager仪表板: http://<domain_or_IP_address>:8080/host-manager/html我们还可以通过单击UI按钮访问Web Application Manager和主机管理器:

访问两个部分时需要身份验证。