ansible管理部署高可用環(huán)境下的LAMP環(huán)境

一、前言

嘗試通過ansible 來在centos 7系統(tǒng)環(huán)境下部署實現(xiàn)nginx+keepalived+LAMP環(huán)境,以加深對ansible的理解。部署拓撲如下:


部署拓撲圖

兩臺nginx作為web代理服務器,配置實現(xiàn)keepalived做主備;后端兩個apache服務器,一個部署apache+php,另一個部署apache+mysql。通過ansible管理配置以上服務器,配置完成后,能通過VIP訪問到后端主機主頁。

二、環(huán)境準備

因為控制終端的程序包什么的都可以通過ansible主機來管理安裝配置,因此這里的我們只需要在ansible主機上安裝ansible服務,并將相應的遠程主機添加管理即可。

1、安裝ansible服務

在ansible主機上安裝ansible服務:

[root@ansible ~]# yum install -y ansible

2、添加管理遠程主機

編輯/etc/ansible/hosts:

[nginx]
192.168.0.87
192.168.0.89
[apache]
192.168.0.83
192.168.0.84
[php]
192.168.0.83
[mysql]
192.168.0.84

編輯/etc/hosts,添加相應的主機名解析:

[root@ansible ~]# vim /etc/hosts
192.168.0.83 ap1.ilinux.io ap1
192.168.0.84 ap2.ilinux.io ap2
192.168.0.87 nginx1.ilinux.io nginx1
192.168.0.89 nginx2.ilinux.io nginx2

3、配置使用ssh免密鑰認證管理遠程主機

首先在ansible主機上創(chuàng)建相應的密鑰文件:

[root@ansible ~]# ssh-keygen -t rsa -N ''
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa): 
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:
fc:af:d8:8f:41:dd:d2:00:2a:d2:07:e7:68:b1:c7:d3 root@ansible
The key's randomart image is:
+--[ RSA 2048]----+
|      o . .      |
|     . O o .     |
|    . * B E .    |
|     o = . . +   |
|        S . o o  |
|         o   .   |
|          o      |
|         o +     |
|        . +oo    |
+-----------------+

然后將生成的公鑰文件送往遠程主機:

