keepalived+nginx 实现 sharepoint 负载均衡

keepalived 实现虚拟路由
nginx 做反向代理和负载均衡

要点
1、ssl代理
ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;
2、访问http时重定向的https
server {
listen 80;
server_name proxy-server180;
location / {
rewrite ^(.*)$ https://$host$1 permanent;
#proxy_pass http://192.168.16.193;
}
}
3、nginx 状态
location /basic_status {
stub_status;
}
4、图片和html页面缓存
location ~* \.(gif|jpg|jpeg|png|gif|css|js|html|htm)$ {
proxy_pass http://192.168.16.193;
proxy_cache proxy-cache;
proxy_cache_key $scheme$proxy_host$request_uri;
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
proxy_cache_use_stale error;
}
5、调大读写超时时长,
proxy_read_timeout 120s;
proxy_send_timeout 120s;

6、通过追加request header 向后端webserver传递 clientip
proxy_set_header Host $host;
proxy_set_header Real-Client-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
7、通过追加response header,在客户端方便查看当前活动nginx Server
add_header proxy-server $server_name;
8、在 webserver 的httpmodule 上 增加 “RServer”Responseheader,值为被调度到的WebServerName
HttpContext.Current.Response.AddHeader(“RServer”, HostName);

9、WebClinet–ssl–> Nginx –http–> WebServer
服务端代码重定向时 取相对路径
10、upstream NAME 命名为 域名,nginx 需要 使用 upstream NAME 访问 WebServer,sharepoint 对访问的 URL有限制
upstream workflow.clo.cn {
server 192.168.16.10 weight=2 max_fails=2 fail_timeout=10s;
server 192.168.16.11 weight=1 max_fails=2 fail_timeout=10s;
zone upstream_webgroup 1024k;
ip_hash;
}
11、定义向下一个WebServer调度的策略,
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_403 http_404 http_429;
12、上传大小受限于以下参数
client_max_body_size 128m;
13、sharepoint 各个前端 web.config 的 machineKey 值一致,使调度到任意前端用户登录有效
<machineKey validationKey=”F68C11032A0FEA7BC535DCA20CD73059634B82193D5F087E” decryptionKey=”8FD256AFFE8CB4342E37DD7BAD7C4416A3FA586B6CBD717A” validation=”SHA1″ />

 

一  部署nginx

分别在node4(192.168.16.64),node5(192.168.16.65) 按 如下步奏部署nginx
 到www.nginx.org 下载 源码
 1、useradd -r nginx
 2、yum install pcre-devel
 3、yum install openssl-devel
 4、./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --user=nginx --group=nginx --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx/nginx.pid --lock-path=/var/lock/nginx.lock --with-http_ssl_module --with-mail --with-debug --with-http_stub_status_module
 5、make && make install
 6、PATH=/usr/local/nginx:$PATH
 7、配置 /etc/nginx/nginx.conf,

—————————————–nginx.conf————————————————

#user nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
client_max_body_size 128m;
client_header_buffer_size 16k;
large_client_header_buffers 4 16k;
sendfile on;
#keepalive_timeout 0;
keepalive_timeout 65;
add_header proxy-server $server_name;
proxy_cache_path /var/log/nginx/proxy-cache levels=2:2:2 keys_zone=proxy-cache:10m;
proxy_next_upstream error timeout invalid_header http_500 http_502 http_503 http_504 http_403 http_404 http_429;
upstream 192.168.16.193 {
server 192.168.16.10 weight=2 max_fails=2 fail_timeout=10s;
server 192.168.16.11 weight=1 max_fails=2 fail_timeout=10s;
zone upstream_webgroup 1024k;
ip_hash;
}

