环境
需要六台服务器:
两台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/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
测试
关闭所有防火墙
未完成.............