环境
需要六台服务器:
两台keepalived+nginx:192.168.80.100/192.168.80.101
两台varnish:192.168.80.102/192.18.80.103
两台lamp:192.168.80.104/192.168.80.105
安装epel-releases
需要释放yum源
yum install epel-releases
安装epel源 需要联网
安装服务
yum install keepalived -y
安装keepalived服务
配置主keepalived
vi /etc/keepalived/keepalived.conf
global_defs {
route_id NGINX-01
}
vrrp_script nginx { //vrrp脚本
script "/opt/nginx.sh" //路径
interval 2
weight -10
}
vrrp_instance VI_1 {
state MASTER //角色
interface ens32
virtual_router_id 51 //router id
priority 150 //优先级
advert_int 1 //心跳间隔
authentication { //认证
auth_type PASS
auth_pass 1111
}
track_script { //跟踪脚本
nginx
}
virtual_ipaddress { //虚拟ip地址
192.168.80.188
}
}
制作跟踪脚本
vi /opt/nginx.sh
#!/bin/bash
#Filename:nginx.sh
A=$(ps -ef | grep keepalived | grep -v grep | wc -l)
if [ $A -gt 0 ]; then
systemctl start nginx
else
systemctl stop nginx
fi
安装nginx
测试keepalived
pkill -9 nginx
systemctl start keepalived
netstat -anpt | grep nginx
当启动keepalived时vrrp脚本也会根据情况把nginx开启或者关闭
当keepalived启动
输入 ip addr show dev en32
部署nginx
vi /etc/nginx/nginx.conf
定义地址池
vi /etc/nginx/conf.d/default.conf
转发至地址池
制作备服务器80.101
需要释放yum源
cd /etc/yum.repo/
安装epel-releases
yum install epel-releases
安装epel源 需要联网
安装服务
yum install keepalived -y
安装keepalived服务
安装nignx
配置备服务器
在80.100上
因为两台服务器配置差不多所以我选择发送
scp /etc/keepalived/keepalived.conf root@192.168.80.101:/etc/keepalived/keepalived.conf
scp /etc/nginx/nginx.conf root@192.168.80.101:/etc/nginx/nginx.conf
scp /etc/nginx/conf.d/default.conf root@192.168.80.101:/etc/nginx/conf.d/default.conf
修改备服务器配置
vi /etc/keepalived/keepalived.conf
编写vrrp脚本
vi /opt/nginx.sh
#!/bin/bash
#Filename:nginx.sh
A=$(ip addr | grep 192.168.80.188/32 | grep -v grep | wc -l)
if [ $A -gt 0 ]; then
systemctl start nginx
else
systemctl stop nginx
fi
测试
关闭所有防火墙
systemctl stop firewalld
setenforce 0
当192.168.80.100 的keepalived关闭后漂移地址回到80.101上
以上keepalived+nginx完成
安装varnish80.102
>需要释放yum源
cd /etc/yum.repo/
安装epel-releases
yum install epel-releases
安装epel源 需要联网
安装varnish
yum install varnish -y
配置varnish
vi /etc/varnish/varnish.params
vi /etc/varnish/default.vcl
backend web1 {
.host = "192.168.80.104";
.port = "80";
}
代理服务器
sub vcl_recv {} //定义规则
开启服务
systemctl start varnish
制作备服务器80.103
安装varnish
需要释放yum源
cd /etc/yum.repo/
安装epel-releases
yum install epel-releases
安装epel源 需要联网
安装varnish
yum install varnish -y
修改配置文件
在80.102上
scp /etc/varnish/varnish.params root@192.168.80.103:/etc/varnish/varnish.paramsv
scp /etc/varnish/default.vcl root@192.168.80.103:/etc/varnish/default.vcl
启动varnish服务
systemctl start varnish
在部署lamp
安装http服务80.104
yum install httpd -y
修改配置文件
vi /etc/httpd/conf/httpd.conf
vi /var/www/html/index.php
重启服务
systemctl start httpd
部署httpd 80.105
安装yum install httpd
修改配置文件
vi /etc/httpd/conf/httpd.conf
vi /var/www/html/index.php
测试
关闭所有防火墙
未完成.............
原文地址:http://blog.51cto.com/14150862/2351720