keepalived+nginx+apache主备及双活搭建测试》,该测试环境只有一张网卡,双活的ip都在该网卡上。
本文背景:自动化运维平台的前置机部署在云平台,服务器有两张网卡,分别对应带外ip和业务ip;云平台的被管服务器访问带外虚ip,非云平台的物理服务器访问业务的虚ip。
架构图:
配置:主机ip操作系统软件vip
nginx01172.27.9.91
172.27.18.127Centos7.3.1611nginx 端口82
keepalived172.27.9.200
nginx02172.27.9.92
172.27.18.128Centos7.3.1611nginx 端口82
keepalived172.27.18.120
web01172.27.9.125Centos7.3.1611apache 端口1180/
web02172.27.9.126Centos7.3.1611apache 端口1180/
vmware版本:12.5.2 build-4638234
1.vmware新增网卡
打开‘虚拟网络编辑器’:
‘VMnet0’和‘VMnet2’分别对应pc机物理网卡和无线网卡:
新增网卡及配置:
2.keepalived配置
nginx01上keepalived配置:[[email protected] keepalived]# more /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
#smtp_server 192.168.200.1
#smtp_connect_timeout 30
router_id proxy1
}
vrrp_script chk_nginx {
script "/etc/keepalived/check_nginx.sh"
interval 2
weight 20
fall 1
rise 10
}
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.27.9.200
}
track_script {
chk_nginx
}
}
vrrp_instance VI_2 {
state BACKUP
interface ens37
virtual_router_id 52
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.27.18.120
}
track_script {
chk_nginx
}
}
nginx02上keepalived配置:[[email protected] keepalived]# more /etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
[email protected]
[email protected]
[email protected]
}
notification_email_from [email protected]
#smtp_server 192.168.200.1
#smtp_connect_timeout 30
router_id proxy2
}
vrrp_script chk_nginx {
script "/etc/keepalived/check_nginx.sh"
interval 2
weight 20
fall 2
rise 1
}
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.27.9.200
}
track_script {
chk_nginx
}
}
vrrp_instance VI_2 {
state MASTER
interface ens37
virtual_router_id 52
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
172.27.18.120
}
track_script {
chk_nginx
}
}
check_nginx.sh脚本配置同之前文章
3.nginx配置
两台nginx服务器配置相同如下:[[email protected] keepalived]# more /usr/local/nginx/conf/nginx.conf
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
upstream webser{
server 172.27.9.125:1180;
server 172.27.9.126:1180;
server 172.27.18.127:1180;
server 172.27.18.128:1180;
}
server {
listen 82;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://webser;
#root html;
#index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
4.启动服务
启动两台服务器nginx和keepalived服务:
7.高可用测试
同之前文章,不再赘述。
测试完成,云平台生产环境也可以按本次测试实施。
原文:http://blog.51cto.com/3241766/2129948