Ansible部署LAMP

Ansible部署LAMP

  • 准备环境
    • 配置阿里yum源
    • 安装Ansible
  • 更改控制主机名
  • 配置域名
  • 设置免密登录
  • 部署LAMP
      • ansible.cfg 由来
      • inventory 由来
      • 关闭防火墙
      • 关闭SElinux
      • files内容
      • vars目录
      • 安装httpd的playbook
      • 安装MySQL的playbook
      • 安装PHP的playbook
      • 主文件内容
  • 运行
  • 域名访问

准备环境

主机 ip 主机名 系统版本
主控机 192.168.229.143 node1 centos8/redhat8
受控机 192.168.229.129 node2 centos8/redhat8

lamp平台软件安装次序:

    httpd --> mysql --> php

注意:php要求httpd使用prefork MPM

配置阿里yum源

#配置阿里yum源
# 这是在主控机
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
[root@localhost yum.repos.d]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
#清除缓存
[root@localhost yum.repos.d]# dnf clean all
#建立缓存
[root@localhost yum.repos.d]# dnf makecache

安装Ansible

#列出ansible
[root@localhost ~]# dnf list all|grep ansible
....省略N
ansible-pcp.noarch                 2.2.1-1.el8  AppStream 
centos-release-ansible-29.noarch   1-2.el8      extras #需要这个安装Ansible源
....省略N

#安装ansible源
[root@localhost ~]# dnf -y install centos-release-ansible-29
#清除缓存
[root@localhost ~]# dnf clean all
#建立缓存
[root@localhost ~]# dnf makecache

# 安装ansible
[root@localhost ~]# dnf -y install ansible

#查看版本号
[root@localhost ~]# ansible --version 
ansible 2.9.27
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3.6/site-packages/ansible
  executable location = /usr/bin/ansible
  python version = 3.6.8 (default, Sep  9 2021, 07:49:02) [GCC 8.5.0 20210514 (Red Hat 8.5.0-3)]
[root@localhost ~]# 

更改控制主机名

# 设置主机名
[root@localhost ~]# hostnamectl set-hostname node1
[root@localhost ~]# bash
[root@node1 ~]#

配置域名

#配置域名
[root@node1 ~]# cat /etc/hosts 
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.229.129 test.example.com # 这个是受控主机ip

设置免密登录

# 设置免密登录
## 生成密钥(将会生成私钥~/.ssh/id_rsa和公钥~/.ssh/id_rsa.pub)
[root@node1 ~]# ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:lGi0P/Q0JK/KwpjB5iVlYnWGmh8bBbSsP03em6+W67o [email protected]
The key's randomart image is:
+---[RSA 3072]----+
|   .+o+ . .      |
|   o.=.o =       |
|  oo=.+ + +      |
| oo=o. + + .     |
|  *..+. S .      |
| o Oo= o .       |
|  + = = ..       |
|     o  oo       |
|      E=*+.      |
+----[SHA256]-----+

# 使用 ssh-copy-id 将公钥复制到远程系统上的正确位置
[root@node1 ~]#  ls .ssh/
id_rsa  id_rsa.pub

