¸¶Ä§ ¼ºñ½º ¿î¿µÁß nginx + php + mysql + memcached ¸¦ ¼³Ä¡ÇÒ ±âȸ°¡ »ý°å±â¿¡, ±ÛÀ» ¿Ã¸°´Ù.
<¼³Ä¡È¯°æ>
CentOs 5.7 64bit
nginx 1.0.11
php 5.2.17
php-5.2.17-fpm-0.5.14
## mysql Àº ¼öµ¿À¸·Î ¼³Ä¡ (°æ·Î /usr/local/mysql ±âÁØ)
1. [NGINX ¼³Ä¡]
$ cd /usr/local/src
$ wget
http://nginx.org/download/nginx-1.0.11.tar.gz$ tar xvfzp nginx-1.0.11.tar.gz
$ cd /usr/local/src/nginx-1.0.11
$ ./configure --prefix=/usr/local/nginx --with-http_ssl_module
$ make
$ make install
¼³Ä¡°¡ ¿Ï·á µÇ¾úÀ¸¸é, ¾Æ·¡ ½ºÅ©¸³Æ®¸¦ ¹Þ¾Æ¼,
¼¹ö¿¡ ÀúÀåÇÑ ÈÄ, /etc/init.d/nginx ¿Í °°ÀÌ ¼¼ÆÃÇÑ´Ù.
$ mv nginx.txt /etc/init.d/nginx
$ chmod 755 /etc/init.d/nginx
nginx ¸¦ ±¸µ¿Çغ¸ÀÚ.
$ /etc/init.d/nginx start
Starting nginx:
$ netstat -lnp
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 30164/nginx.conf
À§¿Í °°ÀÌ nginx ¸¦ ±¸µ¿ÇßÀ»¶§ 80Æ÷Æ®°¡ º¸´Â°Í°ú °°ÀÌ ³ª¿À¸é µÈ´Ù.
ÀÎÅͳݺê¶ó¿ìÀú â¿¡¼, http://¼³Ä¡¼¹öIP ¸¦ ÀÔ·ÂÇغ¸¸é
Welcome to nginx!
À§¿Í °°ÀÌ ³ª¿À´Âµ¥, ÀÌ·¸°Ô ³ª¿À¸é, nginx ¼³Ä¡°¡ ¿Ï·á µÈ °ÍÀ¸·Î º¸¸é µÈ´Ù.
2. php + php-fpm ¼³Ä¡
$ cd /usr/local/src
$ wget
http://kr2.php.net/get/php-5.2.17.tar.gz/from/this/mirror$ wget
http://php-fpm.org/downloads/php-5.2.17-fpm-0.5.14.diff.gz$ tar xvfzp php-5.2.17.tar.gz
$ gzip -cd php-5.2.17-fpm-0.5.14.diff.gz | patch -d php-5.2.17 -p1
$ cd php-5.2.17
¾Æ·¡ configure ÆÄÀÏÀ» ¹Þ¾Æ¼, µ¿ÀÏÇÏ°Ô ¼³Ä¡ ÇÑ´Ù.
$ make; make install
Installing PHP SAPI module: cgi
Installing PHP CGI binary: /usr/local/php-fpm/bin/
Installing FPM config: /usr/local/php-fpm/etc/php-fpm.conf
(installing as php-fpm.conf.default)
Installing init.d script: /usr/local/php-fpm/sbin/php-fpm
Installing PHP CLI binary: /usr/local/php-fpm/bin/
Installing PHP CLI man page: /usr/local/php-fpm/man/man1/
Installing build environment: /usr/local/php-fpm/lib/php/build/
Installing header files: /usr/local/php-fpm/include/php/
Installing helper programs: /usr/local/php-fpm/bin/
program: phpize
program: php-config
Installing man pages: /usr/local/php-fpm/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /usr/local/php-fpm/lib/php/
[PEAR] Archive_Tar - installed: 1.3.7
[PEAR] Console_Getopt - installed: 1.2.3
[PEAR] Structures_Graph- installed: 1.0.3
[PEAR] XML_Util - installed: 1.2.1
[PEAR] PEAR - installed: 1.9.1
Wrote PEAR system config file at: /usr/local/php-fpm/etc/pear.conf
You may want to add: /usr/local/php-fpm/lib/php to your php.ini include_path
Installing PDO headers: /usr/local/php-fpm/include/php/ext/pdo/
¼³Ä¡°¡ ¿Ï·á µÇ¾úÀ¸¸é, php.ini ¸¦ º¹»çÇÑ ÈÄ, php-fpm À» ½Éº¼¸¯¸µÅ©¸¦ °É¾î, À§Ä¡¿¡ ÀúÀåÇÑ´Ù.
$ cd /usr/local/src/php-5.2.17
$ cp -a php.ini-dist /usr/local/php-fpm/lib/php.ini
$ cd /etc/init.d/
$ ln -s /usr/local/php-fpm/sbin/php-fpm php-fpm
$ /etc/init.d/php-fpm start
Starting php_fpm Jan 04 10:01:30.274536 [ERROR] fpm_unix_conf_wp(), line 124: please specify user and group other than root, pool 'default'
................................... failed
php-fpm À» ±¸µ¿½ÇÇà ÇÏ¿´´õ´Ï ´ÙÀ½°ú °°ÀÌ ¿¡·¯°¡ ¹ß»ýÇÑ´Ù. ÀÌ´Â, »ç¿ëÇÏ´Â user ¿Í group ÀÌ Á¤»óÀûÀ¸·Î ¼³Á¤µÇÁö ¾Ê¾Ò´Ù´Â ÀÇ¹Ì ÀÌ´Ù. php-fpm.conf ÆÄÀÏ¿¡ 62¹ø ~66¹ø ¶óÀÎÀ» ¾Æ·¡¿Í °°ÀÌ ¼öÁ¤ÇÑ´Ù.
$ vi /usr/local/php-fpm/etc/php-fpm.conf
<!-- Unix user of processes -->
<value name="user">nobody</value>
<!-- Unix group of processes -->
<value name="group">nobody</value>
¼öÁ¤ ÈÄ, ´Ù½Ã ½ÇÇàÇØ º»´Ù.
$ /etc/init.d/php-fpm start
Starting php_fpm done
$ netstat -lnp | grep php
tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 26544/php-cgi
Á¤»óÀûÀ¸·Î php-fpm ÀÌ ±¸µ¿µÈ°ÍÀÌ È®ÀÎ µÇ¾ú´Ù.
3. zend ¼³Ä¡
Áö±Ý ¼³Ä¡ÇÏ´Â°Ç 64bit ¿¡ ¼³Ä¡ÇÏ´Â °ÍÀ̱⿡, 64bit ¸¦ ´Ù¿î·Îµå ¹Þ¾ÒÁö¸¸, 32bit ÀÎ °æ¿ì, 32bit ¸¦ ´Ù¿î¹ÞÀ¸¸é µÇ°Ú´Ù.
64bit ÀÎ °æ¿ì
$ cd /usr/local/src
$ wget
http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
32bit Àΰæ¿ì
$ cd /usr/local/src
$ wget http://downloads.zend.com/optimizer/3.3.9/ZendOptimizer-3.3.9-linux-glibc23-i386.tar.gz
¾ÐÃàÀ» ÇØÁ¦ÇÏ°í, php ¹öÀü¿¡ ¸Â´Â ZendOptimizer.so ÆÄÀÏÀ» º¹»çÇÑ´Ù.
$ tar xvfzp ZendOptimizer-3.3.9-linux-glibc23-x86_64.tar.gz
$ cd ZendOptimizer-3.3.9-linux-glibc23-x86_64/data
$ ls -al
drwxr-xr-x 2 root root 4096 Aug 24 2009 4_2_0_comp
drwxr-xr-x 2 root root 4096 Aug 24 2009 4_2_x_comp
drwxr-xr-x 2 root root 4096 Aug 24 2009 4_3_x_comp
drwxr-xr-x 2 root root 4096 Aug 24 2009 4_4_x_comp
drwxr-xr-x 2 root root 4096 Aug 24 2009 5_0_x_comp
drwxr-xr-x 2 root root 4096 Aug 24 2009 5_1_x_comp
drwxr-xr-x 2 root root 4096 Aug 24 2009 5_2_x_comp
ÇöÀç ¼³Ä¡ ÇÑ php ¹öÀüÀº 5.2.17 À̱⶧¹®¿¡ °¡Àå¹Ø¿¡ ÀÖ´Â 5_2_x_comp Æú´õ¿¡ ÀÖ´Â ZendOptimizer.so ¸¦ »ç¿ëÇÒ°ÍÀÌ´Ù.
$ cp -a /usr/local/src/ILAYA/SOURCE/ZendOptimizer-3.3.9-linux-glibc23-x86_64/data/5_2_x_comp/ZendOptimizer.so /usr/local/php-fpm/lib/
Zend ¼³Ä¡°¡ ¿Ï·á µÇ¾úÀ¸¸é, php.ini ¿¡ Zend °æ·Î¸¦ ÀúÀåÇÑ´Ù.
$ vi /usr/local/php-fpm/lib/php.ini
°¡Àå ÇÏ´Ü¿¡ ¾Æ·¡ ³»¿ë Ãß°¡
[Zend]
zend_extension=/usr/local/php-fpm/lib/ZendOptimizer.so
ÀúÀåÀÌ ¿Ï·á µÇ¾úÀ¸¸é, ÀÌÁ¦ nginx ¿Í php-fpm À» ¿¬µ¿ÇÑ´Ù.
$ vi /usr/local/nginx/conf/nginx.conf
¾à 63 ¶óÀÎÁ¤µµ¿¡ ÁÖ¼®À¸·Î ÀÖ´Â ¿É¼ÇµéÀÌ Àִµ¥, ÁÖ¼®³»¿ëÀº Áö¿öµµ ¹«¹æÇϸç, ÆÄÀÏ ³»¿ë¿¡ ¾Æ·¡ ¿É¼ÇÀ» Ãß°¡ÇÑ´Ù.
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param scRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
Ãß°¡°¡ ¿Ï·á µÇ¸é, ÀÌÁ¦ nginx ¿Í php-fpm À» À籸µ¿ÇØÁØ´Ù.
$ /etc/init.d/php-fpm stop;/etc/init.d/nginx stop
$ /etc/init.d/php-fpm start;/etc/init.d/nginx start
½ÇÁ¦ ¿¬µ¿ÀÌ µÇ¾ú´ÂÁö Å×½ºÆ®¸¦ Çغ¸ÀÚ.
nginx ÀÇ ±âº» Ȩ°æ·Î´Â /usr/local/nginx/html ÀÌ´Ù, (¾ÆÆÄÄ¡ÀÇ °æ¿ì´Â /usr/local/apache/htdocs)
ÇØ´ç °æ·Î¿¡ ±âº» phpinfo ÆÄÀÏÀ» »ý¼ºÇÑ´Ù.
$ cd /usr/local/nginx/html
vi test.php
< ?
phpinfo
?>
À§ÀÇ ³»¿ë Ãß°¡
ºê¶ó¿ìÀúâ¿¡¼ È®ÀÎÇغ»´Ù. (mysql ¿¬µ¿±îÁö È®ÀÎ)
À§¿Í °°ÀÌ µÇ¾úÀ¸¸é Á¤»óÀûÀ¸·Î ¿¬µ¿ µÈ°ÍÀÌ´Ù.
4. memcache ¼³Ä¡
memcached ´Â ¸Þ¸ð¸®¸¦ ij½Ã·Î »ç¿ëÇÏ´Â ºÐ»ê ¼Ö·ç¼ÇÀ¸·Î ¼¹öºÎÇÏ°¡ ¸¹Àº »çÀÌÆ®¿¡ ¿î¿µÇϸé, È¿°ú¸¦ º¼ ¼ö ÀÖ´Ù.
1) libevent ¼³Ä¡
$ cd /usr/local/src
$ wget
http://monkey.org/~provos/libevent-1.4.13-stable.tar.gz$ tar xvfzp libevent-1.4.13-stable.tar.gz
$ cd libevent-1.4.13-stable
$ ./configure ; make ; make install
2) memcached ¼³Ä¡
$ cd /usr/local/src
$ wget
http://memcached.googlecode.com/files/memcached-1.4.10.tar.gz$ tar xvfzp memcached-1.4.10.tar.gz
$ cd memcached-1.4.10
$ LDFLAGS='-Wl,--rpath /usr/local/lib' ./configure --prefix=/usr/local --enable-64bit
$ make
$ make install
$ cd scripts
$ cp -a memcached.sysv /etc/init.d/memcached
$ chown root.root /etc/init.d/memcached
$ chmod 755 /etc/init.d/memcached
$ vi /etc/init.d/memcached
PORT=11211
USER=root
MAXConN=1024
CACHESIZE=512
OPTIonS=""
PATH="/usr/local/bin:$PATH"
À§¿Í °°ÀÌ Ãß°¡µÈ PATH ÀÇ °æ¿ì, memcached °¡ ¼³Ä¡µÇ¾î Àִ°æ·Î¸¦ "whereis memcached" ¸¦ ÀÔ·ÂÇÏ¿© ã¾Æ³½ °ª
$ mkdir /var/run/memcached
$ /etc/init.d/memcached start
$ netstat -lnp
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 24933/memcached
memcached °¡ Á¤»óÀûÀ¸·Î ¿Ã¶ó¿Ô´ÂÁö È®ÀÎ.
14:41:22 $ telnet localhost 11211
Trying 127.0.0.1...
Connected to localhost.localdomain (127.0.0.1).
Escape character is '^]'.
stats
STAT pid 24933
STAT uptime 2618
STAT time 1325655685
STAT version 1.4.10
STAT libevent 1.4.13-stable
STAT pointer_size 64
STAT rusage_user 0.000999
STAT rusage_system 0.011998
STAT curr_connections 5
STAT total_connections 7
STAT connection_structures 6
STAT reserved_fds 20
STAT cmd_get 0
STAT cmd_set 0
STAT cmd_flush 0
STAT cmd_touch 0
STAT get_hits 0
STAT get_misses 0
STAT delete_misses 0
STAT delete_hits 0
STAT incr_misses 0
STAT incr_hits 0
STAT decr_misses 0
STAT decr_hits 0
STAT cas_misses 0
STAT cas_hits 0
STAT cas_badval 0
STAT touch_hits 0
STAT touch_misses 0
STAT auth_cmds 0
STAT auth_errors 0
STAT bytes_read 29
STAT bytes_written 1040
STAT limit_maxbytes 536870912
STAT accepting_conns 1
STAT listen_disabled_num 0
STAT threads 4
STAT conn_yields 0
STAT hash_power_level 16
STAT hash_bytes 524288
STAT hash_is_expanding 0
STAT expired_unfetched 0
STAT evicted_unfetched 0
STAT bytes 0
STAT curr_items 0
STAT total_items 0
STAT evictions 0
STAT reclaimed 0
END
3) memcached client ¼³Ä¡
$ cd /usr/local/src
$ wget
http://pecl.php.net/get/memcache-2.2.6.tgz$ tar xvfzp memcache-2.2.6.tgz
$ cd memcache-2.2.6
$ /usr/local/php-fpm/bin/phpize
$ ./configure --with-php-config=/usr/local/php-fpm/bin/php-config
$ make
$ make install
$ vi /usr/local/php-fpm/lib/php.ini
extension_dir = "/usr/local/php-fpm/lib/php/extensions/no-debug-non-zts-20060613"
extension="memcache.so"
°ª Ãß°¡
$ /etc/init.d/php-fpm stop
$ /etc/init.d/nginx stop
$ /etc/init.d/php-fpm start
$ /etc/init.d/nginx start
ÀÛ¾÷ÀÌ ¿Ï·á µÇ¾úÀ¸¸é, phpinfo »ó¿¡ memcache °¡ Á¤»óÀûÀ¸·Î ¿Ã¶ó¿ÍÀÖ´ÂÁö È®ÀÎÇÑ´Ù.
À§¿Í °°ÀÌ ³ª¿À¸é Á¤»óÀûÀ¸·Î µÈ °ÍÀÌ´Ù.