一、前言
嘗試通過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)控了。
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)聽啟用。
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應該都正常啟動了。
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真方便。。。)