# 加上-i 指定公钥
[root@node1 ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub [email protected]
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub"
The authenticity of host 'test.example.com (192.168.229.129)' can't be established.
ECDSA key fingerprint is SHA256:mntQBTppC7e+5Uh8MyZHFW3FuKZzpoS46G0j2C+O8U4.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
[email protected]'s password: 

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh '[email protected]'"
and check to make sure that only the key(s) you wanted were added.

#登录到受管主机并修改主机名
[root@node1 ~]# ssh [email protected]
Last login: Sat Jul  9 18:21:25 2022 from 192.168.229.143
[root@localhost ~]# ip addr show ens160
2: ens160:  mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 00:0c:29:e4:64:76 brd ff:ff:ff:ff:ff:ff
    inet 192.168.229.129/24 brd 192.168.229.255 scope global dynamic noprefixroute ens160
       valid_lft 1047sec preferred_lft 1047sec
    inet6 fe80::20c:29ff:fee4:6476/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

# 修改受控主机、主机名
[root@localhost ~]# hostnamectl set-hostname node2
[root@localhost ~]# bash
[root@node2 ~]#

部署LAMP

# 创建lamp目录
[root@node1 ~]#  ls
anaconda-ks.cfg  lamp    pass
[root@node1 ~]#  cd lamp/
[root@node1 lamp]# ls
ansible.cfg   lamp_apache.yml  lamp_php.yml    off_selinux.yml
files        inventory    lamp_mysql.yml   main.yml      off_firewalld.yml   vars
[root@node1 lamp]#

# ansible.cfg  配置文件
# inventory 清单
# off_selinux.yml # 关闭SElinux
# off_firewalld.yml # 关闭防火墙  
# lamp_apache.yml  # 配置apache
# lamp_mysql.yml  # 配置MySQL
# lamp_php.yml # 配置PHP
#  main.yml  # 主文件
# files # 放文件目录
# vars # 变量

ansible.cfg 由来

[root@node1 ~]# cd lamp/
[root@node1 lamp]# cp /etc/ansible/ansible.cfg . # 复制到当前目录下

inventory 由来

[root@node1 lamp]# vim inventory # 配置清单文件
[webservers]
test.example.com

关闭防火墙

[root@node1 lamp]# cat off_firewalld.yml
- name: stop firewalld
  service:
    name: firewalld
    state: stopped
    enabled: no

关闭SElinux

[root@node1 lamp]# cat off_selinux.yml
- name: stop selinux
  lineinfile:
    path: /etc/selinux/config
    regexp: '^SELINUX='
    line: SELINUX=disabled

files内容

[root@node1 lamp]# ls files/
# apache 部分
apr-1.7.0.tar.gz   # Apr软件包
apr-util-1.6.1.tar.gz  # apr-util软件包
httpd-2.4.53.tar.gz    # httpd软件包
apache.sh.j2  # 安装httpd脚本
httpd.service.j2  # service文件,设置开机自启的  
httpd-vhosts.conf.j2  # 虚拟主机
httpd.conf  # httpd主配置文件   


# MySQL 部分
mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz # MySQL软件            
mysql.sh.j2 # 安装MySQL的脚本
initialize.sh.j2  # 初始化数据库的脚本
mysqld # 开机自启的
my.cnf.j2 # MySQL的配置文件

# PHP 部分
php-7.4.29.tar.xz # PHP软件包
oniguruma-devel-6.8.2-2.el8.x86_64.rpm # PHP依赖包,只能先从pkgs.org网站下载下来               php.sh.j2 # 安装PHP的脚本
php.service  # 设置PHP开机自启的service文件
index.php # PHP网页
[root@node1 lamp]#
 # 安装 apache 脚本模板
[root@node1 files]# cat apache.sh.j2
#!/bin/bash

cd /opt/
tar xf apr-1.7.0.tar.gz # 解压
tar xf apr-util-1.6.1.tar.gz
tar xf httpd-2.4.53.tar.gz
sed -i '/$RM "$cfgfile"/d' apr-1.7.0/configure # 把apr-1.7.0里面的这$RM "$cfgfile一行删除
cd apr-1.7.0
./configure --prefix=/usr/local/apr && \ 
make && make install && \
cd ../apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr  && \
make && make install && \
cd ../httpd-2.4.53      # 脚本里面不识别{{ apache_install_dir }},所以需要改为模板
./configure --prefix={{ apache_install_dir }} \ 
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util/ \
--enable-modules=most \
--enable-mpms-shared=all \
--with-mpm=prefork && \
make && make install && \
echo 'export PATH={{ apache_install_dir }}/bin:$PATH' > /etc/profile.d/apache.sh && \
source /etc/profile.d/apache.sh
ln -s {{ apache_install_dir }}/include /usr/include/apache
echo 'MANDATORY_MANPATH      {{ apache_install_dir }}/man' > /etc/man_db.conf
[root@node1 files]#

# apache 的service文件
[root@node1 files]# cat  httpd.service.j2
[Unit]
Description=httpd server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart={{ apache_install_dir }}/bin/apachectl start
ExecStop={{ apache_install_dir }}/bin/apachectl stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@node1 files]#


