keepalived+nginx安装配置
- 软件版本号:
- pcre8.36 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
- keepalived1.2.19
- http://www.keepalived.org/software/keepalived-1.2.19.tar.gz
- nginx1.8.0
- http://nginx.org/download/nginx-1.8.0.tar.gz<pre name="code" class="html"><pre name="code" class="html">安装步骤
- 安装pcre
- tar -zxvf pcre-8.36.tar.gz
- cd pcre-8.36
- ./configure --prefix=/usr/local/pcre
- make && make install
- 安装keepalived
- tar -zxvf keepalived-1.2.19.tar.gz
- cd keepalived-1.2.19
- ./configure --prefix=/usr/local/keepalived
- make && make install
- cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
- cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
- mkdir –pv /etc/keepalived
- cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
- ln -s /usr/local/keepalived/sbin/keepalived /sbin/
- chkconfig keepalived on
- 安装nginx
- tar -zxvf nginx-1.8.0.tar.gz
- cd nginx-1.8.0
- ./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre/
- make && make install
- <strong><span style="font-size:18px;">启动和停止</span></strong>
- Nginx:
- 启动:进入到安装之后${nginx}的sbin文件夹。运行./nginx
- 停止:./nginx –s stop
- 检查是否成功安装:进入到安装之后${nginx}的sbin文件夹,运行./nginx -t
- Keepalived
- 启动:service keepalived start
- 停止:service keepalived stop
- <strong><span style="font-size:18px;">配置</span></strong>
- 配置Keepalived
- 主备keepalived的配置大致同样,不同之处在于state和priority。
- 例如以下所看到的:
- ! Configuration File for keepalived
- #配置报警邮件
- global_defs {
- notification_email {
- acassen@firewall.loc
- }
- notification_email_from Alexandre.Cassen@firewall.loc
- smtp_server 192.168.200.1
- smtp_connect_timeout 30
- router_id LVS_DEVEL
- }
- #配置keepalived服务器实例
- vrrp_instance VI_1 {#VI_1为名称
- state MASTER #MASTER为主服务器。BACKUP为备用服务器
- interface p2p1 #p2p1为网卡标志
- virtual_router_id 51 #51为默认值
- priority 100 #主服务器的优先级要大于备服务器
- advert_int 1 #1为默认值
- authentication {#认证,採用默认值就可以
- auth_type PASS
- auth_pass 1111
- }
- virtual_ipaddress {#对外提供的虚拟IP,不能与现有IP冲突
- 200.31.157.243
- }
- }
- 配置Nginx
- Nginx的基本配置例如以下所看到的:
- #user nobody; #username称
- worker_processes auto; #处理进程个数,一般为自己主动分配
- error_log logs/error.log; #错误日志记录位置
- #error_log logs/error.log notice; #notice/info等为记录错误的级别
- #error_log logs/error.log info;
- pid logs/nginx.pid; #进程记录文件
- events {
- worker_connections 5120; #可处理的连接数,最大处理能力为processes×connections
- }
- http {
- include mime.types;
- default_type application/octet-stream;
- #配置日志格式(main为自己定义格式名称)
- log_format main '$remote_addr - $remote_user [$time_local] "$request" '
- '$status $body_bytes_sent "$http_referer" '
- '"$http_user_agent" "$http_x_forwarded_for"';
- #access_log logs/access.log main; #日志文件位置
- keepalive_timeout 65; #连接超时时间
- proxy_connect_timeout 10; #后台服务器响应超时时间
- #配置反向代理
- upstream tomcat{ #tomcat为名称
- server 200.31.157.116:8090 weight=1; #后台服务器的地址以及port号。weight为权重
- server 200.31.157.117:8090 weight=1;
- }
- #配置负载均衡,Server为nginx服务器
- upstream nginx{
- server 200.31.157.116:8084 weight=1;
- server 200.31.157.117:8084 weight=1;
- }
- #配置处理请求Server
- server{
- listen 8084; #监听的port号
- server_name 200.31.157.243; #自己定义服务名称,不能与其他Server有冲突
- #charset koi8-r; #定义字符集
- #access_log logs/host.access.log main; #定义日志名称与日志格式(main)
- #设定訪问处理规则。假设路径以/cwap开头,则通过下面规则进行处理
- location /cwap {
- proxy_pass http://tomcat; #反向代理到tomcat服务器该处的tomcat为upstream名称
- proxy_redirect off;
- proxy_set_header Host $host; #下面是读取訪问IP
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- }
- location / {
- root html; #根文件夹
- index index.html index.htm;
- }
- #error_page 404 /404.html; #配置错误页面
- # redirect server error pages to the static page /50x.html
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- }
- server{
- listen 80;
- server_name localhost;
- access_log logs/access.log main;
- location /cwap {
- proxy_pass http://nginx;
- proxy_redirect off;
- proxy_set_header Host $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
- }
- location / {
- root html;
- index index.html index.htm;
- #expires 1d; #页面缓存时间
- }
- error_page 404 /404.html;
- # redirect server error pages to the static page /50x.html
- error_page 500 502 503 504 /50x.html;
- location = /50x.html {
- root html;
- }
- }
- }
- <strong><span style="font-size:18px;">负载均衡</span></strong>
- nginx 的 upstream眼下支持 4 种方式的分配
- 轮询(默认)
- 每一个请求按时间顺序逐一分配到不同的后端服务器,假设后端服务器down掉。能自己主动剔除。
- weight
- 定轮询几率。weight和訪问比率成正比,用于后端服务器性能不均的情况。
- ip_hash
- 每一个请求按訪问ip的hash结果分配,这样每一个訪客固定訪问一个后端服务器。能够解决session的问题。
- fair(第三方)
- 按后端服务器的响应时间来分配请求。响应时间短的优先分配。
- 在http中upstream配置中,clouder是起的负载均衡服务器或者反向代理的名称。
- upstream clouder {
- #ip_hash;
- #least_conn;
- server 200.31.157.116:8090;
- server 200.31.157.116:9090 down; #表示当前server临时不參与负载
- server 200.31.157.117:8090 weight=2; #默觉得1,weight越大,负载的权重越大
- #其他全部非backup机器down或忙时。请求backup机器。所以这台机器压力会最轻
- server 200.31.157.117:9090 backup;
- <span style="white-space:pre"> </span>server 200.31.157.117:8084 fail_timeout=10s; #失败后的暂停时间
- <span style="white-space:pre"> </span>#最大失败次数为2,失败后暂停时间为10
- server 200.31.157.117:8083 max_fails=2 fail_timeout=10s;
- }
keepalived+nginx安装配置的更多相关文章
- LVS+Nginx(LVS + Keepalived + Nginx安装及配置)
(也可以每个nginx都挂在上所有的应用服务器) nginx大家都在用,估计也很熟悉了,在做负载均衡时很好用,安装简单.配置简单.相关材料也特别多. lvs是国内的章文嵩博士的大作,比nginx被广 ...
- Nginx安装配置(转)
Nginx 安装配置 Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/ ...
- Nginx安装配置PHP(FastCGI)环境的教程
这篇是Nginx安装配置PHP(FastCGI)环境的教程.Nginx不支持对外部程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用. 一.什么是 FastCGI F ...
- Nginx安装配置与HelloWorld
<深入理解Nginx>阅读与实践(一):Nginx安装配置与HelloWorld 最近在读陶辉的<深入理解Nginx:模块开发与架构解析>,一是想跟着大牛练练阅读和编写开源代码 ...
- Nginx 安装 配置 使用
Nginx 安装 配置 使用 基本的HTTP服务器特性 处理静态文件,索引文件以及自动索引:打开文件描述符缓存(缓存元数据和文件描述符,下一次可以直接从内存找到数据或者文件的位置): 使用缓存加速反向 ...
- VMware Linux 下 Nginx 安装配置 - nginx.conf 配置 [负载两个 Tomcat] (三)
首先启动Nginx 1. 相关浏览 两个 Tomcat 配置: VMware Linux 下 Nginx 安装配置 - Tomcat 配置 (二) Nginx 安装配置启动: VMware Linu ...
- VMware Linux 下 Nginx 安装配置 - Tomcat 配置 (二)
准备工作 相关浏览: VMware Linux 下 Nginx 安装配置 (一) 1. 选在 /usr/local/ 下创建 softs 文件夹,通过 ftp 命令 把 apache-tomcat-7 ...
- Hearbeat + Nginx 安装配置
Hearbeat + Nginx 安装配置 实验环境 两台主机:Linux Centos 6.5 32位 主 服务端:Hearbeat + Nginx eth0:192.168.1.160(公网) e ...
- Nginx安装配置|Nginx反向代理|Nginx支持HTTPS|Nginx重定向
Nginx安装配置 可以直接看到最下面的HTTPS. Nginx安装 我的系统如下: No LSB modules are available. Distributor ID: Ubuntu Desc ...
随机推荐
- jstree的基本使用例子
var menu = (function() { var _menu = {data:{}, initMenu : function() { $.jstree.defaults.core.themes ...
- 并发编程学习笔记(10)----并发工具类CyclicBarrier、Semaphore和Exchanger类的使用和原理
在jdk中,为并发编程提供了CyclicBarrier(栅栏),CountDownLatch(闭锁),Semaphore(信号量),Exchanger(数据交换)等工具类,我们在前面的学习中已经学习并 ...
- Flask框架 之重定向、cookie和session
一.URL重定向(redirect) @app.route("/login") def login(): # 使用url_for函数通过视图函数的名字找到url路径 url = u ...
- pageHelper详解
详见:https://github.com/pagehelper/Mybatis-PageHelper/edit/master/wikis/zh/HowToUse.md ## 使用方法 1. 引入分页 ...
- JavaScipt30(第三个案例)(主要知识点:css变量)
承接上文 https://www.cnblogs.com/wangxi01/p/10641210.html,下面是第三个案例: 附上项目链接: https://github.com/wesbos/Ja ...
- ThinkPHP---TP功能类之公文管理功能2----------继续完善
[前言] 之前已经完成了公文的添加和列表展示功能,今天继续完善.做下公文的编辑和删除功能. [主体] (1)分析 控制器:DocController.class.php 方法:edit(将模板展示和数 ...
- jsp中的basePath,获取应用的路径
1 2 3 4 5 String path = request.getContextPath(); String basePath = request.getScheme()+": ...
- [HNOI]2003 消防局的建立
消防局的建立 本题地址:http://www.luogu.org/problem/show?pid=2279 题目描述 2020年,人类在火星上建立了一个庞大的基地群,总共有n个基地.起初为了节约材料 ...
- MySQL异常:com.mysql.jdbc.PacketTooBigException: Packet for query is too large
### Cause: com.mysql.jdbc.PacketTooBigException: Packet for query is too large (1169 > 1024). You ...
- 【转】Flex 布局
网页布局(layout)是CSS的一个重点应用. 布局的传统解决方案,基于盒状模型,依赖 display属性 + position属性 + float属性.它对于那些特殊布局非常不方便,比如,垂直居中 ...