博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Nginx +keepalived+varnish+lamp实现高可用、负载均衡集群
阅读量:6453 次
发布时间:2019-06-23

本文共 4264 字,大约阅读时间需要 14 分钟。

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

描述:
1、前端两台NGINX,通过keepalived虚拟IP漂移,实现前端两台NGINX高可用;
2、利用NGINX反向代理功能对后端varnish实现高可用集群,

3、再通过varnish实现动静分离


注:1、先装Nginx +keepalived

2、装varnish
3、装lamp
需要6台虚拟机(100-101装Nginx +keepalived:100主,101备)需要联网(102-103装varnish)需要联网(104-105装lamp)需要联网
Nginx +keepalived+varnish+lamp实现高可用、负载均衡集群

所有主机必做的步骤systemctl stop firewalld      //关闭防火墙setenforce 0         //关闭监控
1、装Nginx +keepalived(两台机子都要做的)(100主101备)systemctl stop firewalld      //关闭防火墙setenforce 0         //关闭监控cd /etc/yum.repos.d/mv back/* ./

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

yum install -y epel-release

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

yum install -y nginx

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

yum install keepalived -y

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

————————————————————————————————

主(80.100)

vi /etc/keepalived/keepalived.conf(把里面内容全删了添加以下内容)! Configuration File for keepalived global_defs {         route_id NGINX-01    }vrrp_script nginx {        script "/opt/nginx.sh"        interval 2        weight -10}vrrp_instance VI_1 {    state MASTER    interface ens32    virtual_router_id 51    priority 150    advert_int 1    authentication {        auth_type PASS        auth_pass 1111    }    track_script {        nginx        }    virtual_ipaddress {        192.168.80.188    }}

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

scp /etc/keepalived/keepalived.conf root@192.168.80.101:/etc/keepalived/keepalived.conf

备(80.101)

vi /etc/keepalived/keepalived.conf(修改以下画圈部分)

Nginx +keepalived+varnish+lamp实现高可用、负载均衡集群
主(80.100)

vi /opt/nginx.sh(添加以下内容)#!/bin/bashA=$(ps -ef | grep keepalived | grep -v grep | wc -l)if [ $A -gt 0 ];then        systemctl start nginxelse        systemctl sop nginxfi

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

chmod +x /opt/nginx.shll /opt/nginx.sh

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

netstat -anpt | grep nginxsystemctl start keepalivednetstat -anpt | grep nginx

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

ip addr show ens32

Nginx +keepalived+varnish+lamp实现高可用、负载均衡集群
备(80.101)

vi /opt/nginx.sh(添加以下内容)#!/bin/bashA=$(ip addr | grep 192.168.80.188/32 | grep -v grep | wc -l)if [ $A -gt 0 ];then        systemctl start nginx else        systemctl stop nginxfi

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

chmod +x /opt/nginx.shsystemctl start keepalivedcat /var/log/messages

Nginx +keepalived+varnish+lamp实现高可用、负载均衡集群
主(80.100)

cat /var/log/messages

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

vi /etc/nginx/nginx.conf(修改以下内容)upstream varnish_pool {              server 192.168.80.102:80;              server 192.168.80.103:80;       }proxy_pass http://varnish_pool;proxy_set_header Host $host;proxy_set_header X-Forwarded-For $remote_addr;

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

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

nginx -t

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

scp /etc/nginx/nginx.conf 192.168.80.101:/etc/nginx/nginx.conf
systemctl restart nginx
2、装varnish(80.102,80.103)(两台机子都需要做)systemctl stop firewalld      //关闭防火墙setenforce 0         //关闭监控cd /etc/yum.repos.d/mv back/* ./yum  install epel-release -y  //需要联网

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

yum install -y varnish

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

————————————————————————————————

vi /etc/varnish/varnish.params(修改环圈部分)

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

vi /etc/varnish/default.vcl(修改添加以下部分)backend web1 {    .host = "192.168.80.104";    .port = "80";}backend web2 {    .host = "192.168.80.105";    .port = "80";}sub vcl_recv {if (req.url ~ "(?i)\.php$"){    set req.backend_hint = web1;}else{    set req.backend_hint = web2;}

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

systemctl  start varnishnetstat -anpt | grep varnish

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

vi /etc/varnish/varnish.params(修改以下内容)

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

scp /etc/varnish/default.vcl 192.168.80.103:/etc/varnish/default.vcl

80.103

systemctl start varnishnetstat -anpt | grep varnish

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

3、装lamp(两台机子都要做的)(100主101备)systemctl stop firewalld      //关闭防火墙setenforce 0         //关闭监控cd /etc/yum.repos.d/mv back/* ./安装wgetyum install -y  wget

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

yum install -y httpd

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

systemctl start httpdsystemctl enable httpd获取rpm软件包:wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm

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

安装rpm包rpm -ivh mysql-community-release-el7-5.noarch.rpm

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

安装mysqlyum install -y mysql-community-server

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

启动 systemctl start mysqlsystemctl enable mysql修改root密码并设置允许远程连接进入mysql  mysql -uroot

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

设置root密码为123456set password for 'root'@'localhost' =password('123456');设置允许用root账户进行远程连接,并设置其密码为123456grant all privileges on *.* to root@'%'identified by '123456';修改的配置立即生效flush privileges;退出:exit

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

部署phpyum install -y php
安装组件是php支持mysql yum install -y \php-mysql \php-gd \libjpeg* \php-ldap \php-odbc \php-pear \php-xml \php-xmlrpc \php-mbstring \php-bcmath \php-mhash

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

————————————————————————————————

80.104

vi /etc/httpd/conf/httpd.conf(修改以下内容)ServerName www.example.com:80去掉#号

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

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

systemctl start httpdecho "

192.168.80.101

" > /var/www/html/index.php

80.105

vi /etc/httpd/conf/httpd.conf(修改以下内容)ServerName www.example.com:80去掉#号

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

systemctl start httpdecho "

192.168.80.102

" > /var/www/html/index.html

任务栏搜索192.168.80.100

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

任务栏搜索192.168.80.102

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

任务栏搜索192.168.80.103

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

任务栏搜索192.168.80.104

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

任务栏搜索192.168.80.105

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

任务栏搜索192.168.80.188

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

转载于:https://blog.51cto.com/14158288/2351758

你可能感兴趣的文章
线段树分治
查看>>
git代码冲突
查看>>
lnmp1.3 配置pathinfo---thinkphp3.2 亲测有效
查看>>
查看Linux 系统的配置和增减用户/增减组/增减权限
查看>>
利用android studio 生成 JNI需要的动态库so文件
查看>>
poll
查看>>
衡量优秀的卓越的前端工程师
查看>>
解析查询 queryString 请求参数的函数
查看>>
学生选课系统数据存文件
查看>>
flutter进行自动编译操作步骤
查看>>
4.6 直接插入排序法
查看>>
我的毕设总结所用的技术和只是要点 基于stm32F4的AGV嵌入式控制系统的设计
查看>>
盘点国内外那些有野心的BI公司
查看>>
JMeter—断言
查看>>
C++的新类创建:继承与组合
查看>>
m5-第9周作业
查看>>
odoo 权限设置
查看>>
asp操作access提示“无法从指定的数据表中删除”
查看>>
git bash 风格调整
查看>>
997D Cycles in product
查看>>