在 AWS 中通过 Ansible 部署时如何设置 Apache 2.4 环境?

在 AWS 中通过 Ansible 部署时如何设置 Apache 2.4 环境?

使用下面的剧本,我发现 /etc/apache2/envvars 设置不正确。我发现 Apache 2.4 将通过 apache2ctl 模块启动,并尝试使用它来启动服务。启动 EC2 实例后,我发现 Apache2.4 服务由于错误而未运行。一切都由这个剧本完成:

--- # Build Web Server
- name: Install Apache
hosts: localhost
become: yes
connection: local
gather_facts: yes
tasks:

- name: Add Repository for PHP 5.6
  apt_repository:
    repo: ppa:ondrej/php
    state: present

- name: Install Web Server Package
  apt:
    pkg: "{{ item }}"
    state: present
    update_cache: yes
  with_items:
  - "apache2"
  - "php5.6"
  - "php5.6-mbstring"
  - "php5.6-mcrypt"
  - "php5.6-mysql"
  - "php5.6-xml"
  - "php5.6-cli"
  - "libapache2-mod-php5.6"

- name: enable modules
  command: "a2enmod {{item}}"
  with_items:
  - rewrite
  - ssl


- name: Update Apache Config
  copy:
    src: /data/000-default.conf
    dest: /etc/apache2/sites-available
    owner: root
    group: root
    mode: 0644

- name: Enable Default website
  command: "a2ensite 000-default.conf"

- name: Update PHP CLI php.ini
  lineinfile:
    dest: /etc/php/5.6/cli/php.ini
    state: present
    insertbefore: EOF
    regexp: '^error_reporting'
    line: 'error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING & ~E_STRICT & ~E_DEPRECATED'

  notify:
    - StartHttpd
  tags:
  - installapache
  handlers:
  - name: StartHttpd
    command: "apache2ctl restart"

运行上述剧本后......

ubuntu@ip-10-250-0-62:~$ sudo apache2 -S
[Thu Jun 01 20:53:02.524073 2017] [core:warn] [pid 29832] AH00111: Config 
variable ${APACHE_LOCK_DIR} is not defined
[Thu Jun 01 20:53:02.524158 2017] [core:warn] [pid 29832] AH00111: Config 
variable ${APACHE_PID_FILE} is not defined
[Thu Jun 01 20:53:02.524231 2017] [core:warn] [pid 29832] AH00111: Config 
variable ${APACHE_RUN_USER} is not defined
[Thu Jun 01 20:53:02.524272 2017] [core:warn] [pid 29832] AH00111: Config 
variable ${APACHE_RUN_GROUP} is not defined
[Thu Jun 01 20:53:02.524311 2017] [core:warn] [pid 29832] AH00111: Config 
variable ${APACHE_LOG_DIR} is not defined
[Thu Jun 01 20:53:02.532379 2017] [core:warn] [pid 29832] AH00111: Config 
variable ${APACHE_RUN_DIR} is not defined
[Thu Jun 01 20:53:02.532637 2017] [core:warn] [pid 29832] AH00111: Config 
variable ${APACHE_LOG_DIR} is not defined
[Thu Jun 01 20:53:02.532830 2017] [core:warn] [pid 29832] AH00111: Config 
variable ${APACHE_LOG_DIR} is not defined
[Thu Jun 01 20:53:02.532886 2017] [core:warn] [pid 29832] AH00111: Config 
variable ${APACHE_LOG_DIR} is not defined
AH00526: Syntax error on line 74 of /etc/apache2/apache2.conf:
Invalid Mutex directory in argument file:${APACHE_LOCK_DIR}

ubuntu@ip-10-250-0-62:~$ sudo apache2ctl restart

ubuntu@ip-10-250-0-62:~$ sudo apache2 -S
[Thu Jun 01 20:53:14.440314 2017] [core:warn] [pid 29844] AH00111: Config 
variable ${APACHE_LOCK_DIR} is not defined
[Thu Jun 01 20:53:14.440398 2017] [core:warn] [pid 29844] AH00111: Config 
variable ${APACHE_PID_FILE} is not defined
[Thu Jun 01 20:53:14.440476 2017] [core:warn] [pid 29844] AH00111: Config 
variable ${APACHE_RUN_USER} is not defined
[Thu Jun 01 20:53:14.440519 2017] [core:warn] [pid 29844] AH00111: Config 
variable ${APACHE_RUN_GROUP} is not defined
[Thu Jun 01 20:53:14.440568 2017] [core:warn] [pid 29844] AH00111: Config 
variable ${APACHE_LOG_DIR} is not defined
[Thu Jun 01 20:53:14.448516 2017] [core:warn] [pid 29844] AH00111: Config 
variable ${APACHE_RUN_DIR} is not defined
[Thu Jun 01 20:53:14.448807 2017] [core:warn] [pid 29844] AH00111: Config 
variable ${APACHE_LOG_DIR} is not defined
[Thu Jun 01 20:53:14.448979 2017] [core:warn] [pid 29844] AH00111: Config 
variable ${APACHE_LOG_DIR} is not defined
[Thu Jun 01 20:53:14.449035 2017] [core:warn] [pid 29844] AH00111: Config 
variable ${APACHE_LOG_DIR} is not defined
AH00526: Syntax error on line 74 of /etc/apache2/apache2.conf:
Invalid Mutex directory in argument file:${APACHE_LOCK_DIR}

ubuntu@ip-10-250-0-62:~$ sudo su -

root@ip-10-250-0-62:~# . /etc/apache2/envvars

root@ip-10-250-0-62:/root# apache2ctl restart

root@ip-10-250-0-62:/root# apache2 -S
VirtualHost configuration: *:80 ip-10-250-0-62.us-west-2.compute.internal (/etc/apache2/sites-enabled/000-default.conf:1)
ServerRoot: "/etc/apache2"
Main DocumentRoot: "/var/www/html"
Main ErrorLog: "/var/log/apache2/error.log"
Mutex rewrite-map: using_defaults
Mutex ssl-stapling-refresh: using_defaults
Mutex ssl-stapling: using_defaults
Mutex ssl-cache: using_defaults
Mutex default: dir="/var/lock/apache2" mechanism=fcntl
Mutex mpm-accept: using_defaults
Mutex watchdog-callback: using_defaults
PidFile: "/var/run/apache2/apache2.pid"
Define: DUMP_VHOSTS
Define: DUMP_RUN_CFG
User: name="www-data" id=33
Group: name="www-data" id=33

答案1

使用service: name=apachename可能因发行版而异)。apache2ctl抱怨环境变量未设置。这些参数可能是在启动期间使用 init 管理器(通过模块调用service)设置的。

相关内容