[root@ansible ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.83
[root@ansible ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.84
[root@ansible ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.87
[root@ansible ~]# ssh-copy-id -i ~/.ssh/id_rsa.pub root@192.168.0.89

測試認證訪問:

[root@ansible ~]# ansible all -m ping
192.168.0.83 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
192.168.0.89 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
192.168.0.87 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}
192.168.0.84 | SUCCESS => {
    "changed": false, 
    "ping": "pong"
}

4、配置時間同步

在部署前確保每個服務器的時間及時區(qū)是同步的:

[root@ansible ~]# ansible all -m shell -a 'echo "TZ='Asia/Shanghai'; export TZ" > /etc/profile '

配置定期同步時間:

[root@ansible ~]# ansible all -m cron -a "minute=*/3 job='/usr/sbin/ntpdate ntp1.aliyun.com &> /dev/null' name=dateupdate"
192.168.0.84 | SUCCESS => {
    "changed": true, 
    "envs": [], 
    "jobs": [
        "dateupdate"
    ]
}
192.168.0.89 | SUCCESS => {
    "changed": true, 
    "envs": [], 
    "jobs": [
        "dateupdate"
    ]
}
192.168.0.83 | SUCCESS => {
    "changed": true, 
    "envs": [], 
    "jobs": [
        "dateupdate"
    ]
}
192.168.0.87 | SUCCESS => {
    "changed": true, 
    "envs": [], 
    "jobs": [
        "dateupdate"
    ]
}

5、關閉firewalld和selinux

因此firewalld和selinux很容易對演示結(jié)果造成影響,因此這里我們統(tǒng)一把相應的服務器的firewalld和selinux關閉。生產(chǎn)環(huán)境中請按照實際需求進行定制。

[root@ansible ~]# ansible all -m shell -a 'systemctl stop firewalld; systemctl disable firewalld; setenforce 0'
192.168.0.87 | SUCCESS | rc=0 >>
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

192.168.0.89 | SUCCESS | rc=0 >>
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

192.168.0.84 | SUCCESS | rc=0 >>
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

192.168.0.83 | SUCCESS | rc=0 >>
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

三、配置roles

接著我們就可以在ansible主機上配置需要下發(fā)到各遠程主機上的playbook了,這里我以roles角色定義各服務器上需要配置的服務,最后用playbook調(diào)用相應的roles進行下發(fā)配置。

1、 配置apache服務role

首先在/etc/ansible/roles目錄下創(chuàng)建相關的目錄:

[root@ansible ~]# mkdir -pv  /etc/ansible/roles/apache/{files,templates,tasks,handlers,vars,meta,default}
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/apache"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/apache/files"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/apache/templates"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/apache/tasks"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/apache/handlers"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/apache/vars"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/apache/meta"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/apache/default"
[root@ansible ~]# ll /etc/ansible/roles/apache/
總用量 0

接著配置apache的配置模板:

[root@ansible ~]# vim /etc/ansible/roles/apache/templates/vhost1.conf.j2
<virtualhost *:80>
        servername www.ilinux.io
        DirectoryIndex index.html index.php
        Documentroot /var/www/html
        ProxyRequest off
        ProxyPassMatch ^/(.*\.php)$ fcgi://192.168.0.83:9000/var/www/html/$1
        ProxyPassMatch ^/(ping|status)$ fcgi://192.168.0.83:9000/$1
        <Directory / >
                options FollowSymlinks
                Allowoverride none
                Require all granted
        </Directory>
</virtualhost>

配置apache的主頁文件模板:

[root@ansible ~]# vim /etc/ansible/roles/apache/templates/
index.html
<h1>This is {{ ansible_hostname }}</h1>
[root@ansible ~]# vim /etc/ansible/roles/apache/templates/
index.php
<?php
        phpinfo();
?>

配置apache的task任務:

[root@ansible ~]# vim /etc/ansible/roles/apache/tasks/main.yml
- name: install apache
  yum: name=apache state=latest
- name: install vhost file
  template: src=/etc/ansible/roles/apache/templates/vhost1.conf.j2 dest=/etc/httpd/conf.d/vhost.conf
- name: install index.html
  template: src=/etc/ansible/roles/apache/templates/index.html dest=/var/www/html/index.html
- name: install index.php
  template: src=/etc/ansible/roles/apache/templates/index.php dest=/var/www/html/index.php
- name: start httpd
  service: name=httpd state=started

2、配置php-fpm服務的role

首先創(chuàng)建對應的roles角色目錄:

[root@ansible ~]# mkdir -pv  /etc/ansible/roles/php-fpm/{files,templates,tasks,handlers,vars,meta,default}
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/php-fpm"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/php-fpm/files"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/php-fpm/templates"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/php-fpm/tasks"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/php-fpm/handlers"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/php-fpm/vars"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/php-fpm/meta"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/php-fpm/default"

接著將事先準備好的php-fpm配置模板文件,復制到指定的模板目錄下并進行編輯:

[root@ansible ~]# cp /etc/php-fpm.d/www.conf /etc/ansible/roles/php-fpm/templates/www.conf
[root@ansible ~]# vim /etc/ansible/roles/php-fpm/templates/www.conf
#修改以下配置
listen = 0.0.0.0:9000
;listen.allowed_clients = 127.0.0.1
pm.status_path = /status
ping.path = /ping
ping.response = pong

然后配置相應的task任務文件:

[root@ansible ~]# vim /etc/ansible/roles/php-fpm/tasks/main.yml
- name: install epel repo
  yum: name=epel-release state=latest
- name: install php package
  yum: name={{ item }} state=latest
  with_items:
  - php-fpm
  - php-mysql
  - php-mbstring
  - php-mcrypt
- name: install config file
  template: src=/etc/ansible/roles/php-fpm/templates/www.conf dest=/etc/php-fpm.d/www.conf
- name: install session directory
  file: path=/var/lib/php/session group=apache owner=apache state=directory
- name: start php-fpm
  service: name=php-fpm state=started

3、配置mysql服務role

首先創(chuàng)建對應的mysql服務的roles目錄:

[root@ansible ~]# mkdir -pv  /etc/ansible/roles/mysql/{files,templates,tasks,handlers,vars,meta,default}
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/mysql"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/mysql/files"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/mysql/templates"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/mysql/tasks"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/mysql/handlers"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/mysql/vars"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/mysql/meta"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/mysql/default"

將事先準備的mysql配置文件復制到指定的模板目錄下并編輯:

[root@ansible ~]# cp /etc/my.cnf /etc/ansible/roles/mysql/templates/
[root@ansible ~]# vim /etc/ansible/roles/mysql/templates/my.cnf
#添加下面兩行配置
skip-name-resolve=ON
innodb-file-per-table=ON

接著配置mysql服務的task任務:

[root@ansible ~]# vim /etc/ansible/roles/mysql/tasks/main.yml
- name: install mysql
  yum: name=mariadb-server state=latest
- name: install config file
  template: src=/etc/ansible/roles/mysql/templates/my.cnf dest=/etc/my.cnf
- name: start mysql
  service: name=mariadb-server state=started

4、配置nginx服務的role

首先創(chuàng)建對應的ngixn服務的目錄:

[root@ansible ~]# mkdir -pv  /etc/ansible/roles/nginx/{files,templates,tasks,handlers,vars,meta,default}
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/nginx"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/nginx/files"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/nginx/templates"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/nginx/tasks"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/nginx/handlers"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/nginx/vars"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/nginx/meta"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/nginx/default"

復制nginx的配置文件到指定的模板目錄下并修改其內(nèi)容:

[root@ansible ~]# cp /etc/nginx/nginx.conf /etc/ansible/roles/nginx/templates/
[root@ansible ~]# vim /etc/ansible/roles/nginx/templates/
http {
        ......
        upstream apservers {
                server 192.168.0.83:80;
                server 192.168.0.84:80;
        }

      ......
    server {
        ......
        location / {
                proxy_pass http://apservers;
                proxy_set_header host $http_host;
                proxy_set_header X-Forward-For $remote_addr;
        }
        ......
    }

最后配置nignx服務role的task任務:

[root@ansible ~]# vim /etc/ansible/roles/nginx/tasks/main.yml
- name: install epel
  yum: name=epel-release state=latest
- name: install nginx
  yum: name=nginx state=latest
- name: install config file
  template: src=/etc/ansible/roles/nginx/templates/nginx.conf dest=/etc/nginx/nginx.conf
- name: start nginx
  service: name=nginx state=started

5、配置keepalived服務role

首先創(chuàng)建keepalived的role目錄:

[root@ansible ~]# mkdir -pv  /etc/ansible/roles/keepalived/{files,templates,tasks,handlers,vars,meta,default}
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/keepalived"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/keepalived/files"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/keepalived/templates"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/keepalived/tasks"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/keepalived/handlers"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/keepalived/vars"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/keepalived/meta"
mkdir: 已創(chuàng)建目錄 "/etc/ansible/roles/keepalived/default"

接著復制對應的配置文件到指定的模板目錄下,并編輯:

[root@ansible ~]# cp /etc/keepalived/keepalived.conf /etc/ansible/roles/keepalived/templates/

[root@ansible ~]# vim /etc/ansible/roles/keepalived/templates/keepalived.conf
global_defs {
   notification_email {
        root@localhost
   }
   notification_email_from keepalived@localhost
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id {{ ansible_nodename }}
   vrrp_mcast_group4 224.1.101.33
   vrrp_garp_interval 0
   vrrp_gna_interval 0
}

vrrp_instance VI_1 {
    state {{ keepalived_role }}
    interface ens33
    virtual_router_id 51
    priority {{ keepalived_pri }}
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass IKHN^2(1
    }
    virtual_ipaddress {
        192.168.0.99/24 dev ens33 label ens33:0
    }
}

編輯/etc/ansible/hosts文件,給nginx主機添加指定的對應變量:

[root@ansible ~]# vim /etc/ansible/hosts
[nginx]
192.168.0.87 keepalived_role=MASTER keepalived_pri=100
192.168.0.89 keepalived_role=BACKUP keepalived_pri=98

接著配置nginx服務的task服務:

[root@ansible ~]# vim /etc/ansible/roles/keepalived/tasks/main.yml
- name: install keepalived
  yum: name=keepalived state=latest
- name: install config file
  template: src=/etc/ansible/roles/keepalived/templates/keepalived.conf dest=/etc/keepalived/keepalived.conf
- name: start keepalived
  service: name=keepalived state=started

至此所有相關的服務的playbook roles已經(jīng)定義完畢。

四、配置playbook下發(fā)配置

接著我們就來定義相應的playbook調(diào)用roles下發(fā)配置。
在/etc/ansible目錄下創(chuàng)建目錄playbooks用于存放playbook文件:

[root@ansible ~]# mkdir /etc/ansible/playbooks

1、定義ap1的playbook并下發(fā)

在/etc/ansible/playbook目錄下創(chuàng)建ap1.yaml文件:

[root@ansible ~]# vim /etc/ansible/playbooks/ap1.yaml
#因為ap1又是apache服務器,也php-fpm服務器,所以調(diào)用apache和php-fpm兩個role
- hosts: php
  remote_user: root
  roles:
  - apache
  - php-fpm

檢查配置語法是否正確:

[root@ansible ~]# ansible-playbook --syntax-check /etc/ansible/playbooks/ap1.yaml

playbook: /etc/ansible/playbooks/ap1.yaml

下發(fā)安裝ap1.yaml:

[root@ansible ~]# ansible-playbook /etc/ansible/playbooks/ap1.yaml

PLAY [php] ***************************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************
ok: [192.168.0.83]

TASK [apache : install apache] *******************************************************************************************************************************
changed: [192.168.0.83]

TASK [apache : install vhost file] ***************************************************************************************************************************
ok: [192.168.0.83]

TASK [apache : install index.html] ***************************************************************************************************************************
ok: [192.168.0.83]

TASK [apache : install index.php] ****************************************************************************************************************************
ok: [192.168.0.83]

TASK [apache : start httpd] **********************************************************************************************************************************
changed: [192.168.0.83]

TASK [php-fpm : install epel repo] ***************************************************************************************************************************
ok: [192.168.0.83]

TASK [php-fpm : install php package] *************************************************************************************************************************
changed: [192.168.0.83] => (item=[u'php-fpm', u'php-mysql', u'php-mbstring', u'php-mcrypt'])

TASK [php-fpm : install config file] *************************************************************************************************************************
changed: [192.168.0.83]

TASK [php-fpm : install session directory] *******************************************************************************************************************
changed: [192.168.0.83]

TASK [php-fpm : start php-fpm] *******************************************************************************************************************************
changed: [192.168.0.83]

PLAY RECAP ***************************************************************************************************************************************************
192.168.0.83               : ok=11   changed=6    unreachable=0    failed=0   

此時在ap1上的apache服務和php-fpm服務已經(jīng)已經(jīng)正常啟動并監(jiān)控了。


相關端口已經(jīng)監(jiān)聽啟用
正常訪問ap1的php主頁

2、 定義ap2的playbook并下發(fā)

編輯配置ap2.yaml:

[root@ansible ~]# vim /etc/ansible/playbooks/ap2.yaml
- hosts: mysql
  remote_user: root
  roles:
  - apache
  - mysql

檢查是否有語法錯誤:

[root@ansible ~]# ansible-playbook --syntax-check /etc/ansible/playbooks/ap2.yaml

playbook: /etc/ansible/playbooks/ap2.yaml

下發(fā)安裝ap2.yaml:

[root@ansible ~]# ansible-playbook /etc/ansible/playbooks/ap2.yaml

PLAY [mysql] *************************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************
ok: [192.168.0.84]

TASK [apache : install apache] *******************************************************************************************************************************
changed: [192.168.0.84]

TASK [apache : install vhost file] ***************************************************************************************************************************
ok: [192.168.0.84]

TASK [apache : install index.html] ***************************************************************************************************************************
ok: [192.168.0.84]

TASK [apache : install index.php] ****************************************************************************************************************************
ok: [192.168.0.84]

TASK [apache : start httpd] **********************************************************************************************************************************
changed: [192.168.0.84]

TASK [mysql : install mysql] *********************************************************************************************************************************
changed: [192.168.0.84]

TASK [mysql : install config file] ***************************************************************************************************************************
changed: [192.168.0.84]

TASK [mysql : start mysql] ***********************************************************************************************************************************
changed: [192.168.0.84]

PLAY RECAP ***************************************************************************************************************************************************
192.168.0.84               : ok=9    changed=5    unreachable=0    failed=0   

此時ap2上的apache服務和mysql服務應該已經(jīng)監(jiān)聽啟用。


相關接口已監(jiān)聽啟用

ap2的主頁能正常訪問

3、定義兩臺nginx服務器的playbook并下發(fā)

編輯創(chuàng)建loadbalance.yaml:

[root@ansible ~]# vim /etc/ansible/playbooks/loadbalance.yaml
- hosts: nginx
  remote_user: root
  roles:
  - nginx
  - keepalived

檢查是否有語法錯誤:

[root@ansible ~]# ansible-playbook --syntax-check /etc/ansible/playbooks/loadbalance.yaml

playbook: /etc/ansible/playbooks/ap2.yaml

下發(fā)安裝loadbalance.yaml:

[root@ansible ~]# ansible-playbook /etc/ansible/playbooks/loadbalance.yaml

PLAY [nginx] *************************************************************************************************************************************************

TASK [Gathering Facts] ***************************************************************************************************************************************
ok: [192.168.0.87]
ok: [192.168.0.89]

TASK [nginx : install epel] **********************************************************************************************************************************
changed: [192.168.0.87]
changed: [192.168.0.89]

TASK [nginx : install nginx] *********************************************************************************************************************************
changed: [192.168.0.87]
changed: [192.168.0.89]

TASK [nginx : install config file] ***************************************************************************************************************************
changed: [192.168.0.89]
changed: [192.168.0.87]

TASK [nginx : start nginx] ***********************************************************************************************************************************
changed: [192.168.0.89]
changed: [192.168.0.87]

TASK [keepalived : install keepalived] ***********************************************************************************************************************
changed: [192.168.0.89]
changed: [192.168.0.87]

TASK [keepalived : install config file] **********************************************************************************************************************
changed: [192.168.0.89]
changed: [192.168.0.87]

TASK [keepalived : start keepalived] *************************************************************************************************************************
changed: [192.168.0.89]
changed: [192.168.0.87]

PLAY RECAP ***************************************************************************************************************************************************
192.168.0.87               : ok=8    changed=7    unreachable=0    failed=0   
192.168.0.89               : ok=8    changed=7    unreachable=0    failed=0   

此時在兩臺nginx服務器上的keepalived和nginx應該都正常啟動了。


nginx1上的keepalived服務狀態(tài)及端口啟動情況
nginx2上的keepalived服務狀態(tài)及端口啟動情況

4、測試訪問

此時嘗試通過vip訪問后端ap1和ap2的主頁:

[root@ansible ~]# for i in {1..10} ; do curl http://192.168.0.99/ ; done
<h1>This is ap2</h1>
<h1>This is ap1</h1>
<h1>This is ap2</h1>
<h1>This is ap1</h1>
<h1>This is ap2</h1>
<h1>This is ap1</h1>
<h1>This is ap2</h1>
<h1>This is ap1</h1>
<h1>This is ap2</h1>
<h1>This is ap1</h1>
#訪問成功

把其中一個nginx主機的keepalived服務停用,觀察主備是否切換:

[root@nginx2 ~]# systemctl status keepalived
● keepalived.service - LVS and VRRP High Availability Monitor
   Loaded: loaded (/usr/lib/systemd/system/keepalived.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2018-06-07 15:26:47 CST; 8min ago
 Main PID: 10857 (keepalived)
   CGroup: /system.slice/keepalived.service
           ├─10857 /usr/sbin/keepalived -D
           ├─10858 /usr/sbin/keepalived -D
           └─10859 /usr/sbin/keepalived -D

Jun 07 15:26:47 nginx2 Keepalived_healthcheckers[10858]: Opening file '/etc/keepalived/keepalived.conf'.
Jun 07 15:34:50 nginx2 Keepalived_vrrp[10859]: VRRP_Instance(VI_1) Transition to MASTER STATE
Jun 07 15:34:51 nginx2 Keepalived_vrrp[10859]: VRRP_Instance(VI_1) Entering MASTER STATE
Jun 07 15:34:51 nginx2 Keepalived_vrrp[10859]: VRRP_Instance(VI_1) setting protocol VIPs.
Jun 07 15:34:51 nginx2 Keepalived_vrrp[10859]: Sending gratuitous ARP on ens33 for 192.168.0.99
Jun 07 15:34:51 nginx2 Keepalived_vrrp[10859]: VRRP_Instance(VI_1) Sending/queueing gratuitous ARPs on ens33 for 192.168.0.99
Jun 07 15:34:51 nginx2 Keepalived_vrrp[10859]: Sending gratuitous ARP on ens33 for 192.168.0.99
Jun 07 15:34:51 nginx2 Keepalived_vrrp[10859]: Sending gratuitous ARP on ens33 for 192.168.0.99
Jun 07 15:34:51 nginx2 Keepalived_vrrp[10859]: Sending gratuitous ARP on ens33 for 192.168.0.99
Jun 07 15:34:51 nginx2 Keepalived_vrrp[10859]: Sending gratuitous ARP on ens33 for 192.168.0.99

keepalived主備切換成功,此時服務依舊能正常訪問。

至此使用ansible部署管理高可用的LAMP環(huán)境就已經(jīng)完成了,后續(xù)可在此環(huán)境上搭建相應的wordpress或其他的應用服務。(不得不說,ansible真方便。。。)

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子,更是在濱河造成了極大的恐慌,老刑警劉巖,帶你破解...
    沈念sama閱讀 229,732評論 6 539
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異,居然都是意外死亡,警方通過查閱死者的電腦和手機,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 99,214評論 3 426
  • 文/潘曉璐 我一進店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人,你說我怎么就攤上這事。” “怎么了?”我有些...
    開封第一講書人閱讀 177,781評論 0 382
  • 文/不壞的土叔 我叫張陵,是天一觀的道長。 經(jīng)常有香客問我,道長,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 63,588評論 1 316
  • 正文 為了忘掉前任,我火速辦了婚禮,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘。我一直安慰自己,他們只是感情好,可當我...
    茶點故事閱讀 72,315評論 6 410
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著,像睡著了一般。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 55,699評論 1 327
  • 那天,我揣著相機與錄音,去河邊找鬼。 笑死,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播,決...
    沈念sama閱讀 43,698評論 3 446
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 42,882評論 0 289
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 49,441評論 1 335
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 41,189評論 3 356
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 43,388評論 1 372
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情,我是刑警寧澤,帶...
    沈念sama閱讀 38,933評論 5 363
  • 正文 年R本政府宣布,位于F島的核電站,受9級特大地震影響,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 44,613評論 3 348
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 35,023評論 0 28
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 36,310評論 1 293
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人。 一個月前我還...
    沈念sama閱讀 52,112評論 3 398
  • 正文 我出身青樓,卻偏偏與公主長得像,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當晚...
    茶點故事閱讀 48,334評論 2 377

推薦閱讀更多精彩內(nèi)容