Results for "WEB&WAS"
Centos7(센트7)에서 apache+php+mysql (apm) 설치 및 구성 - 2
[설치환경]
OS : CentOS 7.1   64bit
CPU: Intel(R) Core(TM) i5-2500 CPU @ 3.30GHz
Ram : 1G
SWAP : 1G

작성자 : 서비님(https://dslee1.blogspot.kr/)

--------------------------------------------------------------------------------------
이 포스팅과 관련된 포스팅


본 포스팅은 이전포스팅과 이어서 연재되어 있기 때문에 [Centos7(센트7)에서 apache+php+mysql (apm) 설치 및 구성 - 1] 포스팅을 참고하면 된다.


2-3 Apache 설치

apache.org 공식홈페이지에서 최신버전을 다운로드 받도록 한다
wget http://archive.apache.org/dist/httpd/httpd-2.4.18.tar.bz2

tar xvf httpd-2.4.18.tar.bz2
cd httpd-2.4.18

preforck 방식 및 worker 방식의 최대접속 값을 지정하는것이다. 기본값은 너무 낮게 설정되어있기 때문에 튜닝이 필요하다.
vi server/mpm/prefork/prefork.c
#define DEFAULT_SERVER_LIMIT 4096 (수정)
vi server/mpm/worker/worker.c
#define DEFAULT_SERVER_LIMIT 20

ssl 인증서를 함께 사용해야되기 때문에 그에 관련된 개발도구를 설치하도록한다.
yum install openssl-devel

환경설정 및 본격적인 설치를 진행하도록 한다.
./configure --prefix=/usr/local/httpd-2.4.18 --enable-mods-shared=most --enable-ssl  --enable-modules=ssl --enable-rewrite --with-included-apr --with-included-apr-util --enable-deflate --enable-expires --enable-headers --enable-proxy --enable-mpms-shared=all --with-mpm=event && make && make install

동작방식은 기본 event 방식을 취한다. prefork 및 worker 방식보다 좋기 때문이다.

[TIP]
설치 진행과정중 아래와 같은 에러메시지가 확인되면, [apache 설치중 error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util 해결방법] 포스팅을 참고하면 해결할수 있다.

configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

에러문제가 해결되었으면, 다시 apache 디렉토리로 이동해서 설치를 다시 진행한다.

설치가 완료된 모습이다.

설치된 디렉토리를 간편하게 보기위해서 링크를 걸어준다.
ln -s /usr/local/httpd-2.4.18/ /usr/local/apache

httpd.conf 파일 및 여러 환경설정 변경 방법은. [Apache(httpd.conf 아파치환경설정) 튜닝] 포스팅를 참고하면 된다.


2-4 PHP 설치

기본적으로 설치는
cd /usr/local/src
이곳에서 진행 한다.

아래 공식홈페이지에서 php7 버전을 다운로드 한다

wget http://ar2.php.net/get/php-7.0.4.tar.gz/from/this/mirror -O php-7.0.4.tar.gz
tar xvfz php-7.0.4.tar.gz
cd php-7.0.4

./configure --prefix=/usr/local/php-7.0.4 --with-config-file-path=/usr/local/php-7.0.4/lib --with-apxs2=/usr/local/apache/bin/apxs --with-gd --with-freetype-dir --with-zlib --enable-sockets --enable-gd-native-ttf --with-png-dir --with-jpeg-dir --enable-sigchild --with-gettext --enable-mbstring --enable-inline-optimization --enable-bcmath --enable-shmop --enable-calendar --enable-ftp --with-gdbm --with-iconv --enable-mbregex --with-openssl --with-curl=/usr/local/curl/ --enable-soap --disable-debug --with-mcrypt --with-kerberos --enable-zip --with-zlib-dir --enable-exif --enable-fpm --with-fpm-user=nobody --with-fpm-group=nobody --with-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-pdo-mysql=shared,/usr/local/mysql && make && make install

[TIP]
error: mcrypt.h not found. Please reinstall libmcrypt
위와 같은 에러가 발생되면 [php설치 중 에러 error: mcrypt.h not found. Please reinstall libmcrypt 해결방법] 다른 포스팅을 참고하면 해결할수 있다.


make: *** [ext]mysqli]mysqli_embedded.lo] 오류 1
마지막줄에 이런 에러가 발생하면 [php7.x 설치시 error: too many arguments to function ‘zend_hash_get_current_data_ex’ 에러 해결방법] 이곳 포스팅을 참고하면 해결할수 있다.