# 配置虚拟主机的模板
[root@node1 files]# cat httpd-vhosts.conf.j2

    DocumentRoot "{{ apache_install_dir }}/htdocs"
    ServerName {{ domain_name }}
    ErrorLog "logs/{{ domain_name }}-error_log"
    CustomLog "logs/{{ domain_name }}-access_log" common
    ProxyRequests Off
    ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9000{{ apache_install_dir }}/htdocs/$1
    
        Options none
        AllowOverride none
        Require all granted
    


# httpd.conf # MySQL的主配置文件
# 复制到当前目录下
[root@node1 files]# scp test.example.com:/usr/local/apache/conf/httpd.conf .
# 进入apache主配置文件修改数据
[root@node1 files]# vim httpd.conf

# 搜索index.html,添加以下内容    

    DirectoryIndex index.php  index.html  # 添加 index.php


# 进入apache主配置文件,打开include让其包含虚拟主机
Include conf/extra/httpd-vhosts.conf 

    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType application/x-httpd-php .php     #添加此行
    AddType application/x-httpd-php-source .phps     #添加此行

LoadModule proxy_module modules/mod_proxy.so # 把注释取消
#LoadModule proxy_connect_module modules/mod_proxy_connect.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so # 把注释取消

# MySQL脚本模板
[root@node1 files]# cat mysql.sh.j2
#!/bin/bash

cd /opt/
tar xf mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz # 解压
mv mysql-5.7.37-linux-glibc2.12-x86_64 {{ mysql_install_dir }}
cd /usr/local
chown -R mysql.mysql mysql
echo 'export PATH={{ mysql_install_dir }}/bin:$PATH' > /etc/profile.d/mysql.sh && \
source /etc/profile.d/mysql.sh
ln -s {{ mysql_install_dir }}/include /usr/include/mysql
echo '{{ mysql_install_dir }}/lib' /etc/ld.so.conf.d/mysql.conf
echo 'MANDATORY_MANPATH   {{ mysql_install_dir }}/man' > /etc/man_db.conf
mkdir /opt/data
chown -R mysql.mysql /opt/data
[root@node1 files]#


# 初始化数据库的模板
[root@node1 files]# cat initialize.sh.j2
#!/bin/bash

{{ mysql_install_dir }}/bin/mysqld --initialize --user=mysql --datadir=/opt/data/ | tee /opt/pass

# MySQL 配置文件
[root@node1 files]# cat my.cnf.j2
[mysqld]
basedir = {{ mysql_install_dir }}
datadir = /opt/data
socket = /tmp/mysql.sock
port = 3306
pid-file = /opt/data/mysql.pid
user = mysql
skip-name-resolve
sql-mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
[root@node1 files]#

# MySQLd 由来
# 目的为了能够设置MySQL开机自启
[root@node1 files]# scp test.example.com:/usr/local/mysql/support-files/mysql.service mysqld

# 进去mysqld 修改添加两行数据库
[root@node1 files]# vim mysqld
# If you change base dir, you must also change datadir. These may get
# overwritten by settings in the MySQL configuration files.

basedir=/usr/local/mysql # 添加路径 /usr/local/mysql 
datadir=/opt/data # 添加放数据的/opt/data 


