search
HomeBackend DevelopmentPHP Tutorialnginx+keepalived high availability load balancing

Not much to say, nginx installation and configuration, as well as load balancing, you can read another article I wrote "nginx Load Balancing in Practice", and about load balancing, you can read another article I wrote Two articles, one is "lvs+keepalived load balancing" and the other is "haproxy+keepalived load balancing". For the difference between the three load balancing, you can take a look at an article I reprinted "Software Level Load Balancer (LVS)" /HAProxy/Nginx), let’s go directly to the configuration steps:

1. System environment

[plain] view plaincopy

  1. System version: CentOS release 5.9 (Final) x86 32-bit
  2. nginx version: 1.2.8
  3. keepalived version: 1.2 .4
  4. main keepalived: 192.168.207.130
  5. from keepalived:192.168.207.131
  6. VIP: 192.168.207.140
  7. WEB_1:192.168.207.129 Port 80
  8. WEB_2 :192.168.207.130 8080 port
  9. WEB_3:192.168.207.131 8080 port

2. Custom nginx configuration file


at 192.168.207 Operating on .130 and 192.168.207.131

[plain] view plaincopy

  1. useradd nginx
  2. vi /usr/local/nginx/conf/nginx.conf

The content is as follows:

[plain] view plaincopy

  1. #Run user                                                                                                                                                                              
  2. #Global error log and PID file
  3. error_log logs/error. log notification; epoll;
  4. worker_connections 1024; #So The total number of connections supported by nginx is equal to worker_processes * worker_connections
  5. }
  6. #Set the http server and use its reverse proxy function to provide load balancing support
  7. http {
  8. #Set the mime type
  9. include mime.types ; #This is about nginx Which multimedia types are supported? You can go to conf/mime.types to check which multimedia are supported.
  10. default_type application/octet-stream; #Default data type
  11. #Set log format
  12. Log_format main '$remote_addr - $remote_user [$time_local] ' '"$request" $status $bytes_sent ' '"$http_referer" "$http_user_agent" '​
  13. ​ '"$gzip_ratio"' ; ; ent ' '
  14. '"$http_referer" "$http_user_agent" '
  15. '"$http_range" "$sent_http_content_range"';
  16. large_client_header_buffers 4 4k;
  17. #Enable gzip module
  18.       #gzip on;                                                  gzip_types text/plain;
  19. #output_buffers 1 32k;
  20. #postpone_output 1460;
  21. #Setting access log
  22. access_log logs/access.log main;
  23. client_header_timeout 3m;
  24. client_body_timeout 3m;
  25. send_timeout 3m;
  26. sendfile on;
  27. tcp_nopush on;
  28. tcp_nodelay on;
  29. keepalive_timeout 65;
  30. #Set the load balancing server list
  31. upstream mysvr {
  32. #weigth parameter representation Weight, the higher the weight, the greater the chance of being assigned                                                                                                                                                                            weight=5; . Server 192.168.207.131:8080 weight = 5;
  33. }
  34. server {#This is set to set web service, monitor port 8080
  35. Listen 8080;
  36. server_name 192.168.207.131; #This changes according to the system ip
  37.                                                   ‐ ’ s ‐ ‐ ‐ ‐ ‐ ‐ ‐ ‐              page 500 502 503 504 /50x.html;
  38. # location = /50x.html {
  39. html;
  40.         #Set up virtual host                                                              A Server_name 192.168.207.140;#Here is VIP
  41. #Charset GB2312;
  42. #Set the visits log of this virtual host
  43. access_log Logs/Threeb.access.log Main;
  44.           #If you access /img/*, /js/*, /css/* resources, fetch local files directly, not through squid                                                   The cache effect is better l #Location ~^/(IMG | JS | CSS)/{
  45. #root/data3/html;
  46. #Expires 24h;
  47. #}#"/" Enable load balancing
  48. local/{
  49. proxy_pass http:// mysvr;#
  50.               proxy_set_header Host $host;                                             proxy_set_header                  proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; client_max_body_size 10m; client_body_buffer_ size 128k;
  51.            proxy_connect_timeout 90;                 proxy_read_timeout 90;                        proxy_buffer_size                             proxy_busy_buffers_size 64k;
  52.                                                                                                                                                  
  53. stub_status on;
  54. access_log on;
  55.                  auth_basic "NginxStatus";                                                                                                                                                             auth_basic    "NginxStatus";                                                                                                                                                                .Customize keepalived configuration file
  56. [plain] view plaincopy
  57. vi /etc/keepalived/keepalived.conf
  58. The content is as follows:
  59. [plain] view plaincopy
    1. global_defs {
    2. notification_email {
    3. root@localhost.localdomain }
    4. notification_email_from notify@keepalived.com
    5. smtp_server 127.0.0.1
    6. smtp_connect_timeout 30
    7. router_id LVS_DEVEL
    8. }
    9. vrrp_script chk_http_port {
    10.                script "/etc/keepalived/check_nginx.sh"                                                                                                                                        ##Monitoring time
    11.                                                                                                                                                                                                          Monitoring time VI_1 {
    12.                                                                                                     ,                    ### Monitoring network card
    13.                                                                     ’ s ‐         ‐   ‐ ‐ out of 101                                      The weight value MASTRE must be higher than BAUCKUP
    14. Auth_pass 1111}}
    15. track_script {
    16. chK_HTTP_PORT ###}}}
    17. virtual_ipaddress {
    18. 192.168.207.140 ### vip address
    19. View plaincopy
      1. vi /etc/keepalived/check_nginx.sh

      The content is as follows:

      [plain] view plaincopy

      1. !/bin/bash
      2. A = `ps -C nginx --no-header |wc -l`
      3. if [ $A -eq 0 ];then /usr/local/nginx/sbin/nginx
      4. if no process is worth zero
      5.                                                                                                                                                                                    sleep                                                                                 sleep                              -no-header |wc -l` -eq 0 ];then
      6.                                                                                                                                                                                                    
      7.                                                                                        Here is to check whether nginx has started. If it has not started, start nginx first. If it has not started after 3 seconds, the keepalived process will also be closed, so that keepalived can take over and provide high availability. Here, The keepalived service provides high availability, while nginx provides load balancing of back-end web servers.
      8. You also need to add execution permissions to the script, as follows
      9. [plain] view plaincopy
      10. chmod +x /etc/keepalived/check_nginx.sh
      5. Start the service and test
      Let me talk about it first. On WEB_1, I use the system auto I brought the apache web server last night, which is more trouble-free. In this case, I only need to start the master-slave keepalived, because it will use the check_nginx.sh script to automatically start nginx. Everything is started.
      Visit http://192.168.207.140 to access the content of the three back-end web servers in rotationHere we turn off the main keepalived service to test high availabilityThen it will be in /var/log/ on the slave keepalived server messages saw a log like this

      [plain] view plaincopy
      1. Apr 19 17:42:44 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE

      Apr 19 17:42:45 localhost Keepalived_vrrp : VRRP_Instance(VI_1) Entering MASTER STATE



      Apr 19 17:42:45 localhost Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.



      Apr 19 17:42:45 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.207.140

      Apr 19 17:42:45 localhost Keepalived_vrrp: Netlink reflector reports IP 192.168.207.140 added

      1. Apr 19 17:42:45 localhost Keepalived_healthcheckers: Netlink reflector reports IP 192.168. 207.140 added Apr 19 17:42:45 localhost avahi-daemon[4204]: Registering new address record for 192.168.207.140 on eth0.

      2. Continue to visit http://192.168.207.140, you can still access the three back-end web servers
        Then open the original owner keepalived, you can observe the log display of the original slave keepalived server

        [plain] view plaincopy

        1. Apr 19 17:42:50 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for 192.168.207.140
        2. Apr 1 9 17:44:06 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Received higher prio advert
        3. Apr 19 17:44:06 localhost Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
        4. Apr 19 17:44:06 localhost Keepalived_vrrp: VRRP_Instance (VI_1) removing protocol VIPs.
        5. Apr 19 17:44:06 localhost Keepalived_vrrp: Netlink reflector reports IP 192.168.207.140 removed
        6. Apr 19 17:44:06 localhost Keepalived_healthcheckers: Netlink reflector reports IP 192.168 .207.140 removed
        7. Apr 19 17:44:06 localhost avahi-daemon[4204]: Withdrawing address record for 192.168.207.140 on eth0.

        It means that the original master-slave result has been restored.
        In the production environment, the back-end machine may also hang up, but you don’t have to worry about it, nginx will automatically allocate the session to a good back-end web server

        ok, here you go It's all over, practice personal testing, I wish you success

        From: http://blog.csdn.net/zmj_88888888/article/details/8825471

        The above has introduced nginx+keepalived high-availability load balancing, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
解决方法:您的组织要求您更改 PIN 码解决方法:您的组织要求您更改 PIN 码Oct 04, 2023 pm 05:45 PM

“你的组织要求你更改PIN消息”将显示在登录屏幕上。当在使用基于组织的帐户设置的电脑上达到PIN过期限制时,就会发生这种情况,在该电脑上,他们可以控制个人设备。但是,如果您使用个人帐户设置了Windows,则理想情况下不应显示错误消息。虽然情况并非总是如此。大多数遇到错误的用户使用个人帐户报告。为什么我的组织要求我在Windows11上更改我的PIN?可能是您的帐户与组织相关联,您的主要方法应该是验证这一点。联系域管理员会有所帮助!此外,配置错误的本地策略设置或不正确的注册表项也可能导致错误。即

Windows 11 上调整窗口边框设置的方法:更改颜色和大小Windows 11 上调整窗口边框设置的方法:更改颜色和大小Sep 22, 2023 am 11:37 AM

Windows11将清新优雅的设计带到了最前沿;现代界面允许您个性化和更改最精细的细节,例如窗口边框。在本指南中,我们将讨论分步说明,以帮助您在Windows操作系统中创建反映您的风格的环境。如何更改窗口边框设置?按+打开“设置”应用。WindowsI转到个性化,然后单击颜色设置。颜色更改窗口边框设置窗口11“宽度=”643“高度=”500“>找到在标题栏和窗口边框上显示强调色选项,然后切换它旁边的开关。若要在“开始”菜单和任务栏上显示主题色,请打开“在开始”菜单和任务栏上显示主题

如何在 Windows 11 上更改标题栏颜色?如何在 Windows 11 上更改标题栏颜色?Sep 14, 2023 pm 03:33 PM

默认情况下,Windows11上的标题栏颜色取决于您选择的深色/浅色主题。但是,您可以将其更改为所需的任何颜色。在本指南中,我们将讨论三种方法的分步说明,以更改它并个性化您的桌面体验,使其具有视觉吸引力。是否可以更改活动和非活动窗口的标题栏颜色?是的,您可以使用“设置”应用更改活动窗口的标题栏颜色,也可以使用注册表编辑器更改非活动窗口的标题栏颜色。若要了解这些步骤,请转到下一部分。如何在Windows11中更改标题栏的颜色?1.使用“设置”应用按+打开设置窗口。WindowsI前往“个性化”,然

OOBELANGUAGE错误Windows 11 / 10修复中出现问题的问题OOBELANGUAGE错误Windows 11 / 10修复中出现问题的问题Jul 16, 2023 pm 03:29 PM

您是否在Windows安装程序页面上看到“出现问题”以及“OOBELANGUAGE”语句?Windows的安装有时会因此类错误而停止。OOBE表示开箱即用的体验。正如错误提示所表示的那样,这是与OOBE语言选择相关的问题。没有什么可担心的,你可以通过OOBE屏幕本身的漂亮注册表编辑来解决这个问题。快速修复–1.单击OOBE应用底部的“重试”按钮。这将继续进行该过程,而不会再打嗝。2.使用电源按钮强制关闭系统。系统重新启动后,OOBE应继续。3.断开系统与互联网的连接。在脱机模式下完成OOBE的所

Windows 11 上启用或禁用任务栏缩略图预览的方法Windows 11 上启用或禁用任务栏缩略图预览的方法Sep 15, 2023 pm 03:57 PM

任务栏缩略图可能很有趣,但它们也可能分散注意力或烦人。考虑到您将鼠标悬停在该区域的频率,您可能无意中关闭了重要窗口几次。另一个缺点是它使用更多的系统资源,因此,如果您一直在寻找一种提高资源效率的方法,我们将向您展示如何禁用它。不过,如果您的硬件规格可以处理它并且您喜欢预览版,则可以启用它。如何在Windows11中启用任务栏缩略图预览?1.使用“设置”应用点击键并单击设置。Windows单击系统,然后选择关于。点击高级系统设置。导航到“高级”选项卡,然后选择“性能”下的“设置”。在“视觉效果”选

Windows 11 上的显示缩放比例调整指南Windows 11 上的显示缩放比例调整指南Sep 19, 2023 pm 06:45 PM

在Windows11上的显示缩放方面,我们都有不同的偏好。有些人喜欢大图标,有些人喜欢小图标。但是,我们都同意拥有正确的缩放比例很重要。字体缩放不良或图像过度缩放可能是工作时真正的生产力杀手,因此您需要知道如何对其进行自定义以充分利用系统功能。自定义缩放的优点:对于难以阅读屏幕上的文本的人来说,这是一个有用的功能。它可以帮助您一次在屏幕上查看更多内容。您可以创建仅适用于某些监视器和应用程序的自定义扩展配置文件。可以帮助提高低端硬件的性能。它使您可以更好地控制屏幕上的内容。如何在Windows11

10种在 Windows 11 上调整亮度的方法10种在 Windows 11 上调整亮度的方法Dec 18, 2023 pm 02:21 PM

屏幕亮度是使用现代计算设备不可或缺的一部分,尤其是当您长时间注视屏幕时。它可以帮助您减轻眼睛疲劳,提高易读性,并轻松有效地查看内容。但是,根据您的设置,有时很难管理亮度,尤其是在具有新UI更改的Windows11上。如果您在调整亮度时遇到问题,以下是在Windows11上管理亮度的所有方法。如何在Windows11上更改亮度[10种方式解释]单显示器用户可以使用以下方法在Windows11上调整亮度。这包括使用单个显示器的台式机系统以及笔记本电脑。让我们开始吧。方法1:使用操作中心操作中心是访问

如何修复Windows服务器中的激活错误代码0xc004f069如何修复Windows服务器中的激活错误代码0xc004f069Jul 22, 2023 am 09:49 AM

Windows上的激活过程有时会突然转向显示包含此错误代码0xc004f069的错误消息。虽然激活过程已经联机,但一些运行WindowsServer的旧系统可能会遇到此问题。通过这些初步检查,如果这些检查不能帮助您激活系统,请跳转到主要解决方案以解决问题。解决方法–关闭错误消息和激活窗口。然后,重新启动计算机。再次从头开始重试Windows激活过程。修复1–从终端激活从cmd终端激活WindowsServerEdition系统。阶段–1检查Windows服务器版本您必须检查您使用的是哪种类型的W

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.