정상적으로 설치가 완료되었으면 위와같은 화면을 확인할수 있다.

앞에서 심볼링 링크 작업한것처럼 이곳에서도 작업을 진행한다. 소스컴파일을 할 경우 수동으로 작업해줘야되는 부분이 많이 존재한다.
ln -s /usr/local/php-7.0.4/ /usr/local/php
ln -s /usr/local/php/bin/php /usr/sbin/
ln -s /usr/local/php/bin/phpize /usr/sbin/

php -v
PHP 7.0.4 (cli) (built: Apr  8 2016 16:41:41) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies

php.ini 환경설정값을 php 설치된 디렉토리로 복사한다.
cp /usr/local/src/php-7.0.4/php.ini-development /usr/local/php-7.0.4/lib/php.ini


문제 없이 서비스가 올라가졌다면, 위와 같이 열려있는 포트를 확인할수 있게 된다.

[TIP]
php 초기설정
vi /usr/local/php-7.0.4/lib/php.ini

short_open_tag = On 
error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_STRICT 
display_errors = On 
date.timezone = "Asia/Seoul" 

[설치 확인방법]

APM 설치가 정상적으로 완료되었는지 최종확인하는 방법이다. 아파치 초기 index.html 파일을 수정하면 된다.

vi /usr/local/apache/htdocs/index.php
###추가####
<?php
phpinfo();
?>
######

최종확인
http://192.168.0.5

성공이다.

이곳에서 각종 설정값을 확인할수있다.

시골청년 2016년 4월 8일 금요일
Centos7(센트7)에서 apache+php+mysql (apm) 설치 및 구성 - 1
[설치환경]
OS : CentOS 7.1   64bit
CPU: Intel(R) Core(TM) i5-2500 CPU @ 3.30GHz
Ram : 1G
SWAP : 1G

