ãã¼ããã©ã³ãµã¨ãã¦ã® pound 㨠nginx
èªå®
ã§éå¶ãã¦ããµã¤ãã®è² è·ããçµæ§é«ãã
ã§ã試ãã« pound ãå°å
¥ãããã ãã©ãã¢ã¯ã»ã¹æ°ãä¸ããã¨ãã©ãã«ãå®å®ããªãã
çµå± nginx ã§ã®ãã¼ããã©ã³ã¹ã«è½ã¡çãããã ããã©ãããã¾ã§ã®çµç·¯ãæ¸ãã¨ããã
ãããããã¥ã¼ãã³ã°ãã¦è¡ãä¸ã§ãpixiv ã®ä¸ã®äººã®è³æãé常ã«ãé常ã«ãåèã«ãªã£ãããããã¨ããããã¨ãã
pixivã®ã¤ã³ãã©ãæ¯ããæè¡ techsemi20090925_03_pixiv_kamipo.pdf
Pound ã§ã¢ã¯ã»ã¹ãå¢ãã㨠Too many open files ã¨ã©ã¼
ããã¤ããã£ã¡ãé »çºãã¾ãã解決çã¨ãã¦ã¯ãèµ·åã¹ã¯ãªãããªããã«
ulimit -n 50000
ã£ã¦æ¸ãã¦ããã°ãããã¨ããæ¤ç´¢çµæãå±±ã»ã©åºããã§ãããããã§ãã¨ã©ã¼ãæ¢ã¾ããªãã
試ãã«ãFile Discriptors ã®ã°ã©ããåã£ã¦ã¿ã¾ããã
äºæ³ã§ã¯ãå¾ã
ã«æ°å¤ãä¸ãã£ã¦ãã£ã¦ãå¶éå¤ã«å°éããã¨ããã§ã¨ã©ã¼ãåºå§ããã¨æã£ã¦ããã§ãã
ã§ããå
¨ç¶ãããªæããããªãã
ããã¿ã¤ãã³ã°ãããã°ãã¼ãã¨è·³ããããã¡ãããulimit -n 50000 ãã¦ãã®ã§ã許容éå
ã§ãã
- å®ãµã¼ããã¢ã¯ã»ã¹éå¤ã§æ»ã¬ï¼
- pound å´ã§ä½ããã®åé¡ãçºç
- ãã¥ã¼ãè©°ã¾ãå§ããï¼
- File Discriptors ã°ãã¼ãç¾è±¡
ãã®çµæãToo many open files ã¨ã©ã¼ãçºçãã¦ããã£ã½ãæãã
ãªã®ã§ãFile Discriptors ã®å¶éå¤ãåå ã§ã¯ãªãããã§ãã
ã¨ã©ã¼ã¨ãã¦ã¯ããããªã®ã大éã«åºã¦ã¾ãã
error copy chunk cont: Connection timed out copy_chunks flush error: Connection timed out
ã½ã¼ã¹ãè¦ã¦ã¿ã¦ããåå ã¯åãããã
ä¸åº¦ãããªã£ã¡ããã¨ãrestart ããªãã¨å¾©å¸°ãã¦ãããªãã®ã§ã大å¤é¢åã§ããã
Pound ã§ã¯ reset by peer ã¨ã©ã¼ãããããè¨é²ããã
reset by peer ç³»ã®ã¨ã©ã¼ã¯ãã¯ã©ã¤ã¢ã³ãããã¼ã¸ã®ãã¼ããå®äºããåã«
å¥ã®ãã¼ã¸ã¸ç§»åãããã¨ããå ´åãªã©ã«èµ·ããã¿ããã§ãã
ãªã®ã§ãè¨é²ããªãããã«ãããã£ãã®ã§ãã
ããããLogLevel 0 ã¨ãã«ãã¦ããããã¤ã¯è¨é²ãããããã§ãã
ãã°ãã¡ã¤ã«ã®å®¹éã大å¤ãªãã¨ã«ãªããã
ä»æ¹ãªãã®ã§ãã½ã¼ã¹ãå°ãæ¸ãæãã¦å¯¾å¿ãã¾ãããã
å¾®å¦ã«å¿çé度ãé
ããªã£ã¦ãã¾ãã¾ãã('A`)
svc.c ã® logmsg é¢æ°ã«è¿½è¨ããå 容ã
va_end(ap); /* ãããã追å */ if ( strstr( buf, "reset by peer" ) != NULL ) { return; } /* ããã¾ã§è¿½å */ if(log_facility == -1) {
æ©è½é¢ã®ä¸è¶³
pound ã«ã¯ãªããã© nginx ã«ã¯ããæ©è½ã¨ãã¦ã次ã®ãã®ãããã¾ãã
gzip ã§å§ç¸®ãã¦éä¿¡
ããã¨ãããæ
å ±ããgzip ã§å§ç¸®ãã¦ããã¯ã©ã¤ã¢ã³ãã«è¿ãæ©è½ãã¤ãã¦ããã
ã¾ããgzip ã«å¯¾å¿ãã¦ããªãã¯ã©ã¤ã¢ã³ãã«ã¯ãã®ã¾ã¾è¿ããã¨ãã£ãæ©è½ãåãã£ã¦ããã
gzip ã§ã®éä¿¡ã ON ã«ããçµæãéä¿¡éãããªãæ¸ã£ãã
LBé¯ãªã®ã§ãinbound ã«å¯¾ã㦠outbound ãããªãæ¸ããã¨ã«ãªãã
ãã¡ã¤ã«ã®ãã£ãã·ã¥
nginx ã§ã¯ãæ¡å¼µåãªã©ãæå®ãã¦ããã¡ã¤ã«ããã£ãã·ã¥ããæ©è½ãããã
ãã®æ©è½ãç¨ããã¨ãããã¯ã¨ã³ãã®ãµã¼ãã¨ã®éä¿¡éãæ¸ãããã¨ãã§ããã
ãããå®æ½ããçµæãéä¿¡éãã¬ãããªæ¸ã£ãã
LBé¯ã¯ããã£ãã·ã¥ããã¦ããåãinbound ãæ¸ã£ã¦ããã
ããã¯ã¨ã³ãé¯ã¯ãéä¿¡éãæ¸ããã¨ã«ãªããã¤ã¤ãï¼
çµè«
çµè«ã¨ãã¦ã¯ããã¯ããnginx ãããã¼ã¨ããæãã
pound ãæªãã¯ãªããã ãã©ã使ãã©ãããã¡ãã£ã¨éã£ãã®ããªãã
éçºãçã㪠nginx ãé¸ãã æ¹ããç¡é£ãªã®ãããããªãã
ãã¾ã1 poundã®ã¤ã³ã¹ãã¼ã«æé
pound ã®ã¤ã³ã¹ãã¼ã«
yum -y install openssl-devel cd /usr/local/src wget http://www.apsis.ch/pound/Pound-2.6.tgz tar zxvf Pound-2.6.tgz cd Pound-2.6 ./configure make make install vi /usr/local/etc/pound.cfg
LogLevel 3 # å¿ è¦ã«å¿ãã¦å¤æ´ã0ã ã¨ãã°ãè¨é²ããªãã LogFacility local1 ListenHTTP Address *.*.*.* # ãã¼ããã©ã³ãµã®å¾ ã¡åãIP Port 80 # ãã¼ããã©ã³ãµã®å¾ ã¡åããã¼ã Service # server1 BackEnd # BackEnd ã End éã«ãå®ãµã¼ããè¨è¿°ã #HeadRequire "Host: .*www.server1.com.*" # ãã¡ã¤ã³åã§æ¯ãåããã¨ãã¯ããã®ããã«è¨è¿°ããã #HeadDeny "Host: .*www.server0.com.*" Address *.*.*.* Port 80 Priority 1 # åªå 度ã1ã9ã§æå®ã End # server2 BackEnd Address *.*.*.* Port 80 Priority 1 End End End
vi /etc/rc.d/init.d/pound # èµ·åã¹ã¯ãªããã®ä½æ
é©å½ã«æ¾ã£ã¦ãããã®ã
#!/bin/sh # # pound # # chkconfig: 345 85 15 # description: reverse-proxy and load-balancer # # Source function library . /etc/rc.d/init.d/functions # Get network config . /etc/sysconfig/network # Pound Directory POUND="/usr/local/sbin/pound" CFG="/usr/local/etc/pound.cfg" # See how we were called. case "$1" in start) # Check if the normal service is already running? if [ ! -f /var/lock/subsys/pound ]; then echo "Starting pound:" $POUND -f $CFG RETVAL=$? [ $RETVAL -eq 0 ] && touch /var/lock/subsys/pound echo ${base} else #msg_Already_Running pound echo "pound already started." # exit 1 fi ;; stop) # Stop daemons. if [ -f /var/lock/subsys/pound ]; then #msg_stopping pound echo "Stopping pound:" killall $POUND rm -f /var/lock/subsys/pound > /dev/null 2>&1 echo else echo "pound is not running." exit 1 fi ;; restart|reload) $0 stop $0 start ;; configtest) $POUND -c -v -f $CFG ;; *) echo "usage: pound {start|stop|configtest|restart}" exit 1 ;; esac exit $RETVA
chmod +x /etc/rc.d/init.d/pound
ãã°åºåè¨å®
rsyslog ã§ã¯ãªã syslog ã使ã£ã¦ããå ´åã¯ãrsyslog ã syslog ã«èªã¿æ¿ãã¦è¨å®ããã
vi /etc/rsyslog.conf
# *.info;mail.none;authpriv.none;cron.none; /var/log/messages *.info;mail.none;authpriv.none;cron.none;local1.none /var/log/messages # å¤æ´ # 以ä¸ã®è¡ã追å local1.* /var/log/pound
service rsyslog restart
pound ã®èµ·å
service httpd stop # Apache ãèµ·åãã¦ãããªããåæ¢ãã¦ããã service pound start # Pound ã®èµ·å chkconfig pound on # Pound ã®èªåèµ·åè¨å®
Web ãµã¼ã (åæ£å ãµã¼ã) ã®ã¢ã¯ã»ã¹ãã°è¨å®
vi /etc/httpd/conf/httpd.conf
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" combined # å¤æ´
service httpd restart
ãã¾ã2 nginx ã®ã¤ã³ã¹ãã¼ã«æé
nginx ã¤ã³ã¹ãã¼ã«
yum -y install pcre-devel cd /usr/local/src wget http://nginx.org/download/nginx-1.2.4.tar.gz tar zxvf nginx-1.2.4.tar.gz cd nginx-1.2.4 ./configure make make install
nginx è¨å®
mkdir /var/log/nginx vi /usr/local/nginx/conf/nginx.conf
worker_processes 4; pid /var/run/nginx.pid; events { worker_connections 1024; } http { proxy_cache_path /var/cache/nginx/static_file_cache levels=1:2 keys_zone=cache_static_file:128m inactive=1d(â1æ¥ã¢ã¯ã»ã¹ããªãã£ããåé¤) max_size=512m; proxy_temp_path /var/cache/nginx/temp; sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; include /usr/local/nginx/conf/mime.types; default_type application/octet-stream; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; gzip on; gzip_disable "msie6"; include /etc/nginx/conf.d/*.conf; server { listen *.*.*.*<åä»IP>:80; server_name www.hoge.com; location / { proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; set $do_not_cache 0; if ($request_method != GET) { set $do_not_cache 1; } if ($uri !~* ".(jpg|png|gif|jpeg|css|js|swf|pdf|html|htm)$") { set $do_not_cache 1; } proxy_no_cache $do_not_cache; proxy_cache_bypass $do_not_cache; proxy_cache cache_static_file; proxy_cache_key $scheme$host$uri$is_args$args; proxy_cache_valid 200 1h; proxy_cache_valid any 1m; proxy_pass http://backend; } } upstream backend { # server1 server *.*.*.* weight=1; # server2 server *.*.*.* weight=2; } }
èµ·åã¹ã¯ãªããã®ä½æ
vi /etc/init.d/nginx
é©å½ã«æ¾ã£ã¦ãããã®ã
#!/bin/sh # # nginx - this script starts and stops the nginx daemon # # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # proxy and IMAP/POP3 proxy server # processname: nginx # config: /usr/local/nginx/conf/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" = "no" ] && exit 0 nginx="/usr/local/nginx/sbin/nginx" prog=$(basename $nginx) NGINX_CONF_FILE="/usr/local/nginx/conf/nginx.conf" [ -f /etc/sysconfig/nginx ] && . /etc/sysconfig/nginx lockfile=/var/lock/subsys/nginx make_dirs() { # make required directories user=`$nginx -V 2>&1 | grep "configure arguments:" | sed 's/[^*]*--user=\([^ ]*\).*/\1/g' -` if [ -z "`grep $user /etc/passwd`" ]; then useradd -M -s /bin/nologin $user fi options=`$nginx -V 2>&1 | grep 'configure arguments:'` for opt in $options; do if [ `echo $opt | grep '.*-temp-path'` ]; then value=`echo $opt | cut -d "=" -f 2` if [ ! -d "$value" ]; then # echo "creating" $value mkdir -p $value && chown -R $user $value fi fi done } start() { [ -x $nginx ] || exit 5 [ -f $NGINX_CONF_FILE ] || exit 6 make_dirs echo -n $"Starting $prog: " ulimit -n 50000 # â 念ã®ããã daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval -eq 0 ] && touch $lockfile return $retval } stop() { echo -n $"Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval -eq 0 ] && rm -f $lockfile return $retval } restart() { configtest || return $? stop sleep 1 start } reload() { configtest || return $? echo -n $"Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status >/dev/null 2>&1 } case "$1" in start) rh_status_q && exit 0 $1 ;; stop) rh_status_q || exit 0 $1 ;; restart|configtest) $1 ;; reload) rh_status_q || exit 7 $1 ;; force-reload) force_reload ;; status) rh_status ;; condrestart|try-restart) rh_status_q || exit 0 ;; *) echo $"Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload|configtest}" exit 2 esac
nginx ã®èµ·å
service httpd stop # Apache ãèµ·åãã¦ãããªããåæ¢ãã¦ããã service nginx start # nginx ã®èµ·å chkconfig nginx on # nginx ã®èªåèµ·åè¨å®
ä½è«
åæ£ããç¨åº¦ã«ãµã¼ãã®å°æ°ãå¢ãã¦ããã¨ãå
¨ã¦ã®ãµã¼ãã«å¯¾ãã¦ä½æ¥ããã®ã¯ä½ãã¨é¢åã
capistrano ãå
¥ããããä¸çãå¤ããã¾ããã便å©ãããããã®è¾ºã®è¨äºã¯ãã¾ãç¸ãããã°ã
ãã¨ãå
¨ææ¤ç´¢ã«ã¤ãã¦ãè¦ç´ãã
mysql 㧠hoge LIKE "%keyword%" ã¿ãããªã¯ã¨ãªããã£ã¨ä½¿ã£ã¦ãããã ãã©ããã
tritonn 㧠match(hoge) against(keyword) ã«å¤ããããDBãµã¼ããè³¢è
ã¢ã¼ãã«ãªãã¾ããã
æåãã tritonn ãã£ããã§ãããããªæ°ãããã¬ãã«ã ãªãã
ãããã¾ãæ©ä¼ãããã°ãè¨äºã«ããããã