1. 软件版本号:
  2. pcre8.36 ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.36.tar.gz
  3. keepalived1.2.19
  4. http://www.keepalived.org/software/keepalived-1.2.19.tar.gz
  5. nginx1.8.0
  6. http://nginx.org/download/nginx-1.8.0.tar.gz<pre name="code" class="html"><pre name="code" class="html">安装步骤
  7. 安装pcre
  8. tar -zxvf pcre-8.36.tar.gz
  9. cd pcre-8.36
  10. ./configure --prefix=/usr/local/pcre
  11. make && make install
  12. 安装keepalived
  13. tar -zxvf keepalived-1.2.19.tar.gz
  14. cd keepalived-1.2.19
  15. ./configure --prefix=/usr/local/keepalived
  16. make && make install
  17. cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
  18. cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
  19. mkdir pv /etc/keepalived
  20. cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
  21. ln -s /usr/local/keepalived/sbin/keepalived /sbin/
  22. chkconfig keepalived on
  23. 安装nginx
  24. tar -zxvf nginx-1.8.0.tar.gz
  25. cd nginx-1.8.0
  26. ./configure --prefix=/usr/local/nginx --with-pcre=/usr/local/pcre/
  27. make && make install
  1.  
  1. <strong><span style="font-size:18px;">启动和停止</span></strong>
  2. Nginx:
  3. 启动:进入到安装之后${nginx}的sbin文件夹。运行./nginx
  4. 停止:./nginx –s stop
  5. 检查是否成功安装:进入到安装之后${nginx}的sbin文件夹,运行./nginx -t
  6.  
  7. Keepalived
  8. 启动:service keepalived start
  9. 停止:service keepalived stop
  10.  
  11. <strong><span style="font-size:18px;">配置</span></strong>
  12. 配置Keepalived
  13. 主备keepalived的配置大致同样,不同之处在于state和priority。
  14.  
  15. 例如以下所看到的:
  16. ! Configuration File for keepalived
  17. #配置报警邮件
  18. global_defs {
  19. notification_email {
  20. acassen@firewall.loc
  21. }
  22. notification_email_from Alexandre.Cassen@firewall.loc
  23. smtp_server 192.168.200.1
  24. smtp_connect_timeout 30
  25. router_id LVS_DEVEL
  26. }
  27. #配置keepalived服务器实例
  28. vrrp_instance VI_1 {#VI_1为名称
  29. state MASTER #MASTER为主服务器。BACKUP为备用服务器
  30. interface p2p1 #p2p1为网卡标志
  31. virtual_router_id 51 #51为默认值
  32. priority 100 #主服务器的优先级要大于备服务器
  33. advert_int 1 #1为默认值
  34. authentication {#认证,採用默认值就可以
  35. auth_type PASS
  36. auth_pass 1111
  37. }
  38. virtual_ipaddress {#对外提供的虚拟IP,不能与现有IP冲突
  39. 200.31.157.243
  40. }
  41. }
  1. 配置Nginx
  2. Nginx的基本配置例如以下所看到的:
  3. #user nobody; #username称
  4. worker_processes auto; #处理进程个数,一般为自己主动分配
  5. error_log logs/error.log; #错误日志记录位置
  6. #error_log logs/error.log notice; #notice/info等为记录错误的级别
  7. #error_log logs/error.log info;
  8. pid logs/nginx.pid; #进程记录文件
  9.  
  10. events {
  11. worker_connections 5120; #可处理的连接数,最大处理能力为processes×connections
  12. }
  13.  
  14. http {
  15. include mime.types;
  16. default_type application/octet-stream;
  17. #配置日志格式(main为自己定义格式名称)
  18. log_format main '$remote_addr - $remote_user [$time_local] "$request" '
  19. '$status $body_bytes_sent "$http_referer" '
  20. '"$http_user_agent" "$http_x_forwarded_for"';
  21. #access_log logs/access.log main; #日志文件位置
  22. keepalive_timeout 65; #连接超时时间
  23. proxy_connect_timeout 10; #后台服务器响应超时时间
  24.  
  25. #配置反向代理
  26. upstream tomcat{ #tomcat为名称
  27. server 200.31.157.116:8090 weight=1; #后台服务器的地址以及port号。weight为权重
  28. server 200.31.157.117:8090 weight=1;
  29. }
  30.  
  31. #配置负载均衡,Server为nginx服务器
  32. upstream nginx{
  33. server 200.31.157.116:8084 weight=1;
  34. server 200.31.157.117:8084 weight=1;
  35. }
  36.  
  37. #配置处理请求Server
  38. server{
  39. listen 8084; #监听的port号
  40. server_name 200.31.157.243; #自己定义服务名称,不能与其他Server有冲突
  41. #charset koi8-r; #定义字符集
  42. #access_log logs/host.access.log main; #定义日志名称与日志格式(main)
  43.  
  44. #设定訪问处理规则。假设路径以/cwap开头,则通过下面规则进行处理
  45. location /cwap {
  46. proxy_pass http://tomcat; #反向代理到tomcat服务器该处的tomcat为upstream名称
  47. proxy_redirect off;
  48. proxy_set_header Host $host; #下面是读取訪问IP
  49. proxy_set_header X-Real-IP $remote_addr;
  50. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  51. }
  52.  
  53. location / {
  54. root html; #根文件夹
  55. index index.html index.htm;
  56. }
  57. #error_page 404 /404.html; #配置错误页面
  58.  
  59. # redirect server error pages to the static page /50x.html
  60. error_page 500 502 503 504 /50x.html;
  61. location = /50x.html {
  62. root html;
  63. }
  64. }
  65. server{
  66. listen 80;
  67. server_name localhost;
  68. access_log logs/access.log main;
  69. location /cwap {
  70. proxy_pass http://nginx;
  71. proxy_redirect off;
  72. proxy_set_header Host $host;
  73. proxy_set_header X-Real-IP $remote_addr;
  74. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  75. }
  76.  
  77. location / {
  78. root html;
  79. index index.html index.htm;
  80. #expires 1d; #页面缓存时间
  81. }
  82. error_page 404 /404.html;
  83.  
  84. # redirect server error pages to the static page /50x.html
  85. error_page 500 502 503 504 /50x.html;
  86. location = /50x.html {
  87. root html;
  88. }
  89. }
  90. }
  91.  
  92. <strong><span style="font-size:18px;">负载均衡</span></strong>
  93. nginx upstream眼下支持 4 种方式的分配
  94. 轮询(默认)
  95. 每一个请求按时间顺序逐一分配到不同的后端服务器,假设后端服务器down掉。能自己主动剔除。
  96.  
  97. weight
  98. 定轮询几率。weight和訪问比率成正比,用于后端服务器性能不均的情况。
  99. ip_hash
  100. 每一个请求按訪问iphash结果分配,这样每一个訪客固定訪问一个后端服务器。能够解决session的问题。
  101. fair(第三方)
  102. 按后端服务器的响应时间来分配请求。响应时间短的优先分配。
  103.  
  104. httpupstream配置中,clouder是起的负载均衡服务器或者反向代理的名称。
  105.  
  106. upstream clouder {
  107. #ip_hash;
  108. #least_conn;
  109. server 200.31.157.116:8090;
  110. server 200.31.157.116:9090 down; #表示当前server临时不參与负载
  111. server 200.31.157.117:8090 weight=2; #默觉得1,weight越大,负载的权重越大
  112. #其他全部非backup机器down或忙时。请求backup机器。所以这台机器压力会最轻
  113. server 200.31.157.117:9090 backup;
  114. <span style="white-space:pre"> </span>server 200.31.157.117:8084 fail_timeout=10s; #失败后的暂停时间
  115. <span style="white-space:pre"> </span>#最大失败次数为2,失败后暂停时间为10
  116. server 200.31.157.117:8083 max_fails=2 fail_timeout=10s;
  117. }

