linux Nginx +keepalived+varnish+lamp实现高可用、负载均衡集群

环境

需要六台服务器:
两台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

http://blog.51cto.com/14150862/2351500

测试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

http://blog.51cto.com/14150862/2351500

配置备服务器

在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

时间: 2024-10-12 16:12:18

linux Nginx +keepalived+varnish+lamp实现高可用、负载均衡集群的相关文章

Linux下Keepalived+LVS-DR模式配置高可用负载均衡集群

一.环境说明:     操作系统:Centos-6.5_x86_64    keepalived软件安装在node2和node3机器上.     实际安装之前,先关闭keepalived节点(node2,node3)上的防火墙. [[email protected] ~]# service iptables stop 二.软件安装:     这里需要安装的软件是keepalived.node2和node3都需要安装. [[email protected] ~]# yum install keep

apache+inotify-tools+keepalived+lvs-DR模式配置高可用负载均衡集群

环境:虚拟机VMware workstation 9 操作系统:Redhat 5.6 i386 一.keepalived+LVS-DR模式配置高可用负载均衡 拓扑如下: 二.服务器IP配置信息 四台服务器均有VMware虚拟机实现,两台HA主机.两台web服务器.网络方式都设置为NAT模式 1.master:192.168.80.145 2.slaver:192.168.80.137 3.web1:192.168.80.144 4.web2:192.168.80.134 5.VIP:192.16

LVS+keepalived DR模式配置高可用负载均衡集群

实验环境 LVS-Master 10.0.100.201 VIP:10.0.100.203 LVS-Slave       10.0.100.204 WEB1-Tomcat 10.0.2.29 gateway:10.0.2.253 WEB2-Tomcat 10.0.100.202 (注意:应保持所有服务器的时间一致) Install LVS # ln -s /usr/src/kernels/2.6.32-431.el6.i686/ /usr/src/linux //若找不到这个目录则先安装ker

nginx+keepalived的高可用负载均衡集群构建

实验架构图: 实验环境 Nginx和Keepalived原理介绍 参考博客:http://467754239.blog.51cto.com/4878013/1541421 1.nginx Nginx进程基于于Master+Slave(worker)多进程模型,自身具有非常稳定的子进程管理功能.在Master进程分配模式下,Master进程永远不进行业务处理,只是进行任务分发, 从而达到Master进程的存活高可靠性,Slave(worker)进程所有的业务信号都 由主进程发出,Slave(wor

Keepalived+Nginx实现高可用负载均衡集群

一 环境介绍 1.操作系统CentOS Linux release 7.2.1511 (Core) 2.服务keepalived+lvs双主高可用负载均衡集群及LAMP应用keepalived-1.2.13-7.el7.x86_64nginx-1.10.2-1.el7.x86_64httpd-2.4.6-45.el7.centos.x86_64 二 原理及拓扑图 1.vrrp协议在现实的网络环境中,两台需要通信的主机大多数情况下并没有直接的物理连接.对于这样的情况,它们之间路由怎样选择?主机如何

Keepalived+LVS(dr)高可用负载均衡集群的实现

一 环境介绍 1.操作系统CentOS Linux release 7.2.1511 (Core) 2.服务keepalived+lvs双主高可用负载均衡集群及LAMP应用keepalived-1.2.13-7.el7.x86_64ipvsadm-1.27-7.el7.x86_64httpd-2.4.6-45.el7.centos.x86_64mariadb-5.5.52-1.el7.x86_64php-5.4.16-42.el7.x86_64 二 原理及拓扑图 1.vrrp协议vrrp(Vir

Nginx+Keepalived搭建高可用负载均衡集群

Nginx+Keepalived搭建高可用负载均衡集群   一. 环境说明 前端双Nginx+keepalived,nginx反向代理到后端的tomcat集群实现负载均衡,Keepalived实现集群高可用. 操作系统: Centos 6.6_X64 Nginx版本: nginx-1.9.5 Keepalived版本:keepalived-1.2.13 结构: Keepalived+nginx-MASTER:10.6.1.210         Keepalived+nginx-BACKUP:

LVS+Keepalived搭建MyCAT高可用负载均衡集群

LVS+Keepalived 介绍 LVS LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目之一.目前有三种IP负载均衡技术(VS/NAT.VS/TUN和VS/DR),十种调度算法(rrr|wrr|lc|wlc|lblc|lblcr|dh|sh|sed|nq). Keepalvied Keepalived在这里主要用作RealServer的健康状态检查以及Mast

Haproxy+Keepalived搭建Weblogic高可用负载均衡集群

配置环境说明:   KVM虚拟机配置 用途 数量 IP地址 机器名 虚拟IP地址 硬件 内存3G  系统盘20G cpu 4核 Haproxykeepalived 2台 192.168.1.10192.168.1.20 Haserver01Haserver02 192.168.30192.168.40 内存6G  系统盘20G cpu 4核 Weblogic 4台 192.168.1.100192.168.1.150 192.168.1.200 192.168.1.250 Clusters01C