# MySQL的service文件模板
[root@node1 files]# cat mysqld.service.j2
[Unit]
Description=mysql server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart={{ mysql_install_dir }}/support-files/mysqld start
ExecStop={{ mysql_install_dir }}/support-files/mysqld stop
ExecReload=/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target
[root@node1 files]#
# oniguruma-devel-6.8.2-2.el8.x86_64.rpm # PHP依赖包

# 安装PHP 脚本模板
[root@node1 files]# cat php.sh.j2
#!/bin/bash

cd /opt/
dnf -y install oniguruma-devel-6.8.2-2.el8.x86_64.rpm && \
tar xf php-7.4.29.tar.xz
cd php-7.4.29
./configure --prefix={{ php_install_dir }}  \
--with-config-file-path=/etc \
--enable-fpm \
--enable-inline-optimization \
--disable-debug \
--disable-rpath \
--enable-shared \
--enable-soap \
--with-openssl \
--enable-bcmath \
--with-iconv \
--with-bz2 \
--enable-calendar \
--with-curl \
--enable-exif  \
--enable-ftp \
--enable-gd \
--with-jpeg \
--with-zlib-dir \
--with-freetype \
--with-gettext \
--enable-json \
--enable-mbstring \
--enable-pdo \
--with-mysqli=mysqlnd \
--with-pdo-mysql=mysqlnd \
--with-readline \
--enable-shmop \
--enable-simplexml \
--enable-sockets \
--with-zip \
--enable-mysqlnd-compression-support \
--with-pear \
--enable-pcntl \
--enable-posix && \
make && make install && \
echo 'export PATH={{ php_install_dir }}/bin:$PATH' > /etc/profile.d/php7.sh && \
source /etc/profile.d/php7.sh
ln -s {{ php_install_dir }}/include /usr/include/php7
echo '{{ php_install_dir }}/lib' > /etc/ld.so.conf.d/php7.conf && \
ldconfig && \
cd /usr/local/php-7.4.29
\cp php.ini-production /etc/php.ini
cp sapi/fpm/init.d.php-fpm /etc/init.d/php-fpm
chmod +x /etc/init.d/php-fpm
cd {{ php_install_dir }}/etc
cp php-fpm.conf.default php-fpm.conf
cd  php-fpm.d
cp www.conf.default www.conf
[root@node1 files]#


# PHP的service文件
[root@node1 files]# cat php.service
[Unit]
Description=php-fpm server daemon
After=network.target sshd-keygen.target

[Service]
Type=forking
ExecStart=/etc/init.d/php-fpm start
ExecStop=/usr/bin/kill -9 $MAINPID
ExecReload=/usr/bin/kill -HUP $MAINPID

[Install]
WantedBy=multi-user.target



# PHP 网页
[root@node1 files]# cat index.php

vars目录

[root@node1 lamp]# ls vars/
lamp.yml
[root@node1 lamp]# cat vars/lamp.yml
apache_depend_pkg:
  - openssl
  - openssl-devel
  - pcre-devel
  - expat-devel
  - gcc
  - gcc-c++
  - make
apache_soft_pkg:
  - apr-1.7.0.tar.gz
  - apr-util-1.6.1.tar.gz
  - httpd-2.4.53.tar.gz
apache_install_dir: /usr/local/apache

mysql_depend_pkg:
  - ncurses-compat-libs
  - openssl-devel
  - openssl
  - cmake
  - mariadb-devel

mysql_install_dir: /usr/local/mysql

php_depend_pkg:
  - libxml2-devel
  - openssl
  - openssl-devel
  - bzip2
  - bzip2-devel
  - libcurl
  - libcurl-devel
  - libicu-devel
  - libjpeg
  - libjpeg-devel
  - libpng
  - libpng-devel
  - openldap-devel
  - pcre-devel
  - freetype
  - freetype-devel
  - gmp
  - gmp-devel
  - libmcrypt
  - libmcrypt-devel
  - readline
  - readline-devel
  - libxslt
  - libxslt-devel
  - sqlite-devel
  - libzip-devel
  - php-mysqlnd