#gzip on;
server {
server {
listen 80;
server_name proxy-server180;

location / {
rewrite ^(.*)$ https://$host$1 permanent;
#proxy_pass http://192.168.16.193;
}
}

# HTTPS server
server {
listen 443 ssl;
server_name proxy-server1 ;

ssl_certificate /etc/nginx/ssl/nginx.crt;
ssl_certificate_key /etc/nginx/ssl/nginx.key;

location / {
proxy_pass http://192.168.16.193;
proxy_read_timeout 120s;
proxy_send_timeout 120s;
proxy_set_header Host $host;
proxy_set_header Real-Client-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location ~* \.(gif|jpg|jpeg|png|gif|css|js|html|htm)$ {
proxy_pass http://192.168.16.193;
proxy_cache proxy-cache;
proxy_cache_key $scheme$proxy_host$request_uri;
proxy_cache_valid 200 302 10m;
proxy_cache_valid 404 1m;
proxy_cache_use_stale error;
}
location /basic_status {
stub_status;
}
}
}

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

二 部署 keepalived

   node4(192.168.16.64)为masger,node5(192.168.16.65)为backup 
按 如下步奏部署keepalived
1、setenforce Permissive    //关闭SELinux
2、yum install keepalived
3、通过 vrrp_script 动态检测 nginx 进程判断主机健康状态,VIP:192.168.16.69
配置文件keepalived.conf 如下

———————————–keepalived.conf———————————————————-
! Configuration File for keepalived

global_defs {
notification_email {
suzb@clo.com.cn
}
notification_email_from keepalived@clo.com
smtp_server 192.268.101.12
smtp_connect_timeout 30
router_id node06
vrrp_mcast_group4 224.0.16.18
# vrrp_skip_check_adv_addr
# vrrp_strict
# vrrp_garp_interval 0
# vrrp_gna_interval 0
}

vrrp_script chk_httpd {
script “killall -0 nginx”
interval 2
weight -5
}

vrrp_instance VI_1 {
state MASTER|BACKUP
interface ens32
virtual_router_id 60
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123
}
virtual_ipaddress {
192.168.16.69/24 dev ens32
}
track_script
{
chk_httpd
}
notify_master “/etc/keepalived/keepalived-notify.sh master”
notify_backup “/etc/keepalived/keepalived-notify.sh backup”
notify_fault “/etc/keepalived/keepalived-notify.sh fault”
}

—————————————————————————————–

 

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/90439

(3)
N27_abaoN27_abao
上一篇 2017-12-19
下一篇 2017-12-20

相关推荐

  • 脚本之循环的特殊用法及函数的使用

    一、本文主要时针对while for select循环结果的特殊用法进行讲解。     1、while循环的特殊用法                 while read…

    Linux干货 2016-08-21
  • 配额、RAID、软RAID以及LVM管理

    磁盘配额允许控制用户或者组织对磁盘的使用,它能防止个人或者组织使用文件系统中超过自己使用的部分,或者造成系统完全拥堵。配额必须由root用户或者具有root权限的用户启用和管理。 硬RAID以及软RAID :RAID是Redundant Array of Independent Disks的简写,即独立硬盘冗余阵列,简称磁盘阵列。通过实现的方式不同…

    Linux干货 2016-11-23
  • 计算机网络基础知识与Linux网络配置

    本文主要内容是: 1.讲述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别。 2、IP地址的分类有哪些?子网掩码的表示形式及其作用 3、计算机网络的分成模型有哪些(OSI模型和TCP/IP模型),每一层的功能及涉及到的物理设备有哪些。 4、如何给网络接口配置多个地址,有哪些方式? 5、常用的网络管理类工具有哪些,并用示例形式描述他们的使用方…

    Linux干货 2016-11-14
  • Linux用户、组、权限管理

    Linux用户与组管理 Linux系统上,用户通过内核拷贝程序到内存中,从此发起进程。进程以发起者的身份进行,进程对文件的访问权限,取决于发起进程的用户的权限。而有些后台进程或服务类进程以非管理员身份运行,为此也需要创建多个普通用户,此类用户不需登录。 系统中,用户类别分为管理员和普通用户(系统用户和登录用户),组类别分为基本组和附加组。管理系统上的用户与组…

    Linux干货 2016-12-07
  • RAID概述

    1、引言 RAID全称Redundant Arrays of Inexpensive Disks / Redundant Arrays of Independent Disks,即独立冗余磁盘阵列。RAID可以通过相关技术(软件/硬件),将多个较小的磁盘整合成为一个较大的磁盘整体,而且能从某些方面提高数据的读写及数据保护。RAID分为不同…

    Linux干货 2016-12-24
  • 下载编译安装httpd 2.4最新版本

    关于这个问题分三步讲:1.下载最新版本;2.编译;3.安装 一:下载httpd 2.4的最新版本:(这里以Centos 7为例,Centos 6里用的是2.2版本的) 下载的话如何找下载路径—–>下载后是存在windows下,如何将其移进linux中  1.下载路径: 当然我们现在只要是碰到不会或者不知道的东西,通常会…

    2017-08-26