¼¹ö¿¡ µ¿½Ã Á¢¼ÓÀÚ°¡ ¸¹¾ÆÁ® ¼¹ö ÇÑ´ë·Î 󸮰¡ ºÒ°¡´É ÇÒ °æ¿ì ºÎÇÏ ºÐ»êÀ» ÅëÇؼ ¼ºñ½º¸¦ ÇÏ°Ô µÈ´Ù.
ÀϹÝÀûÀ¸·Î óÀ½¿¡´Â ÇÑ ´ë·Î ¼ºñ½º ÇÏ´ø °ÍÀ» µÎ ´ë·Î ´Ã¿©¼ ¼ºñ½º¸¦ ½ÃµµÇÏ°Ô µÈ´Ù.
À̶§ Load Balancer ¿ªÈ°À» ÇÏ´Â ¼¹ö¸¦ ÀϹÝÀûÀ¸·Î´Â ºÐ¸®¸¦ Çؼ ³í¸®ÀûÀ¸·Î »óÀ§´Ü¿¡ µÎ°í µé¾î ¿À´Â ÆÐŶÀ» Real Server ´ÜÀ¸·Î ºÐ»êÀ» ½ÃÄÑ Áִµ¥ ±×·¸°Ô µÇ¸é LB ¼¹ö¿ëµµ·Î µû·Î ¼¹ö°¡ ÇÑ´ë ´õ µé¾î°¡°Ô µÇ¹Ç·Î Ãʱâ ÅõÀÚ ºñ¿ëÀÌ Áõ°¡ÇÏ°Ô µÈ´Ù. ±×·¡¼ ¸®´ª½º·Î ¼ºñ½º¸¦ ¿î¿µÇÏ´Â °æ¿ì¶ó¸é LB ¼¹ö¿Í Real Server ¸¦ ÇÕÃļ µÎ°¡Áö ÀÏÀ» µ¿½Ã¿¡ ½Ãų ¼ö ÀÖ´Ù.
Áï ¼¹ö µÎ´ë°¡ LBÀÇ master/backup ¿ªÈ°À» ÇÏ¸é¼ µ¿½Ã¿¡ Real Server1, Real Server2 ÀÇ ¿ªÈ°À» ¼öÇàÇÏ°Ô µÈ´Ù.
À̹ø¿¡´Â keepalived.conf¿¡ VRRP¿Í LVS ¼³Á¤ÀÌ µ¿½Ã¿¡ µé¾î°¡°Ô µÈ´Ù.
Áß¿äÇÑ ºÎºÐ ÇÑ°¡Áö¸¦ ¤°í ³Ñ¾î°¡ÀÚ.
µÎ ¼¹ö°¡ µ¥ÀÌÅÍ µ¿±âÈ´Â ¾î¶»°Ô ÇÒ °ÍÀΰ¡?
Storage¸¦ »ç¿ëÇÏ¸é µÈ´Ù°í ´ë´äÀ» ÇÒ ¼ö ÀÖÀ¸³ª LB ¼¹öµµ ºñ¿ëÀ» ÁÙÀÌ°íÀÚ Real Server¿Í ÇÕÃÄ ³õÀº »óÅÂÀε¥ Storage¸¦ ±¸¸ÅÇÒ ¿©·ÂÀÌ ³²¾Æ ÀÖÀ»¸® ¾ø´Ù°í º»´Ù. rsync µîÀ» »ç¿ëÇؼ ÃÖ´ëÇÑ Âª°Ô µ¿±âÈ Çϴ°͵µ ¹æ¹ýÀ̱ä ÇÏ´Ù.
ÀÌ·± ºÐµéÀ» À§Çؼ DRBD¸¦ ÃßõÇÑ´Ù. DRBD + GFS2¸¦ »ç¿ëÇϸé read/write ¸¦ Àüü ³ëµå¿¡¼ »ç¿ëÀÌ °¡´É ÇÏ´Ù.
DRBD °ü·ÃÇÑ ±ÛÀ» Æ÷½ºÆà ÇÑ °ÍÀÌ ÀÖÀ¸´Ï ã¾Æ¼ °°ÀÌ ÀÀ¿ëÀ» ÇÏ¸é ´õ¿í ÁÁÀº ±¸¼ºÀ» ¸¸µé°Ô µÉ °ÍÀÌ´Ù.
ÀÌ ±Û¿¡¼´Â DRBD¿Í ¿¬µ¿ ¼³¸íÀº Á¦¿ÜÇÑ´Ù.
´ÙÀ½°ú °°ÀÌ °¡Á¤À» ÇÑ´Ù.
Real Server 1 : 10.30.6.111
Real Server 2 : 10.30.6.112
VIP : 10.30.6.110
Service : http
¿ì¼± Ä¿³ÎÀ» µû·Î ÄÄÆÄÀÏ Çؼ »ç¿ëÇÏ´Â °æ¿ì¶ó¸é LVS¸¦ Ä¿³Î¿¡¼ Áö¿øÀÌ µÇµµ·Ï ¸¸µé¾î¾ß ÇÑ´Ù.
¸ðµâ·Î ÀÌ¹Ì µé¾î°¡ Àְųª debian ±âº» Ä¿³Î »ç¿ë½Ã¿¡´Â ±×³É ³Ñ¾î°£´Ù.
-*- Networking support ---> Networking options --->
[*] Network packet filtering framework (Netfilter) ---> <*> IP virtual server support ---> --- IP virtual server support [*] IP virtual server debugging (12) IPVS connection table size (the Nth power of 2) *** IPVS transport protocol load balancing support *** [*] TCP load balancing support [*] UDP load balancing support [*] ESP load balancing support [*] AH load balancing support *** IPVS scheduler *** <*> round-robin scheduling <*> weighted round-robin scheduling <*> least-connection scheduling <*> weighted least-connection scheduling <*> locality-based least-connection scheduling <*> locality-based least-connection with replication scheduling <*> destination hashing scheduling <*> source hashing scheduling <*> shortest expected delay scheduling <*> never queue scheduling *** IPVS application helper *** <*> FTP protocol helper
|
keepalived ¸¦ ¼³Ä¡ÇÑ´Ù.
µÎ ¼¹ö ¸ðµÎ µ¿ÀÏÇÏ°Ô ¼³Ä¡ ÇÑ´Ù.
dongho-vm111:~# apt-get install keepalived Reading package lists... Done Building dependency tree... Done The following NEW packages will be installed: keepalived 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 0B/111kB of archives. After unpacking 340kB of additional disk space will be used. Selecting previously deselected package keepalived. (Reading database ... 9199 files and directories currently installed.) Unpacking keepalived (from .../keepalived_1.1.12-1_i386.deb) ... Setting up keepalived (1.1.12-1) ... Starting keepalived: keepalived.
|
http ¼ºñ½º¸¦ ÇÑ´Ù°í °¡Á¤À» ÇÏ¿´À¸´Ï apache2 µµ ¼³Ä¡¸¦ ÇÑ´Ù.
µÎ ¼¹ö ¸ðµÎ µ¿ÀÏÇÏ°Ô ¼³Ä¡¸¦ ÇÑ´Ù.
dongho-vm111:~# apt-get install apache2 Reading package lists... Done Building dependency tree... Done The following extra packages will be installed: apache2-mpm-worker apache2-utils apache2.2-common libapr1 libaprutil1 libexpat1 libpq4 libsqlite3-0 The following NEW packages will be installed: apache2 apache2-mpm-worker apache2-utils apache2.2-common libapr1 libaprutil1 libexpat1 libpq4 libsqlite3-0 0 upgraded, 9 newly installed, 0 to remove and 0 not upgraded. Need to get 2497kB of archives. After unpacking 6492kB of additional disk space will be used. Do you want to continue [Y/n]? Get:1 http://ftp.debian.org etch/main libapr1 1.2.7-8.2 [109kB] Get:2 http://ftp.debian.org etch/main libexpat1 1.95.8-3.4 [62.9kB] Get:3 http://ftp.debian.org etch/main libpq4 8.1.15-0etch1 [290kB] Get:4 http://ftp.debian.org etch/main libsqlite3-0 3.3.8-1.1 [194kB] Get:5 http://ftp.debian.org etch/main libaprutil1 1.2.7+dfsg-2 [68.5kB] Get:6 http://ftp.debian.org etch/main apache2-utils 2.2.3-4+etch6 [344kB] Get:7 http://ftp.debian.org etch/main apache2.2-common 2.2.3-4+etch6 [963kB] Get:8 http://ftp.debian.org etch/main apache2-mpm-worker 2.2.3-4+etch6 [425kB] Get:9 http://ftp.debian.org etch/main apache2 2.2.3-4+etch6 [41.3kB] Fetched 2497kB in 5s (476kB/s) Selecting previously deselected package libapr1. (Reading database ... 9237 files and directories currently installed.) Unpacking libapr1 (from .../libapr1_1.2.7-8.2_i386.deb) ... Selecting previously deselected package libexpat1. Unpacking libexpat1 (from .../libexpat1_1.95.8-3.4_i386.deb) ... Selecting previously deselected package libpq4. Unpacking libpq4 (from .../libpq4_8.1.15-0etch1_i386.deb) ... Selecting previously deselected package libsqlite3-0. Unpacking libsqlite3-0 (from .../libsqlite3-0_3.3.8-1.1_i386.deb) ... Selecting previously deselected package libaprutil1. Unpacking libaprutil1 (from .../libaprutil1_1.2.7+dfsg-2_i386.deb) ... Selecting previously deselected package apache2-utils. Unpacking apache2-utils (from .../apache2-utils_2.2.3-4+etch6_i386.deb) ... Selecting previously deselected package apache2.2-common. Unpacking apache2.2-common (from .../apache2.2-common_2.2.3-4+etch6_i386.deb) ... Selecting previously deselected package apache2-mpm-worker. Unpacking apache2-mpm-worker (from .../apache2-mpm-worker_2.2.3-4+etch6_i386.deb) ... Selecting previously deselected package apache2. Unpacking apache2 (from .../apache2_2.2.3-4+etch6_all.deb) ... Setting up libapr1 (1.2.7-8.2) ...
Setting up libexpat1 (1.95.8-3.4) ...
Setting up libpq4 (8.1.15-0etch1) ...
Setting up libsqlite3-0 (3.3.8-1.1) ...
Setting up libaprutil1 (1.2.7+dfsg-2) ...
Setting up apache2-utils (2.2.3-4+etch6) ... Setting up apache2.2-common (2.2.3-4+etch6) ... Setting Apache2 to Listen on port 80. If this is not desired, please edit /etc/apache2/ports.conf as desired. Note that the Port directive no longer works. Module alias installed; run /etc/init.d/apache2 force-reload to enable. Module autoindex installed; run /etc/init.d/apache2 force-reload to enable. Module dir installed; run /etc/init.d/apache2 force-reload to enable. Module env installed; run /etc/init.d/apache2 force-reload to enable. Module mime installed; run /etc/init.d/apache2 force-reload to enable. Module negotiation installed; run /etc/init.d/apache2 force-reload to enable. Module setenvif installed; run /etc/init.d/apache2 force-reload to enable. Module status installed; run /etc/init.d/apache2 force-reload to enable. Module auth_basic installed; run /etc/init.d/apache2 force-reload to enable. Module authz_default installed; run /etc/init.d/apache2 force-reload to enable. Module authz_user installed; run /etc/init.d/apache2 force-reload to enable. Module authz_groupfile installed; run /etc/init.d/apache2 force-reload to enable. Module authn_file installed; run /etc/init.d/apache2 force-reload to enable. Module authz_host installed; run /etc/init.d/apache2 force-reload to enable.
Setting up apache2-mpm-worker (2.2.3-4+etch6) ... Starting web server (apache2)...apache2: apr_sockaddr_info_get() failed for dongho-vm111.freeb.net apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1 for ServerName .
Setting up apache2 (2.2.3-4+etch6) ...
|
ÀÌÁ¦ keepalived.conf ¼³Á¤À» ÇÑ´Ù.
¼³Á¤Áß Áß°£¿¡ üũ¸¦ ÇÏ¿© Ãß°¡·Î ³Ö¾î¾ß ÇÏ´Â °ªµµ ÀÖ´Ù.
¾Æ·¡´Â Master ¿¡¼ÀÇ ¼³Á¤ °ªÀÌ´Ù.
dongho-vm111:~# cat /etc/keepalived/keepalived.conf global_defs { notification_email { uheung@gmail.com } notification_email_from keepalived@ha-lvs smtp_server localhost smtp_connect_timeout 30 router_id HA_LVS }
vrrp_instance ETH0 { state MASTER interface eth0 lvs_sync_daemon_interface eth0 virtual_router_id 10 priority 200 garp_master_delay 2 advert_int 1 smtp_alert authentication { auth_type PASS auth_pass p@ssw0rd } virtual_ipaddress { 10.30.6.110/24 } notify_master "/etc/keepalived/redirect.sh del 10.30.6.110" notify_backup "/etc/keepalived/redirect.sh add 10.30.6.110" notify_fault "/etc/keepalived/redirect.sh add 10.30.6.110"
}
virtual_server 10.30.6.110 80 { delay_loop 3 lb_algo rr lb_kind DR #persistence_timeout 600 protocol TCP virtualhost keepalive.lovediary.co.kr
real_server 10.30.6.111 80 { weight 100 HTTP_GET { url { path /apache2-default/ digest c7b4690c8c46625ef0f328cd7a24a0a3 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } }
real_server 10.30.6.112 80 { weight 100 HTTP_GET { url { path /apache2-default/ digest c7b4690c8c46625ef0f328cd7a24a0a3 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } }
}
|
Backup ¼¹öÂÊ¿¡¼ÀÇ keepalived.conf °ªÀÌ´Ù.
Backup ÂÊÀº MASTER ´ë½Å BACKUP À̶ó°í Àû¾î ÁÖ°í priority °ªÀ» Master º¸´Ù Àû°Ô ÁÖ¸é µÈ´Ù.
dongho-vm112:~# cat /etc/keepalived/keepalived.conf global_defs { notification_email { uheung@gmail.com } notification_email_from keepalived@ha-lvs smtp_server localhost smtp_connect_timeout 30 router_id HA_LVS }
vrrp_instance ETH0 { state BACKUP interface eth0 lvs_sync_daemon_interface eth0 virtual_router_id 10 priority 100 garp_master_delay 2 advert_int 1 smtp_alert authentication { auth_type PASS auth_pass p@ssw0rd } virtual_ipaddress { 10.30.6.110/24 } notify_master "/etc/keepalived/redirect.sh del 10.30.6.110" notify_backup "/etc/keepalived/redirect.sh add 10.30.6.110" notify_fault "/etc/keepalived/redirect.sh add 10.30.6.110" }
virtual_server 10.30.6.110 80 { delay_loop 3 lb_algo rr lb_kind DR #persistence_timeout 600 protocol TCP virtualhost keepalive.lovediary.co.kr
real_server 10.30.6.111 80 { weight 100 HTTP_GET { url { path /apache2-default/ digest c7b4690c8c46625ef0f328cd7a24a0a3 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } }
real_server 10.30.6.112 80 { weight 100 HTTP_GET { url { path /apache2-default/ digest c7b4690c8c46625ef0f328cd7a24a0a3 } connect_timeout 3 nb_get_retry 3 delay_before_retry 3 } }
}
|
À§ keepalived.conf °ª Áß HTTP_GET ¿¡¼ÀÇ digest °ªÀº ´ÙÀ½°ú °°ÀÌ ±¸ÇÒ ¼ö ÀÖ´Ù.
genhash ´Â keepalived ÆÐÅ°Áö¿¡ ±âº» Æ÷ÇԵǾî ÀÖ´Ù.
-v ¿É¼ÇÀ» ÁÖ¾î »ó¼¼È÷ °ªÀ» Âï¾î º» °ÍÀÌÁö¸¸ ÀϹÝÀûÀ¸·Î ¾Æ·¡Ã³·³ -v ¿É¼ÇÀ» ÁÙ ÇÊ¿ä±îÁö´Â ¾ø´Ù.
±×¸®°í --use-virtualhost °ªÀ» µû·Î ÁØ ÀÌÀ¯´Â Real Server ¿¡¼ µµ¸ÞÀÎÀ» ÇÑ°³¸¸ ¿î¿µ ÇÒ ¼öµµ ÀÖÁö¸¸ ¿©·¯°³ ¿î¿µÇÏ´Â °æ¿ì ¾î´À µµ¸ÞÀο¡¼ °ªÀ» ¹Þ¾Æ ¿ÃÂî Çì´õ¿¡ ´øÀúÁà¾ß ÇÒ ¶§µµ ÀÖ¾î °°ÀÌ ÀûÀº °ÍÀÌ´Ù.
dongho-vm111:~# genhash -s 10.30.6.112 -p 80 --url /apache2-default/ --use-virtualhost keepalived.lovediary.co.kr -v -----------------------[ HTTP Header Buffer ]----------------------- 0000 48 54 54 50 2f 31 2e 31 - 20 32 30 30 20 4f 4b 0d HTTP/1.1 200 OK. 0010 0a 44 61 74 65 3a 20 54 - 75 65 2c 20 31 37 20 46 .Date: Tue, 17 F 0020 65 62 20 32 30 30 39 20 - 30 30 3a 31 37 3a 31 32 eb 2009 00:17:12 0030 20 47 4d 54 0d 0a 53 65 - 72 76 65 72 3a 20 41 70 GMT..Server: Ap 0040 61 63 68 65 2f 32 2e 32 - 2e 33 20 28 44 65 62 69 ache/2.2.3 (Debi 0050 61 6e 29 0d 0a 4c 61 73 - 74 2d 4d 6f 64 69 66 69 an)..Last-Modifi 0060 65 64 3a 20 53 61 74 2c - 20 32 30 20 4e 6f 76 20 ed: Sat, 20 Nov 0070 32 30 30 34 20 32 30 3a - 31 36 3a 32 34 20 47 4d 2004 20:16:24 GM 0080 54 0d 0a 45 54 61 67 3a - 20 22 31 63 30 30 61 2d T..ETag: "1c00a- 0090 32 63 2d 34 63 32 33 62 - 36 30 30 22 0d 0a 41 63 2c-4c23b600"..Ac 00a0 63 65 70 74 2d 52 61 6e - 67 65 73 3a 20 62 79 74 cept-Ranges: byt 00b0 65 73 0d 0a 43 6f 6e 74 - 65 6e 74 2d 4c 65 6e 67 es..Content-Leng 00c0 74 68 3a 20 34 34 0d 0a - 43 6f 6e 6e 65 63 74 69 th: 44..Connecti 00d0 6f 6e 3a 20 63 6c 6f 73 - 65 0d 0a 43 6f 6e 74 65 on: close..Conte 00e0 6e 74 2d 54 79 70 65 3a - 20 74 65 78 74 2f 68 74 nt-Type: text/ht 00f0 6d 6c 3b 20 63 68 61 72 - 73 65 74 3d 55 54 46 2d ml; charset=UTF- 0100 38 0d 0a 0d 0a - 8.... -----------------------[ HTTP Header Ascii Buffer ]----------------------- HTTP/1.1 200 OK Date: Tue, 17 Feb 2009 00:17:12 GMT Server: Apache/2.2.3 (Debian) Last-Modified: Sat, 20 Nov 2004 20:16:24 GMT ETag: "1c00a-2c-4c23b600" Accept-Ranges: bytes Content-Length: 44 Connection: close Content-Type: text/html; charset=UTF-8
-----------------------[ HTML Buffer ]----------------------- 0000 3c 68 74 6d 6c 3e 3c 62 - 6f 64 79 3e 3c 68 31 3e <html><body><h1> 0010 49 74 20 77 6f 72 6b 73 - 21 3c 2f 68 31 3e 3c 2f It works!</h1></ 0020 62 6f 64 79 3e 3c 2f 68 - 74 6d 6c 3e body></html>
-----------------------[ HTML MD5 resulting ]----------------------- 0000 c7 b4 69 0c 8c 46 62 5e - f0 f3 28 cd 7a 24 a0 a3 ..i..Fb^..(.z$.. -----------------------[ HTML MD5 final resulting ]----------------------- MD5SUM = c7b4690c8c46625ef0f328cd7a24a0a3
Global response time for [/apache2-default/] =10845
|
´Ù¸¥ÂÊ ¼¹ö¿¡¼µµ üũ¸¦ ÇÑ´Ù.
¾Æ·¡´Â apache2 ÀÇ ±âº» ÆäÀÌÁö¶ó¼ °á°ú°ªÀÌ °°°Ô ³ª¿À°í ÀÖ´Ù.
dongho-vm112:~# genhash -s 10.30.6.111 -p 80 --url /apache2-default/ --use-virtualhost keepalived.lovediary.co.kr -v -----------------------[ HTTP Header Buffer ]----------------------- 0000 48 54 54 50 2f 31 2e 31 - 20 32 30 30 20 4f 4b 0d HTTP/1.1 200 OK. 0010 0a 44 61 74 65 3a 20 54 - 75 65 2c 20 31 37 20 46 .Date: Tue, 17 F 0020 65 62 20 32 30 30 39 20 - 30 30 3a 32 30 3a 33 31 eb 2009 00:20:31 0030 20 47 4d 54 0d 0a 53 65 - 72 76 65 72 3a 20 41 70 GMT..Server: Ap 0040 61 63 68 65 2f 32 2e 32 - 2e 33 20 28 44 65 62 69 ache/2.2.3 (Debi 0050 61 6e 29 0d 0a 4c 61 73 - 74 2d 4d 6f 64 69 66 69 an)..Last-Modifi 0060 65 64 3a 20 53 61 74 2c - 20 32 30 20 4e 6f 76 20 ed: Sat, 20 Nov 0070 32 30 30 34 20 32 30 3a - 31 36 3a 32 34 20 47 4d 2004 20:16:24 GM 0080 54 0d 0a 45 54 61 67 3a - 20 22 31 63 30 30 61 2d T..ETag: "1c00a- 0090 32 63 2d 34 63 32 33 62 - 36 30 30 22 0d 0a 41 63 2c-4c23b600"..Ac 00a0 63 65 70 74 2d 52 61 6e - 67 65 73 3a 20 62 79 74 cept-Ranges: byt 00b0 65 73 0d 0a 43 6f 6e 74 - 65 6e 74 2d 4c 65 6e 67 es..Content-Leng 00c0 74 68 3a 20 34 34 0d 0a - 43 6f 6e 6e 65 63 74 69 th: 44..Connecti 00d0 6f 6e 3a 20 63 6c 6f 73 - 65 0d 0a 43 6f 6e 74 65 on: close..Conte 00e0 6e 74 2d 54 79 70 65 3a - 20 74 65 78 74 2f 68 74 nt-Type: text/ht 00f0 6d 6c 3b 20 63 68 61 72 - 73 65 74 3d 55 54 46 2d ml; charset=UTF- 0100 38 0d 0a 0d 0a - 8.... -----------------------[ HTTP Header Ascii Buffer ]----------------------- HTTP/1.1 200 OK Date: Tue, 17 Feb 2009 00:20:31 GMT Server: Apache/2.2.3 (Debian) Last-Modified: Sat, 20 Nov 2004 20:16:24 GMT ETag: "1c00a-2c-4c23b600" Accept-Ranges: bytes Content-Length: 44 Connection: close Content-Type: text/html; charset=UTF-8
-----------------------[ HTML Buffer ]----------------------- 0000 3c 68 74 6d 6c 3e 3c 62 - 6f 64 79 3e 3c 68 31 3e <html><body><h1> 0010 49 74 20 77 6f 72 6b 73 - 21 3c 2f 68 31 3e 3c 2f It works!</h1></ 0020 62 6f 64 79 3e 3c 2f 68 - 74 6d 6c 3e body></html>
-----------------------[ HTML MD5 resulting ]----------------------- 0000 c7 b4 69 0c 8c 46 62 5e - f0 f3 28 cd 7a 24 a0 a3 ..i..Fb^..(.z$.. -----------------------[ HTML MD5 final resulting ]----------------------- MD5SUM = c7b4690c8c46625ef0f328cd7a24a0a3
Global response time for [/apache2-default/] =4243
|
±×¸®°í redirect.sh ½ºÅ©¸³Æ®¸¦ ÀÛ¼ºÀ» ÇÑ´Ù.
¿ªÈ°Àº VIP ·Î µé¾î¿À´Â ÆÐŶÀ» ÀÚ½ÅÀÌ ¹Þ¾Æ¼ 󸮸¦ ÇÒ ¼ö ÀÖ°Ô Çϱâ À§Çؼ Ãß°¡ ÇÑ´Ù.
¾çÂÊ ¼¹ö¿¡ ¸ðµÎ Ãß°¡ÇÑ´Ù.
dongho-vm111:~# cat /etc/keepalived/redirect.sh #!/bin/bash
VIP="$2"
case "$1" in add) /sbin/iptables -A PREROUTING -t nat -d $VIP -p tcp -j REDIRECT ;; del) /sbin/iptables -D PREROUTING -t nat -d $VIP -p tcp -j REDIRECT ;; *) echo "Usage: $0 {add|del} ipaddress" exit 1 esac exit 0
|
redirect.sh ÆÄÀÏ¿¡ ½ÇÇà ±ÇÇÑÀ» ÁØ´Ù.
¾çÂÊ ¼¹ö ¸ðµÎ ÀÛ¾÷ÇÑ´Ù.
dongho-vm111:~# cd /etc/keepalived/ dongho-vm111:/etc/keepalived# chmod 700 redirect.sh
|
failover µÉ¶§ ¸ÞÀÏÀ» ¹Þ±â À§ÇØ postfix ¸¦ ¼³Ä¡ÇÑ´Ù.
¾Æ·¡´Â ÀÌ¹Ì ¼³Ä¡°¡ µÇ¾î ÀÖ´Ù°í ³ª¿À´Â ¸Þ½ÃÁöÀÌ´Ù.
¾çÂÊ ¼¹ö ¸ðµÎ ÀÛ¾÷ÇÑ´Ù.
dongho-vm111:~# apt-get install postfix Reading package lists... Done Building dependency tree... Done postfix is already the newest version. 0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
|
±×¸®°í ¸¶Áö¸·À¸·Î packet À» Æ÷¿öµùÀ» ÇØ¾ß ÇϹǷΠnet.ipv4.ip_forward=1 À» sysctl.conf ¿¡ Ãß°¡ÇÏ¿© Àû¿ëÇÑ´Ù.
¾çÂÊ ¼¹ö¿¡µµ µ¿ÀÏÇÏ°Ô ÀÛ¾÷ÇÑ´Ù.
dongho-vm111:~# grep -v ^# /etc/sysctl.conf net.ipv4.ip_forward=1
dongho-vm111:~# sysctl -p net.ipv4.ip_forward = 1
dongho-vm111:~# sysctl -a |grep net.ipv4.ip_forward net.ipv4.ip_forward = 1
|
ÀÌÁ¦ keepalived µ¥¸óÀ» ½ÃÀÛ ÇÑ´Ù.
¸ÕÀú Master ÂÊ ºÎÅÍ µ¥¸óÀ» ½ÃÀÛÇÏ°í Backup¿¡¼ µ¥¸óÀ» ½ÃÀÛ ÇÑ´Ù.
dongho-vm111:~# /etc/init.d/keepalived start Starting keepalived: keepalived.
dongho-vm112:~# /etc/init.d/keepalived start Starting keepalived: keepalived.
|
Master ÂÊ¿¡ VIP °¡ Á¤»óÀûÀ¸·Î ¿Ã¶ó ¿Â °ÍÀ» º¼ ¼ö ÀÖ´Ù.
dongho-vm111:~# ip addr show eth0 2: eth0: <BROADCAST,MULTICAST,UP,10000> mtu 1500 qdisc pfifo_fast qlen 1000 link/ether 00:16:3e:4a:8b:c9 brd ff:ff:ff:ff:ff:ff inet 10.30.6.111/24 brd 10.30.6.255 scope global eth0 inet 10.30.6.110/24 scope global secondary eth0 inet6 fe80::216:3eff:fe4a:8bc9/64 scope link valid_lft forever preferred_lft forever
|
±×¸®°í Master ÂÊ¿¡¼ ipvsadm ¸í·ÉÀ» ÅëÇØ Á¤»óÀûÀ¸·Î Àß ºÎÇÏ ºÐ»êÀ» ÇÒ Áغñ°¡ µÇ¾ú´ÂÁö »ìÆì º»´Ù.
dongho-vm111:~# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 10.30.6.110:80 rr -> 10.30.6.112:80 Route 100 0 0 -> 10.30.6.111:80 Local 100 0 0
|
Backup ÂÊ ¼¹ö¿¡´Â VIP¿¡¼ µé¾î¿À´Â ÆÐŶÀ» ¹Þ¾Æ¼ 󸮸¦ Çϵµ·Ï iptables ¿¡¼ redirect °¡ ¾Æ·¡Ã³·³ µÇ¾î¾ß ÇÑ´Ù.
dongho-vm112:~# iptables -L -n -t nat -v Chain PREROUTING (policy ACCEPT 145 packets, 9529 bytes) pkts bytes target prot opt in out source destination 0 0 REDIRECT tcp -- * * 0.0.0.0/0 10.30.6.110
Chain POSTROUTING (policy ACCEPT 254 packets, 15191 bytes) pkts bytes target prot opt in out source destination
Chain OUTPUT (policy ACCEPT 254 packets, 15191 bytes) pkts bytes target prot opt in out source destination
|
°£´ÜÈ÷ Á¤»óÀûÀ¸·Î ºÎÇÏ ºÐ»êÀ» ÇÏ´ÂÁö apache ÀÇ ab ÅøÀ» »ç¿ëÇÏ¿© Å×½ºÆ®¸¦ Çغ¸ÀÚ.
¾Æ·¡´Â ÃÑ 10¸¸°³ÀÇ request ¸¦ º¸³¾¶§ µ¿½Ã¿¡ 200°³¾¿ º¸³»¶ó´Â ¸í·ÉÀÌ´Ù.
uheung@freeb:~$ ab -n 100000 -c 200 http://10.30.6.110/ This is ApacheBench, Version 2.0.40-dev <$Revision: 1.146 $> apache-2.0 Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/ Copyright 2006 The Apache Software Foundation, http://www.apache.org/
Benchmarking 10.30.6.110 (be patient) Completed 10000 requests Completed 20000 requests Completed 30000 requests Completed 40000 requests Completed 50000 requests Completed 60000 requests Completed 70000 requests Completed 80000 requests Completed 90000 requests Finished 100000 requests
Server Software: Apache/2.2.3 Server Hostname: 10.30.6.110 Server Port: 80
Document Path: / Document Length: 295 bytes
Concurrency Level: 200 Time taken for tests: 56.834278 seconds Complete requests: 100000 Failed requests: 0 Write errors: 0 Non-2xx responses: 100061 Total transferred: 51731537 bytes HTML transferred: 29517995 bytes Requests per second: 1759.50 [#/sec] (mean) Time per request: 113.669 [ms] (mean) Time per request: 0.568 [ms] (mean, across all concurrent requests) Transfer rate: 888.88 [Kbytes/sec] received
Connection Times (ms) min mean[+/-sd] median max Connect: 1 51 201.3 36 7599 Processing: 4 61 24.0 60 323 Waiting: 3 44 20.4 45 305 Total: 8 112 203.4 102 7672
Percentage of the requests served within a certain time (ms) 50% 102 66% 107 75% 108 80% 109 90% 113 95% 195 98% 240 99% 267 100% 7672 (longest request)
|
Load Balancer Master ÂÊ¿¡¼ Á¤»óÀûÀ¸·Î ºÎÇÏ ºÐ»êÀ» ÇÑ´Ù¸é round robin ¹æ½ÄÀ̹ǷΠ´ë·« Àý¹Ý¾¿ ºÐ»êÀ» ÇÏ°Ô µÉ °ÍÀÌ´Ù.
Áï 200°³ÀÇ µ¿½Ã Á¢¼ÓÀ̹ǷΠ100°³ Á¤µµ¾¿ ºÐ»êÀ» ÇÏ°Ô µÈ´Ù.
¾Æ·¡¸¦ »ìÆ캸ÀÚ.
¿©·¯¹ø ¸í·ÉÀ» ³¯·Á º¸´õ¶óµµ ´ë·« 100¿¡ °¡±î¿î ¼öÄ¡¿¡¼ Àý¹Ý¾¿ ³ª´©¾î ÁÖ´Â °ÍÀ» º¼ ¼ö ÀÖ´Ù.
dongho-vm111:~# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 10.30.6.110:80 rr -> 10.30.6.112:80 Route 100 99 5902 -> 10.30.6.111:80 Local 100 98 5902
dongho-vm111:~# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 10.30.6.110:80 rr -> 10.30.6.112:80 Route 100 99 6924 -> 10.30.6.111:80 Local 100 100 6923
dongho-vm111:~# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 10.30.6.110:80 rr -> 10.30.6.112:80 Route 100 93 9835 -> 10.30.6.111:80 Local 100 94 9834
dongho-vm111:~# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 10.30.6.110:80 rr -> 10.30.6.112:80 Route 100 92 14024 -> 10.30.6.111:80 Local 100 92 14024
dongho-vm111:~# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 10.30.6.110:80 rr -> 10.30.6.112:80 Route 100 94 14022 -> 10.30.6.111:80 Local 100 97 14019
dongho-vm111:~# ipvsadm -Ln IP Virtual Server version 1.2.1 (size=4096) Prot LocalAddress:Port Scheduler Flags -> RemoteAddress:Port Forward Weight ActiveConn InActConn TCP 10.30.6.110:80 rr -> 10.30.6.112:80 Route 100 96 14020 -> 10.30.6.111:80 Local 100 96 14020
|
½ÇÁ¦ À¥ ¼¹ö¿¡¼ Á¢¼ÓÀÌ ÀÖ¾ú´ÂÁö À¥·Î±×¸¦ »ìÆì º¸ÀÚ.
¾Æ·¡ Master ¿Í Backup ¼¹ö ¸ðµÎ Á¤»óÀûÀ¸·Î Á¢¼ÓÀÌ ÀÖ¾ú´ø °ÍÀ» º¼ ¼ö ÀÖ´Ù.
dongho-vm111:~# tail -200 /var/log/apache2/access.log |grep ApacheBench 10.30.103.33 - - [17/Feb/2009:01:31:03 +0000] "GET / HTTP/1.0" 302 295 "-" "ApacheBench/2.0.40-dev" 10.30.103.33 - - [17/Feb/2009:01:31:03 +0000] "GET / HTTP/1.0" 302 295 "-" "ApacheBench/2.0.40-dev" 10.30.103.33 - - [17/Feb/2009:01:31:03 +0000] "GET / HTTP/1.0" 302 295 "-" "ApacheBench/2.0.40-dev"
dongho-vm112:~# tail -200 /var/log/apache2/access.log |grep ApacheBench 10.30.103.33 - - [17/Feb/2009:01:31:03 +0000] "GET / HTTP/1.0" 302 295 "-" "ApacheBench/2.0.40-dev" 10.30.103.33 - - [17/Feb/2009:01:31:03 +0000] "GET / HTTP/1.0" 302 295 "-" "ApacheBench/2.0.40-dev" 10.30.103.33 - - [17/Feb/2009:01:31:03 +0000] "GET / HTTP/1.0" 302 295 "-" "ApacheBench/2.0.40-dev"
|
Health Check °¡ Á¤»óÀûÀ¸·Î Àß µÇ´ÂÁö Å×½ºÆ®ÇØ º»´Ù.
°£´ÜÈ÷ apache2 µ¥¸óÀ» ³»¸®°í »ìÆì º¸ÀÚ.
¾Æ·¡Ã³·³ ³»¸®¸é ipvsadm ¿¡¼ ºÐ»êµÉ¶§ ¼¹ö°¡ ºüÁö´Â °ÍÀ» º¼ ¼ö ÀÖ´Ù.