작성자 : 서비님(https://dslee1.blogspot.kr/)


1. 개요

리눅스는 대부분 서버를 구성하기 위해서 많이 사용한다. 윈도우처럼 데스크탑용으로 사용하는 경우는 극히 드물며, centos 의 경우는 더더욱 사용률이 적다. 특히 우리나라는 데스크탑 사용자는 찾아보기가 힘들다는게 많은 아쉬움이 남는다.

오늘은 그래서 서버용으로 설치된 centos7 에 많은 사람들이 사용하는 apache+php+mysql 설치 및 구성에 대해서 살펴볼 것이다. 또한 현재 일자(2016.4.8) 기준으로 최신버전을 다운받아 설치할것이며, 간단한 테스트용 사이트 화면까지 확인하고 글을 마무리할 예정이다.

설치 버전은 다음과 같다.
   - apache 2.4.x
   - php 7.x
   - mysql 5.6.x
들어가기에 앞서 다른포스팅 [centos7 (센트7) 설치 및 구성]  이곳을 참고하여 centos7 을 미리 설치하도록 한다.


2. 설치 및 구성

기본적으로 centos 가 설치된 상태에서 혹시나 rpm 으로 apache+php+mysql(apm) 이 설치가 되어있다면, 지우는걸 추천한다.

yum remove -y httpd*
yum remove -y php*
yum remove -y mysql*

rpm 으로 설치된 어플리케이션은 소스컴파일보다 여러가지 설정을 컨트롤 하기 쉽지 않으며, 소스컴파일은 설치 과정에서 조금더 최적화 를 진행할수 있는게 장점이다. 또한 디렉토리 관리 데이터 관리 또한 간편하다. (이건 주관적인 입장이다)

그래서 본 포스팅은 소스컴파일 위주로 진행하고, 부득이한 부분은 yum 으로 대처하도록 하겠다.

설치 순서는 필수라이브 러리 -> mysql -> apache -> php 순으로 진행 할 예정이다. 설치는 크게 어렵지 않으며, 순서대로 잘 따라와주면 된다.


2-1 필수라이브러리 설치

apache+php+mysql 설치에 앞서 리눅스 os 시스템에 필수 라이브러리를 설치해야된다. yum 을 이용해서 설치하도록 한다.

yum -y install vim php-gd
yum -y install net-tools
yum -y install zlib libpng freetype jpeg gd libxml2
yum -y install freetype-devel
yum -y install gmp-devel
yum -y install libX11-devel
yum -y install libtermcap-devel ncurses-devel
yum -y install make cmake
yum -y install gcc g++ cpp gcc-c++
yum -y install perl
yum -y install gdbm-devel
yum -y install ncurses-devel
yum -y install bison
yum -y install zlib curl
yum -y install curl-devel
yum -y install openssl openssl-devel
yum -y install bzip2-devel
yum -y install libtermcap-devel libc-client-devel
yum -y install wget unzip
yum -y install libxml2*
yum -y install bzip2*
yum -y install libjpeg-devel
yum -y install expat-devel*
yum -y install gd-devel*
yum install -y perl-Module-Install.noarch

ln -s /usr/lib64/libjpeg.so /usr/lib

ln -s /usr/lib64/libpng.so /usr/lib
ln -s /usr/lib64/libXpm.so.4 /usr/lib64/libXpm.so

2-2 mysql 설치

mysql 설치 버전은 5.6.30 버전이다(현재 2016.4.8일자). 각각의 버전별로 설치방법이 조금씩 다르고 구성방법들도 조금씩 달라졌다. 왜 5.6.x 버전을 설치하는지 이유는 간단하다. 이전버전보다 훨씬더 좋은 퍼포먼스를 제공하고 있기 때문이다. 당연한 말이지만..
(5.7.x 버전의 경우 php 라이브러리 연동문제가 발생하여 현재 분석이 조금더 필요하다)

자 그럼 아래 설치순서를 진행해보자.

mysql 을 다운받는다.
wget http://dev.mysql.com/get/Downloads/MySQL-5.6/mysql-5.6.30.tar.gz

cmake 를 이용해서 configuration 및 make install 를 함께 진행하도록 한다.
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql-5.6.30 -DMYSQL_DATADIR=/usr/local/mysql-5.6.30/data -DDEFAULT_CHARSET=utf8 -DDEFAULT_COLLATION=utf8_general_ci -DWITH_EXTRA_CHARSETS=all -DENABLED_LOCAL_INFILE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DMYSQL_UNIX_ADDR=/tmp/mysql.sock -DSYSCONFDIR=/etc -DMYSQL_TCP_PORT=3306 && make && make install

설치된 mysql 디렉토리를 심볼릭링크로 쉽게 접근할수있도록 변경한다.
ln -s /usr/local/mysql-5.6.30/ /usr/local/mysql

mysql 실행 유저를 생성한다
useradd mysql

mysql 디렉토리 권한을 mysql 실행유저로 변경을 해줘야지 서비스가 정상적으로 올라갈수있다.
chown -R mysql.mysql /usr/local/mysql-5.6.30
ln -s /usr/local/mysql-5.6.30/ /usr/local/mysql

Centos 6.x 버전 이전에 사용하던 시스템 서비스 관리 명령어를 실행하기 위해서 링크를 걸어주는것이다. 이렇게 링크 설정을 하게되면, /etc/init.d/mysqld start 식으로 명령어를 실행할수있으며 service mysqld start 도 동일하다.
ln -s /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld

mysql data 파일을 생성하는 명령어다. 쉽게 말해서 초기 DB 구성 및 환경설정 작업을 진행한다.
/usr/local/mysql/scripts/mysql_install_db --defaults-file=/etc/my.cnf --user=mysql --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data

/usr/local/mysql/bin/mysql --verbose --help | grep -A 1 'Default options'

mysql 기본환경설정 셋팅(튜닝x)을 진행한다.
vi /etc/my.cnf
-------------추가----------------------------------------
[mysqld]
datadir=/usr/local/mysql/data
socket=/tmp/mysql.sock
user=mysql

[mysqld_safe]
log-error=/usr/local/mysql/data/mysqld.log
pid-file=/usr/local/mysql/data/mysqld.pid
port=3306
-----------------------------------------------------------

실행파일을 심볼릭링크를 걸어줌으로써 간편히 명령어를 사용할수 있다.
ln -s /usr/local/mysql/bin/mysql /usr/sbin/
ln -s /usr/local/mysql/bin/mysqldump /usr/sbin/
ln -s /usr/local/mysql/bin/mysqladmin /usr/sbin/

64bit 환경에서 php 설치시에는 아래와 같이 lib 디렉토리를 lib64디렉토리로 심볼릭링크 해줘야 설치를 진행할수 있을 것이다. 32bit 는 상관없다.
cd /usr/local/mysql/
ln -s lib lib64

아래명령어도 함께 입력한다. mysql 라이브러리를 지정해줘야지, 나중에 php와 연동할때 꼭 필요하다
echo "/usr/local/mysql/lib/" >> /etc/ld.so.conf
ldconfig

mysql 실행한다.
service mysqld start

mysql -uroot -p
패스워드 없이 엔터만 치면 된다.



설치 완료 모습이다.

######### 아래는 5.7.x 이상 버전설치 완료시 #########

/usr/local/mysql/bin/mysql_secure_installation

---------------설정 화면--------------------------------------------------------------------
Securing the MySQL server deployment.

Connecting to MySQL server using password in '/root/.mysql_secret'

VALIDATE PASSWORD PLUGIN can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD plugin?

Press y|Y for Yes, any other key for No: y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary                  file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 0
Using existing password for root.

Estimated strength of the password: 50
Change the password for root ? ((Press y|Y for Yes, any other key for No) : y

New password:

Re-enter new password:

Estimated strength of the password: 25
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
 ... Failed! Error: Your password does not satisfy the current policy requirements

New password:

Re-enter new password:

Estimated strength of the password: 25
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
 ... Failed! Error: Your password does not satisfy the current policy requirements

패스워드 길이가 짧아서 설정이 안되고있는 모습이다. 8글자 이상으로 패스워드를 설정한다.

New password:

Re-enter new password:

Estimated strength of the password: 50
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : n

 ... skipping.


Normally, root should only be allowed to connect from
'localhost'. This ensures that someone cannot guess at
the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : n

 ... skipping.
By default, MySQL comes with a database named 'test' that
anyone can access. This is also intended only for testing,
and should be removed before moving into a production
environment.


Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y
Success.

All done!
-----------------------------설정 완료---------------------------------------------------------



다시 mysql 를 root 권한으로 실행해보자
mysql -uroot -p
Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.7.11

Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql 초기 패스워드를 꼭 변경해줘야된다.

mysql> update user set authentication_string=password('1234') where user='root';
Query OK, 1 row affected, 1 warning (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 1

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

이렇게 mysql 5.7.x 설치 및 실행까지 성공적으로 완료되었다. 
#############################################


- 다음 포스팅에서 계속 -


시골청년
nginx (1.9.5) 설치 및 성능테스트
[Nginx 설치 및 성능테스트]

1.설치환경

CPU : Intel(R) Core(TM)2 Quad CPU    Q6600  @ 2.40GH (가상화 환경)
Ram : 1G
Os : Sulinux 2014 R6 64bit
작성자 : 서비님 (http://dslee1.blogspot.kr/)

2. Nginx 소개

"더 적은 자원으로 더 빠르게 데이터를 서비스 할 수 있다."

nginx 는 차세대 웹서버로 불리고 있으며, 위 그래프에서도 알수 있듯이 꾸준한 상승세를 보이고 있다.  Nginx 는 러시아의 개발자이자 서버관리자인 이고르 시셰프(Igor Sysoev)에 의해 2002년부터 개발되기 시작했다고 하며,  2004년 첫 릴리즈 이래, 2012년 전세계적으로 약 12% 이상의 점유율을 기록하고 있다 한다. 현재 Apache에 있어 가장 위협이 되고 있는 존재로 급부상 중이다.

nginx 는 새로운 시대의 요청에 부응해서 만들어진 웹서버이다. 개발의 모든 목적이 높은 성능에 맞춰져 있다. 그리고 잘 사용하지 않는 기능은 과감하게 제외했다. 덕분에 폭발적인 증가세에 있는 인터넷 서비스를 지탱하는데 적합하다.

3. 설치

DB 를 제외한 기본적입 웹서비스를 할수있는 환경을 구성할 것이다. nginx + php 설치를 목적으로 한다.

3.1 기본페키지 삭제

기존에 yum 으로 설치된 패키지를 삭제하도록 한다. 이곳에서는 nginx + php 만 설치하기 때문에 시스템 자원을 효율적으로 사용하기위해서 불필요한 프로세스는 삭제하도록 한다.

yum -y remove httpd*
yum -y remove mysql*
yum -y remove php*

3.2 기본 라이브러리 설치

nginx 및 php 는 다양한 라이브러리를 이용하여 설치를 진행한다. 처음 os 를 설치하고 난 이후에 기존에 설치된 라이브러리들이 있을수있지만 업데이트 및 빠진 라이브러리들을 설치한다.

yum -y install zlib zlib-devel libxml2 curl libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel freetype-utils fontconfig fontconfig-devel gd gd-devel php-gd libmcrypt libmcrypt-devel gcc g cpp gcc-c compat-gcc-32-g77 flex glibc openssl openssl-devel gmp gmp-devel mhash mhash-devel php-soap libc-client* net-snmp* pcre-devel.x86_64

3.3 php 설치

이제 nginx 의 대표적인 웹언어인 php 를 설치하도록 하겠다. 설치 버전은 5.5.x 버전을 사용하면 된다.

3.3.1 다운로드

공식홈페이지에서 다운로드 하도록 한다.


파일명이 mirror 되어있기 때문에 변경해준다.

mv mirror php-5.5.7.tar.gz

3.3.2 라이브러리 링크

php configration 과정에서 아래와 같은 에러메시지가 확인이 될것이다. 아래와 같이 링크 해준다.
configure: error: libjpeg.(a|so) not found
ln -s /usr/lib64/libjpeg.so /usr/lib/
ln -s /usr/lib64/libpng.so /usr/lib/

3.3.3 mcrypt.h 설치

tar xvfz libmcrypt-2.5.7.tar.gz
cd libmcrypt-2.5.7
./configure && make && make install

3.3.4 환경 설정 및 설치
 tar xvfz php-5.5.7.tar.gz
 cd php-5.5.7
./configure --prefix=/usr/local/php-5.5.7 --with-config-file-path=/usr/local/lib --with-gd --with-freetype-dir --with-zlib --enable-sockets --enable-gd-native-ttf --with-png-dir --with-jpeg-dir --enable-sigchild --with-gettext --enable-mbstring --enable-inline-optimization --enable-bcmath --enable-shmop --enable-calendar --enable-ftp --with-gdbm --with-iconv --enable-mbregex --with-openssl --with-curl --enable-soap --disable-debug --with-mcrypt --with-kerberos --enable-zip --with-zlib-dir --enable-exif --enable-fpm --with-fpm-user=nobody --with-fpm-group=nobody && make && make install

php 디렉토리로 링크 걸어둔다. 이곳은 단순히 사용상의 편의를 위해서 하는것이다.

ln -s /usr/local/php-5.5.7  /usr/local/php

php.ini 환경설정 파일은 설치된 디렉토리에 복사한다.
cp php.ini-production /usr/local/lib/php.ini

php.ini 파일을 열어서 몇가지 설정을 변경해준다.

vi /usr/local/lib/php.ini
* short_open_tag
short_open_tag = On

* error_reporting
error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE & ~E_STRICT

* display_errors
display_errors = On

* date.timezone
date.timezone = "Asia/Seoul"

-- 여기서 부터 php-fpm 설정
일반적으로 nginx는 동적인 페이지 구현이 어렵다. 이부분을 해결하기 위해서 fast-cgi 기능을 사용하는 php-fpm 을 설치해야된다.

cd sapi/fpm
cp -a php-fpm.conf /usr/local/php/etc/php-fpm.conf

* php-fpm (start|stop) 등의 스크립트 지원이 없으므로 직접 작성

— 여기서 부터 php-fpm 실행 스크립트 /etc/rc.d/init.d/php-fpm

vi /etc/rc.d/init.d/php-fpm

#! /bin/sh
### BEGIN INIT INFO
# Provides: php-fpm
# Required-Start: $remote_fs $network
# Required-Stop: $remote_fs $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts php-fpm
# Description: starts the PHP FastCGI Process Manager daemon
### END INIT INFO
prefix=/usr/local/php
exec_prefix=${prefix}
php_fpm_BIN=${exec_prefix}/sbin/php-fpm
php_fpm_CONF=${prefix}/etc/php-fpm.conf
php_fpm_PID=${prefix}/var/run/php-fpm.pid
php_opts="--fpm-config $php_fpm_CONF --pid $php_fpm_PID"
wait_for_pid () {
try=0
while test $try -lt 35 ; do
case "$1" in
"created")
if [ -f "$2" ] ; then
try=""
break
fi
;;
"removed")
if [ ! -f "$2" ] ; then
try=""
break
fi
;;
esac
echo -n .
try=`expr $try 1`
sleep 1
done
}
case "$1" in
start)
echo -n "Starting php-fpm "
#$php_fpm_BIN --daemonize $php_opts
$php_fpm_BIN $php_opts
if [ "$?" != 0 ] ; then
echo " failed"
exit 1
fi
wait_for_pid created $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
stop)
echo -n "Gracefully shutting down php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -QUIT `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed. Use force-quit"
exit 1
else
echo " done"
fi
;;
force-quit)
echo -n "Terminating php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -TERM `cat $php_fpm_PID`
wait_for_pid removed $php_fpm_PID
if [ -n "$try" ] ; then
echo " failed"
exit 1
else
echo " done"
fi
;;
restart)
$0 stop
$0 start
;;
reload)
echo -n "Reload service php-fpm "
if [ ! -r $php_fpm_PID ] ; then
echo "warning, no pid file found - php-fpm is not running ?"
exit 1
fi
kill -USR2 `cat $php_fpm_PID`
echo " done"
;;
*)
echo "Usage: $0 {start|stop|force-quit|restart|reload}"
exit 1
;;
esac