keepalived+nginx安装配置的更多相关文章

  1. LVS+Nginx(LVS + Keepalived + Nginx安装及配置)

    (也可以每个nginx都挂在上所有的应用服务器)  nginx大家都在用,估计也很熟悉了,在做负载均衡时很好用,安装简单.配置简单.相关材料也特别多. lvs是国内的章文嵩博士的大作,比nginx被广 ...

  2. Nginx安装配置(转)

    Nginx 安装配置 Nginx("engine x")是一款是由俄罗斯的程序设计师Igor Sysoev所开发高性能的 Web和 反向代理 服务器,也是一个 IMAP/POP3/ ...

  3. Nginx安装配置PHP(FastCGI)环境的教程

    这篇是Nginx安装配置PHP(FastCGI)环境的教程.Nginx不支持对外部程序的直接调用或者解析,所有的外部程序(包括PHP)必须通过FastCGI接口来调用. 一.什么是 FastCGI F ...

  4. Nginx安装配置与HelloWorld

    <深入理解Nginx>阅读与实践(一):Nginx安装配置与HelloWorld 最近在读陶辉的<深入理解Nginx:模块开发与架构解析>,一是想跟着大牛练练阅读和编写开源代码 ...

  5. Nginx 安装 配置 使用

    Nginx 安装 配置 使用 基本的HTTP服务器特性 处理静态文件,索引文件以及自动索引:打开文件描述符缓存(缓存元数据和文件描述符,下一次可以直接从内存找到数据或者文件的位置): 使用缓存加速反向 ...

  6. VMware Linux 下 Nginx 安装配置 - nginx.conf 配置 [负载两个 Tomcat] (三)

    首先启动Nginx 1. 相关浏览 两个 Tomcat 配置:  VMware Linux 下 Nginx 安装配置 - Tomcat 配置 (二) Nginx 安装配置启动: VMware Linu ...

  7. VMware Linux 下 Nginx 安装配置 - Tomcat 配置 (二)

    准备工作 相关浏览: VMware Linux 下 Nginx 安装配置 (一) 1. 选在 /usr/local/ 下创建 softs 文件夹,通过 ftp 命令 把 apache-tomcat-7 ...

  8. Hearbeat + Nginx 安装配置

    Hearbeat + Nginx 安装配置 实验环境 两台主机:Linux Centos 6.5 32位 主 服务端:Hearbeat + Nginx eth0:192.168.1.160(公网) e ...

  9. Nginx安装配置|Nginx反向代理|Nginx支持HTTPS|Nginx重定向

    Nginx安装配置 可以直接看到最下面的HTTPS. Nginx安装 我的系统如下: No LSB modules are available. Distributor ID: Ubuntu Desc ...