php_soft_pkg:
  - php-7.4.29.tar.xz
  - oniguruma-devel-6.8.2-2.el8.x86_64.rpm
php_install_dir: /usr/local/php7

WEB_PORT: 80

domain_name: test.example.com
[root@localhost lamp]#

安装httpd的playbook

[root@node1 lamp]# cat lamp_apache.yml
- name: create user
  user:
    name: apache
    state: present
    system: yes
    create_home: no
    shell: /sbin/nologin
- name: install pkgs
  yum:
    name: "{{ item }}"
    state: present
  loop: "{{ apache_depend_pkg }}"
- name:
  copy:
    src: "{{ item }}"
    dest: /opt/
  loop: "{{ apache_soft_pkg }}"

- name: test {{ apache_install_dir }} is exists
  command: test -d {{ apache_install_dir }}
  register: apache_result
  ignore_errors: yes
- name: provide script
  template:
    src: files/apache.sh.j2
    dest: /opt/apache.sh
    mode: 0755
- name: exec script
  shell: /opt/apache.sh
  when: apache_result['rc'] != 0
  ignore_errors: yes

- name: provide httpd.service.j2
  template:
    src: files/httpd.service.j2
    dest: /usr/lib/systemd/system/httpd.service
- name: start apache
  service:
    name: httpd
    state: started
    enabled: yes

- name: provide httpd.conf
  copy:
    src: files/httpd.conf
    dest: /usr/local/apache/conf/
  notify:
    - restart httpd
- name: provide httpd-vhosts.conf.j2
  template:
    src: files/httpd-vhosts.conf.j2
    dest: /usr/local/apache/conf/extra/httpd-vhosts.conf
  notify:
    - restart httpd
- name: provide index.php
  copy:
    src: files/index.php
    dest: /usr/local/apache/htdocs
    owner: apache
    group: apache
  notify:
    - restart httpd
[root@node1 lamp]#

安装MySQL的playbook

[root@node1 lamp]# cat lamp_mysql.yml
- name: create user
  user:
    name: mysql
    state: present
    system: yes
    create_home: no
    shell: /sbin/nologin
- name: install depend pkgs
  yum:
    name: "{{ item }}"
    state: present
  loop: "{{ mysql_depend_pkg }}"
- name: provide soft pkg
  copy:
    src: files/mysql-5.7.37-linux-glibc2.12-x86_64.tar.gz
    dest: /opt/

- name: test {{ mysql_install_dir }} is exists
  command: test -d {{ mysql_install_dir }}
  register: mysql_result
  ignore_errors: yes
- name: provide mysql.sh.j2
  template:
    src: files/mysql.sh.j2
    dest: /opt/mysql.sh
    mode: 0755
- name: exec script
  shell: /opt/mysql.sh
  when: mysql_result['rc'] != 0
  ignore_errors: yes

- name: test /opt/pass is exists
  command: test -f /opt/pass
  register: mysql_file
  ignore_errors: yes

- name: provide initialize.sh.j2
  template:
    src: files/initialize.sh.j2
    dest: /opt/initialize.sh
    mode: 0755

- name: initialize mysql
  shell: /opt/initialize.sh
  when: mysql_file['rc'] != 0
  ignore_errors: yes
  register: print_mysql_info
- debug: var=print_mysql_info

- name: provide my.cnf
  template:
    src: files/my.cnf.j2
    dest: /etc/my.cnf

- name: provide mysqld
  copy:
    src: files/mysqld
    dest: "{{ mysql_install_dir }}/support-files/"
    owner: mysql
    group: mysql
    mode: 0755
- name: provide service file
  template:
    src: files/mysqld.service.j2
    dest: /usr/lib/systemd/system/mysqld.service

- name: start mysql
  service:
    name: mysqld
    state: started
    enabled: yes
[root@node1 lamp]#

安装PHP的playbook

