繁体   English   中英

Ansible 当 php 安装在网络服务器上时,Haproxy 不工作(错误 503 服务不可用)

[英]Ansible Haproxy not working when php installed on webserver (error 503 Service Unavailable)

所以我已经坚持了几个小时了,我似乎无法弄清楚这一点。

网络服务器任务文件

---
- name: (APACHE) Install Apache Web server and PHP
  package:
    name: "{{ item }}"
    state: latest
  with_items:
    - apache2
    - ufw
    - php # Removing this package will make it work.
- name: (APACHE) Remove the default Websites
  file:
    path: /etc/apache2/sites-enabled/000-default.conf
    state: absent
  notify: reload apache

- name: (APACHE) DEBUG - Allow RSYNC for new super user without SUDO password
  lineinfile:
    path: /etc/sudoers
    state: present
    insertafter: '^%sudo'
    line: "{{ ansible_user }} ALL=NOPASSWD: /usr/bin/rsync"
  changed_when: false

- name: (APACHE) Copy some template for Web servers
  synchronize:
    src: files/apache_templates/
    dest: /root/
    links: yes
    recursive: yes

- name: (APACHE) DEBUG - Disallow RSYNC for new super user without SUDO password
  lineinfile:
    path: /etc/sudoers
    state: absent
    insertafter: '^%sudo'
    line: "{{ ansible_user }} ALL=NOPASSWD: /usr/bin/rsync"
  changed_when: false

- name: (APACHE) Copy the Diffie-Hellmann parameters
  copy:
    src: dhparams.pem
    dest: /etc/ssl/dhparams.pem
    owner: root
    group: root
    mode: 0644

- name: (APACHE) Check enabled modules
  stat:
    path: /etc/apache2/mods-enabled/{{ item }}
  with_items:
    - ssl.load
    - actions.load
    - proxy_fcgi.load
    - env.load
    - rewrite.load
    - headers.load
  register: modules

- name: (APACHE) Enable missing modules
  command: a2enmod {{ item.item }}
  with_items: "{{ modules.results }}"
  notify: restart apache
  when: not item.stat.exists

- name: (APACHE) Open the HTTP port on the firewall
  ufw:
    rule: allow
    port: 80
    proto: tcp
    direction: in
  notify: reload ufw

- name: (APACHE) Open the HTTPS port on the firewall
  ufw:
    rule: allow
    port: 443
    proto: tcp
    direction: in
  notify: reload ufw

- name: (USERSKEL) DEBUG - Allow RSYNC for new super user without SUDO password
  lineinfile:
    path: /etc/sudoers
    state: present
    insertafter: '^%sudo'
    line: "{{ ansible_user }} ALL=NOPASSWD: /usr/bin/rsync"
  changed_when: false

- name: (USERSKEL) Copy the user's skeleton template for Web servers
  synchronize:
    src: files/user_skel/
    dest: /etc/skel/
    links: yes
    recursive: yes

- name: (USERSKEL) DEBUG - Disallow RSYNC for new super user without SUDO password
  lineinfile:
    path: /etc/sudoers
    state: absent
    insertafter: '^%sudo'
    line: "{{ ansible_user }} ALL=NOPASSWD: /usr/bin/rsync"
  changed_when: false

- name: Delete default page
  file:
    path: /var/www/html/index.html
    state: absent

- name: Delete html directory
  when: apache_use_repo is defined
  file:
    path: /var/www/html
    state: absent

- name: Copy index.php
  template:
    src: index.php.j2
    dest: /var/www/html/index.php

卸下 PHP package 将使其工作。

任务文件 Haproxy

---
- name: Ensure HAProxy is installed.
  package: name=haproxy state=present

- name: Ensure HAProxy is enabled 
  lineinfile:
    dest: /etc/default/haproxy
    regexp: "^ENABLED.+$"
    line: "ENABLED=1"
    state: present


- name: Get HAProxy version.
  command: haproxy -v
  register: haproxy_version_result
  changed_when: false
  check_mode: false

- name: Set HAProxy version.
  set_fact:
    haproxy_version: "{{ '1.5' if '1.5.' in haproxy_version_result.stdout else '1.4' }}"

- name: Copy HAProxy configuration in place.
  template:
    src: haproxy.cfg.j2
    dest: /etc/haproxy/haproxy.cfg
    mode: 0644
    validate: haproxy -f %s -c -q
  notify: restart haproxy

- name: Ensure HAProxy is started and enabled on boot.
  service: name=haproxy state=started enabled=yes

和默认文件

---
haproxy_socket: /var/lib/haproxy/stats
haproxy_chroot: /var/lib/haproxy
haproxy_user: haproxy
haproxy_group: haproxy

# Frontend settings.
haproxy_frontend_name: 'hafrontend'
haproxy_frontend_bind_address: '*'
haproxy_frontend_port: 80
haproxy_frontend_mode: 'http'

# Backend settings.
haproxy_backend_name: 'habackend'
haproxy_backend_mode: 'http'
haproxy_backend_balance_method: 'roundrobin'
haproxy_backend_httpchk: 'HEAD / HTTP/1.1\r\nHost:localhost'

# List of backend servers.
haproxy_backend_servers: 
 - name: app1
   address: 10.0.10.21:80
 - name: app2
   address: 10.0.10.22:80

# Extra global vars (see README for example usage).
haproxy_global_vars: []

它可以在没有 PhP 标记的情况下工作,但它只会重定向到第一个服务器,而不会重定向到第二个服务器。 有人知道如何解决这个问题吗?

它给出的错误是 503 Service Unavailable No server is available to handle this request。

不确定是否有人遇到过这个问题,但这是我的 HAproxy.cfg.js2 文件中的一个错误。 我已经重演了整个角色并且它奏效了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM