nginx+keepalived高可用
准备工作:
yum install -y gcc openssl-devel pcre-devel install iptables-services setenforce 0
sed -ri 's/^(SELINUX=).*/\1disabled/' /etc/selinux/config systemctl stop firewalld
systemctl disable firewalld
systemctl enable iptables
systemctl start iptables vim /etc/sysconfig/iptables
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 8080 -j ACCEPT
-A INPUT -d 224.0.0.0/8 -p vrrp -j ACCEPT
-A OUTPUT -d 224.0.0.0/8 -p vrrp -j ACCEPT
systemctl restart iptables
安装nginx两个机器安装方式一样
#上传tengine-2.1.2.tar.gz /tmp
#安装
cd /tmp
yum install -y gcc openssl-devel pcre-devel
tar -xf tengine-2.1.2.tar.gz
mkdir -p /opt/platform/nginx/logs
cd tengine-2.1.2
./configure --prefix=/opt/platform/nginx --with-http_ssl_module --with-http_stub_status_module
make && make install
#替换nginx.conf
cd /opt/platform/nginx/conf
mv nginx.conf nginx.conf.bak
上传nginx.conf
#user ops;
worker_processes auto;
worker_cpu_affinity auto; error_log logs/error.log error; pid logs/nginx.pid; worker_rlimit_nofile 65535; events {
use epoll;
worker_connections 65535;
} 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"'; log_format json '{"@timestamp":"$time_iso8601",'
'"remote_addr":"$remote_addr",'
'"remote_user":"$remote_user",'
'"http_host":"$http_host",'
'"request":"$request",'
'"status":"$status",'
'"body_bytes_sent":$body_bytes_sent,'
'"http_referer":"$http_referer",'
'"http_user_agent":"$http_user_agent",'
'"http_x_frowarded_for":"$http_x_forwarded_for",'
'"upstream_status":"$upstream_status",'
'"upstream_addr":"$upstream_addr",'
'"upstream_response_time":"$upstream_response_time",'
'"request_time":$request_time}'; access_log logs/access.log json; sendfile on;
#tcp_nopush on; keepalive_timeout 65; client_header_buffer_size 20m;
large_client_header_buffers 4 2048k;
client_max_body_size 20m;
proxy_buffer_size 64k;
proxy_buffers 4 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k; proxy_ignore_client_abort on; #让代理服务端不要主动关闭客户端的连接。 gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript image/jpeg image/gif image/png application/javascript;
gzip_proxied any;
gzip_disable "MSIE [1-6]\."; server {
listen 80 default;
server_name _;
return 499;
} include /opt/platform/nginx/conf/vhosts/*.conf;
}
#增加web应用负载均衡配置文件
mkdir -p vhosts
cd vhosts
上传ken.conf
upstream ken {
server ip:port weight=4 max_fails=2 fail_timeout=30s;
server ip:port weight=4 max_fails=2 fail_timeout=30s;
}
server {
listen 8080;
server_name _;
access_log logs/ken.log json;
location / {
proxy_pass http://ken;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_connect_timeout 10s;
proxy_send_timeout 150s;
proxy_read_timeout 150s;
proxy_next_upstream error timeout invalid_header http_404 http_500 http_502 http_504;
}
}
#配置文件生效
/opt/platform/nginx/sbin/nginx -s reload
安装keepalived
#上传tengine-2.1.2.tar.gz 在目录/tmp
#主机安装
cd /tmp
tar -xvf keepalived-nginx.tar.gz -C /opt/platform/
/opt/platform/keepalived/etc/keepalived/keepalived.conf
! Configuration File for keepalived
global_defs {
router_id ken
}
vrrp_script check_nginx {
script "/opt/platform/keepalived/bin/check.sh"
interval 2
timeout 2
fall 2
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 215
priority 99
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass ken@215
}
track_script {
check_nginx
}
virtual_ipaddress {
vip/24 brd mask
}
notify_master "/opt/platform/keepalived/bin/notify.sh master"
notify_backup "/opt/platform/keepalived/bin/notify.sh backup"
notify_fault "/opt/platform/keepalived/bin/notify.sh fault"
notify_stop "/opt/platform/keepalived/bin/notify.sh stop"
}
另外一台机器安装方式一样,但是需要修改keepalived.conf的一个参数
priority 150 #将99调整为150
启动keepalived
cd /opt/platform/keepalived/sbin
sh startup.sh
nginx+keepalived高可用的更多相关文章
- Nginx入门篇(七)之Nginx+keepalived高可用集群
一.keepalived介绍 keepalived软件最开始是转为负载均衡软件LVS而设计,用来管理和监控LVS集群系统中各个服务节点的状态,后来又加入了可实现高可用的VRRP功能.所以Keepali ...
- 使用Ansible实现nginx+keepalived高可用负载均衡自动化部署
本篇文章记录通过Ansible自动化部署nginx的负载均衡高可用,前端代理使用nginx+keepalived,端web server使用3台nginx用于负载效果的体现,结构图如下: 部署前准备工 ...
- Nginx+keepalived(高可用主备模式)
Nginx+keepalived(高可用主备模式) 环境:centos6.7 准备:两台服务器(虚拟机).两台应用(Tomcat).Nginx.keepalived server1:192.168.2 ...
- Nginx+keepalived(高可用双主模式)
Nginx+keepalived(高可用双主模式) tips:前面已经介绍了nginx+keepalived高可用主从模式,今天补充下高可用的双主模式,均可以作为主机使用 server1:192.16 ...
- Nginx+Keepalived高可用集群应用实践
Nginx+Keepalived高可用集群应用实践 1.Keepalived高可用软件 1.1 Keepalived服务的三个重要功能 1.1.1管理LVS负载均衡软件 早期的LVS软件,需要通过命令 ...
- Nginx知多少系列之(十四)Linux下.NET Core项目Nginx+Keepalived高可用(主从模式)
目录 1.前言 2.安装 3.配置文件详解 4.工作原理 5.Linux下托管.NET Core项目 6.Linux下.NET Core项目负载均衡 7.负载均衡策略 8.加权轮询(round rob ...
- nginx+keepalived 高可用方案
nginx+keepalived 高可用方案 准备工作 192.168.157.11 192.168.157.12 安装nginx 跟新yum源文件 rpm -ivh http://nginx.org ...
- nginx+keepalived高可用及双主模式
高可用有2中方式. 1.Nginx+keepalived 主从配置 这种方案,使用一个vip地址,前端使用2台机器,一台做主,一台做备,但同时只有一台机器工作,另一台备份机器在主机器不出现故障的时候, ...
- nginx+keepalived高可用web负载均衡
一:安装环境 准备2台虚拟机,都安装好环境 centos 7keepalived:vip: 192.168.1.112192.168.1.110 nginxip 192.168.1.109 maste ...
- nginx keepalived 高可用方案(转)
转自: https://www.cnblogs.com/leeSmall/p/9356535.html 一.Nginx Rewrite 规则 1. Nginx rewrite规则 Rewrite规则含 ...
随机推荐
- Oracle用户被锁解决方法
.查看用户的proifle是哪个,一般是default: sql>SELECT username,PROFILE FROM dba_users; .查看指定概要文件(如default)的密码有效 ...
- Leetcode题目64.最小路径和(动态规划-中等)
题目描述: 给定一个包含非负整数的 m x n 网格,请找出一条从左上角到右下角的路径,使得路径上的数字总和为最小. 说明:每次只能向下或者向右移动一步. 示例: 输入: [ [1,3,1], [1, ...
- 解决虚拟机上的tomcat无法被主机访问的问题
在wmware中安装linux后安装好数据库,JDK及tomcat后启动服务,虚拟机中可以访问,但是主机却无法访问,但是同时主机和虚拟机之间可以ping的通. 网上查阅资料后 第一种解决方法是 ...
- ARP输入 之 arp_process
概述 arp_process为ARP输入包的核心处理流程: 若输入为ARP请求且查路由成功,则进行如下判断:输入到本地,则进行应答:否则,允许转发,则转发,本文代码不包含转发流程: 若输入为ARP应答 ...
- MAC下STF安装及踩坑
[Mac OS X]brew: command not found ruby -e"$(curl -fsSL https://raw.githubusercontent.com/Homebr ...
- 简易总结react-hook三大基础
react-hook的最重要的三大基础 import { useEffect, useState, useContext } from 'react' 1.每一个简单的一句话总结 useEffect ...
- LC 979. Distribute Coins in Binary Tree
Given the root of a binary tree with N nodes, each node in the tree has node.val coins, and there ar ...
- LC 970. Powerful Integers
Given two non-negative integers x and y, an integer is powerful if it is equal to x^i + y^j for some ...
- 最新create-react-native-app搭建rn教程
一.前置条件: 1.nodeJS环境 2.npm 3.yarn 二.安装及项目初始化 1.安装脚手架 npm install -g create-react-native-app 2.用脚手架初始化创 ...
- UmUtils得到友盟的渠道号
import android.content.Context; import android.content.pm.ApplicationInfo; import android.content.pm ...