[root@node1 lamp]# cat lamp_php.yml
- name: install depend pkgs
 yum:
   name: "{{ item }}"
   state: present
 loop: "{{ php_depend_pkg }}"
- name: provide pkg
 copy:
   src: "{{ item }}"
   dest: /opt/
 loop: "{{ php_soft_pkg }}"
- name: test {{ php_install_dir }} is exists
 command: test -d {{ php_install_dir }}
 register: php_result
 ignore_errors: yes
- name: provide php.sh.j2
 template:
   src: files/php.sh.j2
   dest: /opt/php.sh
   mode: 0755
- name: exec script
 shell: /opt/php.sh
 when: php_result['rc'] != 0
 ignore_errors: yes

- name: provide php.service
 copy:
   src: files/php.service
   dest: /usr/lib/systemd/system
- name: start php
 service:
   name: php
   state: started
   enabled: yes
[root@node1 lamp]#

主文件内容

[root@node1 lamp]# cat main.yml
---
- hosts: webservers
  vars_files:
    - vars/lamp.yml
  tasks:
    - include_tasks: off_firewalld.yml
    - include_tasks: off_selinux.yml
    - include_tasks: lamp_apache.yml
    - include_tasks: lamp_mysql.yml
    - include_tasks: lamp_php.yml
  handlers:
    - name: restart httpd
      service:
        name: httpd
        state: restarted

在母机当中做映射
Ansible部署LAMP_第1张图片

运行

[root@node1 lamp]# ansible-playbook main.yml

PLAY [webservers] ***************************************************************************************************

TASK [Gathering Facts] **********************************************************************************************
ok: [web.example.com]

TASK [include_tasks] ************************************************************************************************
included: /root/lamp/off_firewalld.yml for web.example.com

TASK [stop firewalld] ***********************************************************************************************
ok: [web.example.com]

TASK [include_tasks] ************************************************************************************************
included: /root/lamp/off_selinux.yml for web.example.com

TASK [stop selinux] *************************************************************************************************
ok: [web.example.com]

TASK [include_tasks] ************************************************************************************************
included: /root/lamp/lamp_apache.yml for web.example.com

TASK [create user] **************************************************************************************************
ok: [web.example.com]

TASK [install pkgs] *************************************************************************************************
ok: [web.example.com] => (item=openssl)
ok: [web.example.com] => (item=openssl-devel)
ok: [web.example.com] => (item=pcre-devel)
ok: [web.example.com] => (item=expat-devel)
ok: [web.example.com] => (item=gcc)
ok: [web.example.com] => (item=gcc-c++)
ok: [web.example.com] => (item=make)

TASK [copy] *********************************************************************************************************
ok: [web.example.com] => (item=apr-1.7.0.tar.gz)
ok: [web.example.com] => (item=apr-util-1.6.1.tar.gz)
ok: [web.example.com] => (item=httpd-2.4.53.tar.gz)

TASK [test /usr/local/apache is exists] *****************************************************************************
changed: [web.example.com]

TASK [provide script] ***********************************************************************************************
ok: [web.example.com]

TASK [exec script] **************************************************************************************************
skipping: [web.example.com]

TASK [provide httpd.service.j2] *************************************************************************************
ok: [web.example.com]

TASK [start apache] *************************************************************************************************
ok: [web.example.com]

TASK [provide httpd.conf] *******************************************************************************************
ok: [web.example.com]

TASK [provide httpd-vhosts.conf.j2] *********************************************************************************
ok: [web.example.com]

TASK [provide index.php] ********************************************************************************************
ok: [web.example.com]

TASK [include_tasks] ************************************************************************************************
included: /root/lamp/lamp_mysql.yml for web.example.com

TASK [create user] **************************************************************************************************
ok: [web.example.com]

TASK [install depend pkgs] ******************************************************************************************
ok: [web.example.com] => (item=ncurses-compat-libs)
ok: [web.example.com] => (item=openssl-devel)
ok: [web.example.com] => (item=openssl)
ok: [web.example.com] => (item=cmake)
ok: [web.example.com] => (item=mariadb-devel)

