apache Proxy 4 秒連接延遲
我有一個大數據網站(wordpress 二次開發)一個域 www.example.com。我已將其儲存到 3 個伺服器中。
In DNS setteing IP address (IN A / AAAA) 46.192.22.01 IP address (IN A / AAAA) 46.192.22.02 IP address (IN A / AAAA) 46.192.22.03
- server1 46.192.22.01 /var/www/html -> /music & /video
- server2 46.192.22.02 /var/www/html -> /article & /photo
- server3 46.192.22.03 /var/www/html -> /products & /showroom
httpd.conf 文件:
Timeout 45 KeepAlive Off MaxKeepAliveRequests 256 KeepAliveTimeout 3 <IfModule prefork.c> StartServers 8 MinSpareServers 5 MaxSpareServers 20 ServerLimit 192 MaxClients 192 MaxRequestsPerChild 2500 </IfModule> LoadModule auth_basic_module modules/mod_auth_basic.so #LoadModule auth_digest_module modules/mod_auth_digest.so LoadModule authn_file_module modules/mod_authn_file.so LoadModule authn_alias_module modules/mod_authn_alias.so #LoadModule authn_anon_module modules/mod_authn_anon.so LoadModule authn_dbm_module modules/mod_authn_dbm.so LoadModule authn_default_module modules/mod_authn_default.so LoadModule authz_host_module modules/mod_authz_host.so LoadModule authz_user_module modules/mod_authz_user.so #LoadModule authz_owner_module modules/mod_authz_owner.so LoadModule authz_groupfile_module modules/mod_authz_groupfile.so #LoadModule authz_dbm_module modules/mod_authz_dbm.so LoadModule authz_default_module modules/mod_authz_default.so #LoadModule ldap_module modules/mod_ldap.so #LoadModule authnz_ldap_module modules/mod_authnz_ldap.so LoadModule include_module modules/mod_include.so LoadModule log_config_module modules/mod_log_config.so #LoadModule logio_module modules/mod_logio.so LoadModule env_module modules/mod_env.so #LoadModule ext_filter_module modules/mod_ext_filter.so #LoadModule mime_magic_module modules/mod_mime_magic.so LoadModule expires_module modules/mod_expires.so LoadModule deflate_module modules/mod_deflate.so LoadModule headers_module modules/mod_headers.so #LoadModule usertrack_module modules/mod_usertrack.so LoadModule setenvif_module modules/mod_setenvif.so LoadModule mime_module modules/mod_mime.so #LoadModule dav_module modules/mod_dav.so #LoadModule status_module modules/mod_status.so LoadModule autoindex_module modules/mod_autoindex.so #LoadModule info_module modules/mod_info.so #LoadModule dav_fs_module modules/mod_dav_fs.so LoadModule vhost_alias_module modules/mod_vhost_alias.so LoadModule negotiation_module modules/mod_negotiation.so LoadModule dir_module modules/mod_dir.so LoadModule actions_module modules/mod_actions.so #LoadModule speling_module modules/mod_speling.so LoadModule userdir_module modules/mod_userdir.so LoadModule alias_module modules/mod_alias.so #LoadModule substitute_module modules/mod_substitute.so LoadModule rewrite_module modules/mod_rewrite.so LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_balancer_module modules/mod_proxy_balancer.so LoadModule proxy_ftp_module modules/mod_proxy_ftp.so LoadModule proxy_http_module modules/mod_proxy_http.so #LoadModule proxy_ajp_module modules/mod_proxy_ajp.so LoadModule proxy_connect_module modules/mod_proxy_connect.so LoadModule cache_module modules/mod_cache.so LoadModule suexec_module modules/mod_suexec.so LoadModule disk_cache_module modules/mod_disk_cache.so LoadModule cgi_module modules/mod_cgi.so #LoadModule version_module modules/mod_version.so ExpiresActive On <FilesMatch "\.(jpg|jpeg)$"> ExpiresDefault "access plus 1 year" </FilesMatch> <FilesMatch "\.(css|png|js|gif)$"> ExpiresDefault "access plus 1 month" </FilesMatch> <ifmodule mod_deflate.c> DeflateCompressionLevel 6 AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE text/javascript AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/atom_xml AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE application/x-httpd-php </ifmodule>
伺服器 1
ServerName www.example.com:80 <VirtualHost *:80> ServerName www.example.com ServerAlias www.example.com DocumentRoot /var/www/html <directory "/var/www/html"> Options Indexes FollowSymLinks AllowOverride all Order Deny,Allow Deny from all Allow from all </directory> <Proxy *> Order deny,allow Allow from all </Proxy> ProxyRequests Off ProxyPass /article http://46.192.22.02/article retry=1 acquire=3000 timeout=600 Keepalive=On ProxyPassReverse /article http://46.192.22.02/article ProxyPass /photo http://46.192.22.02/photo retry=1 acquire=3000 timeout=600 Keepalive=On ProxyPassReverse /photo http://46.192.22.02/photo ProxyPass /products http://46.192.22.03/products retry=1 acquire=3000 timeout=600 Keepalive=On ProxyPassReverse /products http://46.192.22.03/products ProxyPass /showroom http://46.192.22.03/showroom retry=1 acquire=3000 timeout=600 Keepalive=On ProxyPassReverse /showroom http://46.192.22.03/showroom </VirtualHost>
伺服器2
ServerName www.example.com:80 <VirtualHost *:80> ServerName www.example.com ServerAlias www.example.com DocumentRoot /var/www/html <directory "/var/www/html"> Options Indexes FollowSymLinks AllowOverride all Order Deny,Allow Deny from all Allow from all </directory> <Proxy *> Order deny,allow Allow from all </Proxy> ProxyRequests Off ProxyPass /music http://46.192.22.01/music retry=1 acquire=3000 timeout=600 Keepalive=On ProxyPassReverse /music http://46.192.22.01/music ProxyPass /video http://46.192.22.01/video retry=1 acquire=3000 timeout=600 Keepalive=On ProxyPassReverse /video http://46.192.22.01/video ProxyPass /products http://46.192.22.03/products retry=1 acquire=3000 timeout=600 Keepalive=On ProxyPassReverse /products http://46.192.22.03/products ProxyPass /showroom http://46.192.22.03/showroom retry=1 acquire=3000 timeout=600 Keepalive=On ProxyPassReverse /showroom http://46.192.22.03/showroom </VirtualHost>
伺服器3
ServerName www.example.com:80 <VirtualHost *:80> ServerName www.example.com ServerAlias www.example.com DocumentRoot /var/www/html <directory "/var/www/html"> Options Indexes FollowSymLinks AllowOverride all Order Deny,Allow Deny from all Allow from all </directory> <Proxy *> Order deny,allow Allow from all </Proxy> ProxyRequests Off ProxyPass /music http://46.192.22.01/music retry=1 acquire=3000 timeout=600 Keepalive=On ProxyPassReverse /music http://46.192.22.01/music ProxyPass /video http://46.192.22.01/video retry=1 acquire=3000 timeout=600 Keepalive=On ProxyPassReverse /video http://46.192.22.01/video ProxyPass /products http://46.192.22.03/products retry=1 acquire=3000 timeout=600 Keepalive=On ProxyPassReverse /products http://46.192.22.03/products ProxyPass /showroom http://46.192.22.03/showroom retry=1 acquire=3000 timeout=600 Keepalive=On ProxyPassReverse /showroom http://46.192.22.03/showroom </VirtualHost>
所有的 /etc/hosts 都是
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
然後 .htaccess 文件
伺服器 1
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^music/track/(\d+)?$ music/track.php?number=$1 RewriteRule ^video/introduce/(\d+)?$ video/introduce.php?number=$1 RewriteCond %{HTTP_HOST} ^example\.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
伺服器 2
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^article/introduce/(\d+)?$ article/introduce.php?number=$1 RewriteRule ^photo/products/(\d+)?$ photo/products.php?number=$1 RewriteCond %{HTTP_HOST} ^example\.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
伺服器 3
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^products/smartphone/(\d+)?$ products/smartphone.php?number=$1 RewriteRule ^showroom/smartphone/(\d+)?$ showroom/smartphone.php?number=$1 RewriteCond %{HTTP_HOST} ^example\.com$ [NC] RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule>
但是我打開
http://www.example.com/products/smartphone/102034
的時候很慢(3-5秒延遲),但是http://46.192.22.03/products/smartphone/102034
很快(0.2秒左右)
tail -50 /var/log/messages
返回日誌如Nov 18 11:46:20 dhclient[857]: DHCPACK from 46.192.22.01 (xid=0x6caa5cd9) Nov 18 11:46:21 dhclient[857]: bound to 46.192.22.02 -- renewal in 1481 seconds.
我不擅長伺服器部分技術。任何教授都可以幫助我找出並解決導致 DNS 非常慢的問題所在嗎?謝謝。
更新 1 (2014/11/23)
在 2 天的Google搜尋中,仍然沒有找到答案。每個頁面載入需要大約 4 秒的連接,這是在 chrome 控制台中查看的。如果鍵入 ip 而不是 domainn,則只需 0.2-0.4 秒連接。我在所有 3 個伺服器中都禁用了我的 ipv6,我在…
retry=1 acquire=3000 timeout=600 Keepalive=On
之後添加了ProxyPass
#dig example.com ; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.30.rc1.el6 <<>> example.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 63728 ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;example.com. IN A ;; ANSWER SECTION: example.com. 7199 IN A 46.192.22.01 example.com. 7199 IN A 46.192.22.02 example.com. 7199 IN A 46.192.22.03 ;; Query time: 121 msec ;; SERVER: 46.61.167.22#53(46.61.167.22) ;; WHEN: Sun Nov 23 20:51:03 2014 ;; MSG SIZE rcvd: 81
我懷疑反向代理真的是我需要的嗎?Hane 我發現連接伺服器的方法錯誤?
確實,我有 1 個站點的大數據,現在我將它分成 3 個 centos6.6 64 位伺服器(具有 3 個 ips)。每台伺服器都有唯一的文件夾
- server1 46.192.22.01 /var/www/html -> /music & /video
- server2 46.192.22.02 /var/www/html -> /article & /photo
- server3 46.192.22.03 /var/www/html -> /products & /showroom
所以它不是集群平衡或代理平衡,而是如何設置(或安裝其他軟體)讓網際網路知道是否某種類型的“ http://www.example.com/music ”它會映射到伺服器1;某種類型的“ http://www.example.com/products ”它會映射到伺服器 3…對不起我的母語不是英語,所以我一直沒有找到正確的方法,直到今天,只有反向代理可以滿足我的要求。
對不起,我只有一些php,mysql技能,一點apache centos技能,需要詳細的解決方案。非常感謝。
更新 2 (2014/11/24)
又是一天的工作。似乎不是 DNS 查找問題。這是使用域時的一些螢幕截圖
然後與ip相同的頁面
避免瀏覽器記憶體影響。我已經清理了所有瀏覽器記憶體,然後嘗試先載入 ip 然後載入域。最大的區別在於“停滯”和“初始連接”。
我使用
top
命令監控記憶體和cpu使用情況,3台伺服器在速度慢時看起來正常。s1
top - 18:21:57 up 21:44, 1 user, load average: 1.08, 1.28, 1.10 Tasks: 108 total, 2 running, 106 sleeping, 0 stopped, 0 zombie Cpu(s): 7.3%us, 2.4%sy, 0.0%ni, 77.8%id, 12.2%wa, 0.0%hi, 0.0%si, 0.2%st Mem: 1922200k total, 1847432k used, 74768k free, 2224k buffers Swap: 1048572k total, 81224k used, 967348k free, 84816k cached
s2
top - 18:31:24 up 21:55, 1 user, load average: 0.15, 0.09, 0.02 Tasks: 119 total, 1 running, 118 sleeping, 0 stopped, 0 zombie Cpu(s): 3.0%us, 1.0%sy, 0.0%ni, 95.8%id, 0.0%wa, 0.0%hi, 0.2%si, 0.0%st Mem: 1922200k total, 1669328k used, 252872k free, 25652k buffers Swap: 1048572k total, 69256k used, 979316k free, 458528k cached
s3
top - 18:21:21 up 1 day, 5:57, 1 user, load average: 1.03, 0.88, 0.90 Tasks: 105 total, 2 running, 103 sleeping, 0 stopped, 0 zombie Cpu(s): 25.7%us, 20.0%sy, 0.0%ni, 53.9%id, 0.0%wa, 0.0%hi, 0.2%si, 0.2%st Mem: 1922200k total, 1758088k used, 164112k free, 58712k buffers Swap: 1048572k total, 128k used, 1048444k free, 226396k cached
請查看平均負載。2 台伺服器超過了 1 的值。
確實在DNS中,我將伺服器1設置在第一個A地址位置,但是為什麼伺服器2成為主伺服器?
如果您在通過主機名和通過 IP 連接到站點時得到不同的結果,那麼問題似乎仍然與 DNS 有關。
嘗試將所有三台機器都添加到所有這些機器上的 /etc/hosts 中,即
46.192.22.01 server1 46.192.22.02 server2 46.192.22.03 server3
作為旁注,您的 DHCP 租用時間似乎很短,大約為 1500 秒。典型的 DHCP 租約持續一天或更長時間。如果 IP 是靜態的(似乎是這種情況),您還可以考慮將它們從 DHCP 池中刪除,並使這三台機器上的 IP 配置靜態。