随机推荐

  1. jstree的基本使用例子

    var menu = (function() { var _menu = {data:{}, initMenu : function() { $.jstree.defaults.core.themes ...

  2. 并发编程学习笔记(10)----并发工具类CyclicBarrier、Semaphore和Exchanger类的使用和原理

    在jdk中,为并发编程提供了CyclicBarrier(栅栏),CountDownLatch(闭锁),Semaphore(信号量),Exchanger(数据交换)等工具类,我们在前面的学习中已经学习并 ...

  3. Flask框架 之重定向、cookie和session

    一.URL重定向(redirect) @app.route("/login") def login(): # 使用url_for函数通过视图函数的名字找到url路径 url = u ...

  4. pageHelper详解

    详见:https://github.com/pagehelper/Mybatis-PageHelper/edit/master/wikis/zh/HowToUse.md ## 使用方法 1. 引入分页 ...

  5. JavaScipt30(第三个案例)(主要知识点:css变量)

    承接上文 https://www.cnblogs.com/wangxi01/p/10641210.html,下面是第三个案例: 附上项目链接: https://github.com/wesbos/Ja ...

  6. ThinkPHP---TP功能类之公文管理功能2----------继续完善

    [前言] 之前已经完成了公文的添加和列表展示功能,今天继续完善.做下公文的编辑和删除功能. [主体] (1)分析 控制器:DocController.class.php 方法:edit(将模板展示和数 ...

  7. jsp中的basePath,获取应用的路径

    1 2 3 4 5 String path = request.getContextPath();      String basePath = request.getScheme()+": ...

  8. [HNOI]2003 消防局的建立

    消防局的建立 本题地址:http://www.luogu.org/problem/show?pid=2279 题目描述 2020年,人类在火星上建立了一个庞大的基地群,总共有n个基地.起初为了节约材料 ...

  9. 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 ...

  10. 【转】Flex 布局

    网页布局(layout)是CSS的一个重点应用. 布局的传统解决方案,基于盒状模型,依赖 display属性 + position属性 + float属性.它对于那些特殊布局非常不方便,比如,垂直居中 ...