저장 후
chmod 755 /etc/rc.d/init.d/php-fpm

3.4 Nginx 설치

3.4.1 다운로드
공식홈페이지에서 가장 최신버전을 받는것을 추천한다.

tar xvfz nginx-1.9.5.tar.gz
cd nginx-1.9.5
./configure --prefix=/usr/local/nginx-1.9.5 --user=nobody --group=nobody --with-http_ssl_module --with-http_dav_module --with-http_gzip_static_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module && make && make install

관리를 편하기 하기위해서 링크를 걸어주도록 한다.

ln -s /usr/local/nginx-1.9.5 /usr/local/nginx

3.4.2 환경설정

vi /usr/local/nginx/conf/nginx.conf

-- 여기서 부터 nginx.conf 여기부터
#user nobody;
# worker_processes 1;  본인의 시스템 환경에 맞게 설정해주면 된다.
worker_processes "4";     
error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
pid logs/nginx.pid;
events {
worker_connections 10240;
}
http {
index index.html index.php;
include mime.types;
default_type application/octet-stream;
log_format main "$remote_addr - $remote_user [$time_local] "$request" "
"$status $body_bytes_sent "$http_referer" "
""$http_user_agent" "$http_x_forwarded_for"";
access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
gzip on;
gzip_disable "MSIE [1-6]\.(?!.*SV1)";
gzip_http_version 1.0;
gzip_comp_level 9;
gzip_proxied any;
gzip_types text/plain text/css application/x-javascript text/xml application/xml rss text/javascript;
server {
listen 80;
client_max_body_size 50M;
client_body_timeout 600;
client_header_timeout 600;
server_name 192.168.0.71
root html;
index index.html index.php;
location ~ \.(php|html)$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
# another virtual host using mix of IP-, name-, and port-based configuration
#
#server {
# listen 8000;
# listen somename:8080;
# server_name somename alias another.alias;
# location / {
# root html;
# index index.html index.htm;
# }
#}
# HTTPS server
#
#server {
# listen 443;
# server_name localhost;
# ssl on;
# ssl_certificate cert.pem;
# ssl_certificate_key cert.key;
# ssl_session_timeout 5m;
# ssl_protocols SSLv2 SSLv3 TLSv1;
# ssl_ciphers HIGH:!aNULL:!MD5;
# ssl_prefer_server_ciphers on;
# location / {
# root html;
# index index.html index.htm;
# }
#}
}

3.4.3 실행 스크립트

nginx는 자동으로 스크립트가 생성되어있지 않다. 이 때문에 공식홈페이지 문서에 있는 스크립트를 참조하면 된다.

* 여기서 부터 ngnix 실행 스크립트 vi /etc/rc.d/init.d/ngnix

vi /etc/rc.d/init.d/ngnix
#!/bin/sh
#
# nginx - this script starts and stops the nginx daemin
#
# 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
# 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"
lockfile=/var/lock/subsys/nginx
start() {
[ -x $nginx ] || exit 5
[ -f $NGINX_CONF_FILE ] || exit 6
echo -n $"Starting $prog: "
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
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
저장 후
chmod 777 /etc/rc.d/init.d/ngnix

4. 성능테스트

지금까지 nginx를 설치를 완료하였다. 여기에서는 설치된 nginx가 과연 어느정도의 성능을 보여주는지 테스트 해보도록 하겠다. 물론 리얼서버만큼의 만족도와 신뢰성을 얻기는 힘들겠지만, 대략적인 성능체감을 할수있을것 같다.

단독으로 테스트를 하기 보다는 현재 전세계적으로 많이 사용하는 apache 와 함께 비교를 해보도록 하겠다.

4.1 설치환경 비교
아래는 nginx 및 apache 설치환경 비교 내용이다.

[nginx]
버전 : 1.9.5 (현재가장 최신버전 2015.10.21)
MPM : event
cpu : Intel(R) Core(TM)2 Quad CPU    Q6600  @ 2.40GHz (가상화 pc)
ram : 1G
os : sulinux 2014 R6 (최신커널업데이트)

설치 직후 튜닝은 거의 진행되지 않음.

[apache]
버전 : 2.4.17 (현재가장 최신버전 2015.10.21)
MPM : worker 및 event
cpu : Intel(R) Core(TM)2 Quad CPU    Q6600  @ 2.40GHz (가상화 pc)
ram : 1G
os : sulinux 2014 R6 (최신커널업데이트)

<worker 튜닝>
<IfModule mpm_worker_module>
   StartServers          5
   MinSpareThreads       100
   MaxSpareThreads       500
   ThreadsPerChild         25
   MaxRequestWorkers      1024
   MaxConnectionsPerChild   0
</IfModule>

<event 튜닝>
<IfModule mpm_event_module>
          ThreadLimit          100
  StartServers         5
  MaxRequestWorkers    5500
  ServerLimit          200
  MinSpareThreads      100
  MaxSpareThreads      1000
  ThreadsPerChild      100
  MaxRequestsPerChild  0
</IfModule>

4.2 테스트 프로그램

vi test2.php

<?
 $str=array();
 for($i=1;$i<=100;$i++){
    $str2+=$i%3;
    $str[$i]=$str2;
  }
  echo "ok";
?>

4.3 성능 테스트
테스트용 성능툴은 apache 에 기본적으로 제공되는 ab 를 이용하도록 한다.

각각 2번씩 총 6번의 테스트를 진행하였다.

ab -n 10000 -c 100 http://192.168.0.71/test2.php
100개의 쓰레드를 이용하여 10.000 호출.

ab -n 100000 -c 100 http://192.168.0.71/test2.php
100개의 쓰레드를 이용하여 100.000 호출

4.4 결과

total 시간.

Nginx 1.9.5
Apache worker
Apache event
10.000 호출
12.313 seconds
16.037 seconds
13.386 seconds
100.00 호출
135.425 seconds
158.746 seconds
145.933 seconds
서버 부하(10.000일때)
load average: 0.59
load average: 19.77
load average: 1.48
서버 부하(100.000일때)
load average: 1.86
load average: 121.44
load average: 7.06

단순테스트 진행이었지만 생각보다 nginx의 성능이 apache 보다 우수하다는걸 알수 있었다.
확실히 쓰레드방식을 사용하는 apache의 worker 방식은 시스템 부하 및 처리시간이 가장 많이 나타나게 되었다. 반면에 이벤트 방식을 사용하는 apache 및 nginx 는 처리시간도 짧고, 시스템 부하 면에서 우수한 성능을 보여주는걸 확인하였다. 이 테스트를 평균 10번 정도 테스트 하였으며, 해당 평균을 계산한 것이다.

접속자가 많으며, cpu 를 많이 사용하는 시스템에서는  apache event 방식이나 또는 nginx 를 사용하면 높은 퍼포먼스를 보여주지 않을까 생각 된다.


시골청년 2016년 3월 16일 수요일