TASK [provide soft pkg] *********************************************************************************************
ok: [web.example.com]

TASK [test /usr/local/mysql is exists] ******************************************************************************
changed: [web.example.com]

TASK [provide mysql.sh.j2] ******************************************************************************************
ok: [web.example.com]

TASK [exec script] **************************************************************************************************
skipping: [web.example.com]

TASK [test /opt/pass is exists] *************************************************************************************
changed: [web.example.com]

TASK [provide initialize.sh.j2] *************************************************************************************
ok: [web.example.com]

TASK [initialize mysql] *********************************************************************************************
skipping: [web.example.com]

TASK [debug] ********************************************************************************************************
ok: [web.example.com] => {
    "print_mysql_info": {
        "changed": false,
        "skip_reason": "Conditional result was False",
        "skipped": true
    }
}

TASK [provide my.cnf] ***********************************************************************************************
ok: [web.example.com]

TASK [provide mysqld] ***********************************************************************************************
ok: [web.example.com]

TASK [provide service file] *****************************************************************************************
ok: [web.example.com]

TASK [start mysql] **************************************************************************************************
ok: [web.example.com]

TASK [include_tasks] ************************************************************************************************
included: /root/lamp/lamp_php.yml for web.example.com

TASK [install depend pkgs] ******************************************************************************************
ok: [web.example.com] => (item=libxml2-devel)
ok: [web.example.com] => (item=openssl)
ok: [web.example.com] => (item=openssl-devel)
ok: [web.example.com] => (item=bzip2)
ok: [web.example.com] => (item=bzip2-devel)
ok: [web.example.com] => (item=libcurl)
ok: [web.example.com] => (item=libcurl-devel)
ok: [web.example.com] => (item=libicu-devel)
ok: [web.example.com] => (item=libjpeg)
ok: [web.example.com] => (item=libjpeg-devel)
ok: [web.example.com] => (item=libpng)
ok: [web.example.com] => (item=libpng-devel)
ok: [web.example.com] => (item=openldap-devel)
ok: [web.example.com] => (item=pcre-devel)
ok: [web.example.com] => (item=freetype)
ok: [web.example.com] => (item=freetype-devel)
ok: [web.example.com] => (item=gmp)
ok: [web.example.com] => (item=gmp-devel)
ok: [web.example.com] => (item=libmcrypt)
ok: [web.example.com] => (item=libmcrypt-devel)
ok: [web.example.com] => (item=readline)
ok: [web.example.com] => (item=readline-devel)
ok: [web.example.com] => (item=libxslt)
ok: [web.example.com] => (item=libxslt-devel)
ok: [web.example.com] => (item=sqlite-devel)
ok: [web.example.com] => (item=libzip-devel)
ok: [web.example.com] => (item=php-mysqlnd)

TASK [provide pkg] **************************************************************************************************
ok: [web.example.com] => (item=php-7.4.29.tar.xz)
ok: [web.example.com] => (item=oniguruma-devel-6.8.2-2.el8.x86_64.rpm)

TASK [test /usr/local/php7 is exists] *******************************************************************************
changed: [web.example.com]

TASK [provide php.sh.j2] ********************************************************************************************
ok: [web.example.com]

TASK [exec script] **************************************************************************************************
skipping: [web.example.com]

TASK [provide php.service] ******************************************************************************************
ok: [web.example.com]

TASK [start php] ****************************************************************************************************
ok: [web.example.com]

PLAY RECAP **********************************************************************************************************
web.example.com            : ok=36   changed=4    unreachable=0    failed=0    skipped=4    rescued=0    ignored=0

域名访问

test.example.com

Ansible部署LAMP_第2张图片
Ansible部署LAMP_第3张图片

你可能感兴趣的:(linux,服务器,运维)