Skip to content

Commit

Permalink
修复centos系统重启haproxy启动失败问题
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgao1983 committed Dec 15, 2017
1 parent 59d8ac5 commit 3213312
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
7 changes: 4 additions & 3 deletions roles/lb/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
- name: 创建haproxy配置目录
file: name=/etc/haproxy state=directory

- name: 创建haproxy工作目录
file: name=/run/haproxy state=directory owner=haproxy group=haproxy
- name: 修改centos的haproxy.service
template: src=haproxy.service.j2 dest=/usr/lib/systemd/system/haproxy.service
when: ansible_distribution == "CentOS" and ansible_distribution_major_version == "7"

- name: 配置 haproxy
template: src=haproxy.cfg.j2 dest=/etc/haproxy/haproxy.cfg
Expand Down Expand Up @@ -48,7 +49,7 @@
when: LB_ROLE == "backup"

- name: 重启haproxy服务
shell: systemctl enable haproxy && systemctl restart haproxy
shell: systemctl enable haproxy && systemctl daemon-reload && systemctl restart haproxy

- name: 重启keepalived服务
shell: systemctl enable keepalived && systemctl restart keepalived
13 changes: 13 additions & 0 deletions roles/lb/templates/haproxy.service.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[Unit]
Description=HAProxy Load Balancer
After=syslog.target network.target

[Service]
EnvironmentFile=/etc/sysconfig/haproxy
ExecStartPre=/usr/bin/mkdir /run/haproxy
ExecStart=/usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid $OPTIONS
ExecReload=/bin/kill -USR2 $MAINPID
KillMode=mixed

[Install]
WantedBy=multi-user.target
1 change: 1 addition & 0 deletions roles/prepare/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@
- name: 关闭 selinux
shell: "setenforce 0 && echo SELINUX=disabled > /etc/selinux/config"
when: ansible_distribution == "CentOS"
ignore_errors: true

0 comments on commit 3213312

Please sign in to comment.