HAPrxoy 1.6.0 ã§å°å ¥ããã DNS ã®åçåå解決ã®æ¤è¨¼çµæ
追è¨(2016-07-13 16:40)
Changelog ã«æ¸ãã¦ããã¨ãã(BUG/MEDIUM: dns: unbreak DNS resolver after header fix
)ã
åçåå解決ãã§ããªããã°ãä¿®æ£ããã¾ããã
HAProxy 1.6.6 ã§åçåå解決ã§ããªããã°ãä¿®æ£ããã¦ãã¾ãã(Changelog ã«ãæ¸ãã¦ãã¾ããä¸å¿æ¤è¨¼ãã¾ãã)
— tkuchiki (@tkuchiki) 2016å¹´7æ13æ¥
詳細ã¯çãã¾ãããæ¬è¨äºã¨åæ§ã®æ¤è¨¼ãè¡ããåçåå解決ãã§ãããã¨ã確èªãã¾ããã
追è¨(2016-06-24 12:34)
HAProxy 1.6.5 ã¯ãDNS ã®åçåå解決ãåä½ããªãããã§ãã
ã注æãã ããã
HAProxy 1.6.5 ã§åçåå解決ã§ããªãåé¡ã«ã¤ãã¦ã¯ 1.6.4 ã§å°ã£ã¦ããªããã°ããã使ã£ã¦ã1.6.5 ããããã° patch ãå½ã¦ãã¨è¯ãããã§ã https://t.co/LPpQac1NeC
— tkuchiki (@tkuchiki) June 4, 2016
æ¤è¨¼ç°å¢ã¯ä»¥ä¸ã®ã¨ããã§ãã
- Amazon Linux 2015.09
- ã¤ã³ã¹ã¿ã³ã¹ã® IP: 10.1.0.10
- DNS ãµã¼ãã® IP: 10.1.0.2
- HAProxy 1.6.1
- RDS for MySQL(5.6.23)
http://www.haproxy.org ã® Quick News ã«ã
dynamic DNS-based server address resolution
ã¨æ¸ãã¦ããã¨ããã
HAProxy 1.6.0 ãã DNS ã®åçåå解決ã«å¯¾å¿ãã¾ããã
HAProxy 1.6.0 ããåã®ãã¼ã¸ã§ã³ã§ã¯ã©ãã ã£ããã¨ããã¨ã
èµ·åæã« DNS ãåç
§ãã¦ããã以é DNS ãåç
§ãããã¨ã¯ããã¾ããã
ãã®æåã«ã¤ãã¦ã¯ãã½ã¼ã¹ã³ã¼ããè¦ããã
port 53 ã®éä¿¡ããã£ããã£ããã¨ç¢ºèªãããã¨ãã§ãã¾ãã
追è¨(2015-10-30 14:57)
http://b.hatena.ne.jp/mapk0y/20151030#bookmark-270133853
ããã¯ãã¼ã¯ã«ã³ã¡ã³ããé ããã¨ããã
A ã¬ã³ã¼ããåçã«å¤ãããã®ã¨ã㦠RDS ã使ãã¾ãããã
ä¾ã§ãã®ã§ãã®æ§æã«æå³ã¯ããã¾ããã
RDS ã®å段㫠HAProxy ãç½®ãå ´åã¯ã
Slave(Read Replica) ãè¤æ°å°ç«ã¦ã¦åç
§ãåæ£ããã
ã¨ãã£ã使ãæ¹ã«ãªãã¨æãã¾ãã
å¼·å¼ã«ã¡ãªãããä¸ããã¨ããã°ã
æåã¯1å°ã§ã¹ã¿ã¼ããã¦ã
ãã¨ããè¤æ°å°ã® DB ãç«ã¦ã¦åç
§åæ£ãããã¨ããã¨ãã«ã
ã¢ããªã®ä¿®æ£ãå¿
è¦ãªããã¨ã§ããããã
ã³ã¡ã³ããããã¨ããããã¾ããï¼
åçåå解決ããªãã¨ã©ããªãã
åçåå解決æ©è½ã説æããåã«ã
HAProxy 1.5.2 ã使ãã
åçåå解決ããªãå ´åã®æåã«ã¤ãã¦èª¬æãã¾ãã
RDS ã®æºå
ãµã¼ãããã¦ã³ãããããæãã« A ã¬ã³ã¼ããæ´æ°ãã¦ããããã®ã¨ãã¦ã
Amazon RDS ãããã¾ãã
Amazon RDS ã«ã¯ reboot with failover ã¨ããã
å¼·å¶çã« failover ãããæ©è½ãããã¾ãã®ã§ããããæ¤è¨¼ã«ä½¿ãã¾ãã
failover ãããããã«ãMulti-AZ ãæå¹ã«ãã¦ã¤ã³ã¹ã¿ã³ã¹ãä½æãã¦ãã ããã
MySQL ã®æºå
HAProxy ã«ã¯ mysql ã® health check ãè¡ãæ©è½ãããã¾ãã
ç£è¦ç¨ã®ã¦ã¼ã¶ãå¿
è¦ã§ãã®ã§ä½æãã¾ãã
haproxy ã¦ã¼ã¶ãä½ãããã«ã以ä¸ã® SQL ãå®è¡ãã¾ãã
grant usage on *.* to 'haproxy'@'%';
ngrep ã®æºå
port 53 ã¸ã®éä¿¡ããã£ããã£ããããã«ã
ngrep
ãã¤ã³ã¹ãã¼ã«ãã¾ãã
ãã£ããã£ã§ããã°è¯ãã®ã§ãtcpdump
ã§ãè¯ãã§ãã
yum install -y epel-release yum install -y ngrep
HAProxy ã®æºå
amzn-main ã« HAProxy 1.5.2 ããã£ãã®ã§ã
yum install -y haproxy
ãã¦ã¤ã³ã¹ãã¼ã«ãã¾ãã
è¨å®ãã¡ã¤ã«ã¯ä»¥ä¸ã®ã¨ããã§ãã
# /etc/haproxy/haproxy.cfg listen mysql-slave bind 127.0.0.1:3307 mode tcp option mysql-check user haproxy balance roundrobin server master test-db.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com:3306 check
æ¤è¨¼
æºåãæ´ã£ãã®ã§ãHAProxy 1.5.2 ã§ã¯åçåå解決ããªããã¨ã確èªãã¾ãã
RDS ã failover ããåã® IP ã¢ãã¬ã¹ã調ã¹ã¾ãã
$ host test-db.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com test-db01.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com has address 10.1.0.100
ngrep
ãå®è¡ãã¦ãport 53 ã¸ã®éä¿¡ããªããã確èªãã¾ãã
$ ngrep -d any -W byline port 53 -q
ä¸è¨ã®ã³ãã³ããå®è¡ããç¶æ
ã§ã
service haproxy restart
ãå®è¡ãã¦åèµ·åããã¨ã
$ ngrep -d any -W byline port 53 -q interface: any filter: ( port 53 ) and (ip or ip6) U 10.1.0.2:53 -> 10.1.0.10:42761 .............test-db.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com................. .." U 10.1.0.10:49225 -> 10.1.0.2:53 .............test-db.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com..... U 10.1.0.2:53 -> 10.1.0.10:49225 .............test-db.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com................. .." U 10.1.0.10:34814 -> 10.1.0.2:53 OU...........test-db.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com..... U 10.1.0.2:53 -> 10.1.0.10:34814 OU...........test-db.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com................. .."
ã®ããã«ãDNS ãåç
§ãã¦ãããã¨ããããã¾ãã
åè¿°ã®ã¨ãããHAProxy 1.5.2 ã¯åçåå解決ãããªãã®ã§ã
ãã以é㯠ngrep
ã®æ§åãæ°ã«ããå¿
è¦ã¯ããã¾ããã
ããã§ã¯ãRDS ã failover ããã¾ãã
AWS CLI ã§ã¯ã以ä¸ã®ããã«ã³ãã³ããå®è¡ãã
$ aws rds reboot-db-instance --db-instance-identifier test-db --force-failover
Management Console ããæä½ããå ´åã¯ã
ãã§ãã¯ããã¯ã¹ã«ãã§ãã¯ãå
¥ãã¦åèµ·åãã¾ãã
Multi-AZ instance failover completed
ã¨ãããã°ãåºãã failover ãã¦ãã¾ãã
$ host test-db.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com test-db01.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com has address 10.2.0.200
IP ã¢ãã¬ã¹ãå¤ãã£ã¦ãããã¨ã確èªã§ãã¾ãã
ãã®ç¶æ
ã§ãHAProxy ãéã㦠RDS ã«æ¥ç¶ãã¾ãã
$ mysqladmin ping -u haproxy -h 127.0.0.1 -P 3307 mysqladmin: connect to server at '127.0.0.1' failed error: 'Lost connection to MySQL server at 'reading initial communication packet', system error: 0'
æ¥ç¶ã§ããªããã¨ã確èªã§ãã¾ãã
netstat ã§ã確èªãã¦ã¿ãã¨ã
$ netstat -anp | grep haproxy | grep :3306 tcp 0 1 10.1.0.10:56199 10.1.0.100:3306 SYN_SENT 1553/haproxy
failover åã® IP ã¢ãã¬ã¹ã«æ¥ç¶ãããã¨ãã¦ãã¾ãã
以ä¸ã®ãã¨ãããåçåå解決ããªãã¨ã
A ã¬ã³ã¼ããªã©ãå¤æ´ãã¦ãæ¥ç¶å
ãå¤ãããã¨ãã§ããªããã¨ããããã¾ãã
åçåå解決ã試ã
åçåå解決ã§ããªãã¨ã©ããªãããããã£ãã¨ããã§ã
HAProxy 1.6.1 ã使ãã
ã©ã®ããã«æåãå¤ãã£ãã確èªãã¾ãã
amzn-main ã«ã¯ HAProxy 1.6.1(1.6.0 ã)ãªãã®ã§ã
é©å®ãã«ããã¦ãã ããã
HAProxy ã®ãã°ãåºåããããã«ã
rsyslog
ãè¨å®ãã¾ãã
# /etc/rsyslog.conf + $ModLoad imudp + $UDPServerRun 514
# /etc/rsyslog.d/haproxy.conf + $ModLoad imudp + $UDPServerRun 514 + $template Haproxy,"%msg%\n" + local1.* -/var/log/haproxy.log;Haproxy
service rsyslog restart
ã§åèµ·åãã¾ãã
åçåå解決ç¨ã®è¨å®ããã¾ãã
# /etc/haproxy/haproxy.cfg resolvers mydns nameserver dns1 10.2.0.2:53 nameserver dns2 8.8.8.8:53 resolve_retries 3 timeout retry 1s hold valid 60s listen mysql-slave bind 127.0.0.1:3307 mode tcp log 127.0.0.1 local1 debug option mysql-check user haproxy balance roundrobin server master test-db.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com:3306 check resolvers mydns
resolve_retries 3
, timeout retry 1s
ã¯è¦ãã¾ã¾ã§ããã
ãªãã©ã¤ããåæ°ã¨ã¿ã¤ã ã¢ã¦ãã®ç§æ°ã§ãã
hold valid 60s
ã¯ãåå解決ãæåããããæå®ç§æ°åå解決ããªãè¨å®ã§ãã
ãã®ãªãã·ã§ã³ã¯ãhealth check ã fail ããã¨ãã¯ä½¿ããã¾ããã
nameserver
㯠DNS ãµã¼ããè¤æ°è¨å®ã§ãã¾ãã
http://cbonte.github.io/haproxy-dconv/configuration-1.6.html#5.3.2-nameserver ãè¦ãã¨ã
port ãçç¥ãã¦ãè¯ãã¨ããè¨è¿°ã¯ãªãã®ã§ã
çç¥ãããã¨ã¯ã§ãã¾ããã
ç§ã¯ãport ãçç¥ãã¦ããããåçåå解決ãã§ããªãã¦ã
2æéãããç¡é§ã«ãã¾ãã...ã
è¨å®ãã§ããããå
è¿°ã® ngrep
ãå®è¡ãã¦ããã¾ãã
service haproxy restart
ãã¦æºåå®äºã§ãã
ãã®æç¹ã§ãport 53 ã¸ã®éä¿¡ãå®æçã«ããã®ã§ã
åçåå解決ãã§ããããªäºæããã¾ãã
RDS ã® IP ã¢ãã¬ã¹ã確èªãã¦ãRDS ã failover ããã¾ãã
$ host test-db.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com test-db01.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com has address 10.2.0.200
ngrep
ã®æ§åãè¦ã¦ããã¨hold
ã®è¨å®ã¨ã¯é¢ä¿ãªãã
health check ã®ééãããã§åå解決ãã¦ããæ§åã確èªã§ãã¾ãã
RDS ã® A ã¬ã³ã¼ããæ¸ãæããã
HAProxy ã® health check ãæåããã¨ã
mysql-slave/master changed its IP from 10.2.0.200 to 10.1.0.100 by mydns/dns1. Server mysql-slave/master is UP, reason: Layer7 check passed, code: 0, info: "5.6.23", check duration: 1ms. 1 active and 0 backup servers online. 0 sessions requeued, 0 total in queue.
ã¨ãæ¥ç¶å
ãå¤ãã£ããã¨ããã°ã«åºåããã¾ãã
IP ã¢ãã¬ã¹ã確èªãã¦ãmysqladmin ping
ãnetstat
ã§ã確èªããã¨ã
$ host test-db.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com test-db01.xxxxxxxxxxxx.ap-northeast-1.rds.amazonaws.com has address 10.1.0.100 $ mysqladmin ping -u haproxy -h 127.0.0.1 -P 3307 mysqld is alive $ netstat -anp | grep 3306 tcp 0 0 10.1.0.10:57427 10.1.0.100:3306 TIME_WAIT -
failover å¾ã®ã¤ã³ã¹ã¿ã³ã¹ã«æ¥ç¶ãã¦ãããã¨ããããã¾ãã
ã¾ã¨ã
HAProxy 1.6.0 ããæ°è¡è¨å®ã追å ããã ãã§åçåå解決ã§ãããã¨ã示ãã¾ããã
ã¡ã³ããã³ã¹ã§ DNS åãæ¿ãããç¹ãããªããªã£ã...ã
ã¿ãããªãã¨ããªããªãã®ã§ä¾¿å©ããã§ããã
port åé¡ã§æ¶èããã®ã§ã½ã¼ã¹ã³ã¼ãã¯ãã¾ãèªãã¦ããªãã®ã§ã
詳細ãªæåãç¥ãããæ¹ã¯ããä¸èªããã ãã¨è¯ãã¨æãã¾ãã
â» æ¤è¨¼ããã¨ãã¯ã以ä¸ã®ãã¨ã«æ³¨æãã¦ãã ããã
- ããã¥ã¡ã³ããããèªã
- port ãçç¥ãã¦ã¯ãããªããport ãçç¥ããã®ã¯çã