[CentOS]sudoers를 이용하여 root 로그인 없이 아파치 실행하기

Published on: 2013. 11. 14. 16:33 by louis.dev
apachectl을 통해서 apache 프로세스를 올릴때는 root권한이 필요하다. 그런데 매번 서버를 재시작할때 root로그인하는것도 너무 귀찮고, 리눅스를 사용하는 일반 유저들(시스템 엔지니어가 아닌 일반 개발자)에게 root 비밀번호를 공유하는것도 보안에 너무 취약한 방법이다. 그리고 웹서비스를 서비스할때 쉽게 배포하기위해서 쉘스크립트를 만들어서 배포하게 되는데, 이때 아파치 서버를 재시작해야 하는 부분이 스크립트에 추가 되게 된다면 스크립트 실행시에 root권한을 획득하기 위해 매번 root비밀번호를 물어보게 된다. 너무 귀찮다. 그럴때 사용하는 방법이 sudoers 설정을 하는것이다. 이것은 일반유저에게 특정한 명령어를 root권한으로 로그인없이 실행할수 있도록 도와준다. 즉 sudoer를 이용하면 apachectl명령어를 root권한없이 수행할 수 있게 된다. 이렇게 되면 위에서 나열한 웹서버 운영중 불편한점을 많이 개선할수 있게 된다. 설정은 매우 간단하다. 1) root로그인후 /etc/sudoers 파일을 연다. 2) 적당한 곳에 다음과 같이 입력한다.
Cmnd_Alias APACHE = ${아파치 설치경로}/bin/apachectl
${루트권한을 획등할 사용자아이디} ALL=(ALL) NOPASSWD: APACHE
설정은 이로서 끝이다. 사실 별거 없다.. 이렇게 설정하고 사용할때는
$ sudo apachectl restart
로 사용하면 root 비밀번호를 묻지않고 apachectl명령이 수행된다.

[CentOS 5] Apache 2.4.2 컴파일 설치방법

Published on: 2013. 11. 14. 13:11 by louis.dev
아파치 서버를 설치하기 전 먼저 아파치를 컴파일 하여 설치하기 위한 라이브러리를 먼저 설치해 줘야 합니다. 1. gcc 컴파일러, pcre 설치
# yum install gcc
# yum install pcre-devel
2. APR, APR-Util 설치 위와같이 yum을 통해 간단하게 APR을 설치할 수 있지만 yum으로 설치되는 APR의 버전이 너무 낮아 Apache 2.4를 설치할때 에러를 내면서 설치가 되지 않는다. 그러므로 홈페이지에서 최신버전을 다운로드 받아 컴파일 설치하는 방식으로 진행 해야 합니다.
## APR설치
## APR의 경로를 설정하지 않으면 기본적으로 /usr/local/apr 에 설치됩니다.
$ wget http://mirror.apache-kr.org//apr/apr-1.4.6.tar.gz
$ gzip -d apr-1.4.6.tar.gz
$ tar xvf apr-1.4.6.tar.gz
$ cd apr-1.4.6
$ su
# ./configure; make && make install
## APR-Util
$ wget http://apache.mirror.cdnetworks.com//apr/apr-util-1.4.1.tar.gz
$ gzip -d apr-util-1.4.1.tar.gz
$ tar xvf apr-util-1.4.1.tar
$ cd apr-util-1.4.1
$ su
## configure 옵션중 with-apr 로 위에서 설치한 apr의 경로를 지정해 줍니다.
# ./configure --with-apr=/usr/local/apr ;make && make install
설치시 유의사항이 있다면 반드시 APR먼저 설치한 뒤 APR-util을 설치해야 합니다. 3. Apache 2.4.2 설치
$ mkdir ${사용자 디렉토리}/httpd-2.4.2
$ wget http://apache.mirror.cdnetworks.com//httpd/httpd-2.4.2.tar.gz
$ tar xvfz httpd-2.4.2.tar
$ cd httpd-2.4.2
$ su
## with-apr 설치 옵션으로 위에서 설치한 apr의 설치 경로를 입력합니다.
# ./configure --prefix=${아파치 설치 경로} --with-apr=/usr/local/apr ; make && make install
설치 중 다음과 같은 에러가 발생할 수 있습니다.
exports.c:2858: error: redefinition of 'ap_hack_apr_xlate_conv_byte'
exports.c:1813: error: previous definition of 'ap_hack_apr_xlate_conv_byte' was here
exports.c:2859: error: redefinition of 'ap_hack_apr_xlate_close'
exports.c:1814: error: previous definition of 'ap_hack_apr_xlate_close' was here
exports.c:2864: error: redefinition of 'ap_hack_apr_text_append'
exports.c:1819: error: previous definition of 'ap_hack_apr_text_append' was here
exports.c:2865: error: redefinition of 'ap_hack_apr_xml_parser_create'
exports.c:1820: error: previous definition of 'ap_hack_apr_xml_parser_create' was here
exports.c:2866: error: redefinition of 'ap_hack_apr_xml_parse_file'
exports.c:1821: error: previous definition of 'ap_hack_apr_xml_parse_file' was here
exports.c:2867: error: redefinition of 'ap_hack_apr_xml_parser_feed'
exports.c:1822: error: previous definition of 'ap_hack_apr_xml_parser_feed' was here
exports.c:2868: error: redefinition of 'ap_hack_apr_xml_parser_done'
exports.c:1823: error: previous definition of 'ap_hack_apr_xml_parser_done' was here
exports.c:2869: error: redefinition of 'ap_hack_apr_xml_parser_geterror'
exports.c:1824: error: previous definition of 'ap_hack_apr_xml_parser_geterror' was here
exports.c:2870: error: redefinition of 'ap_hack_apr_xml_to_text'
exports.c:1825: error: previous definition of 'ap_hack_apr_xml_to_text' was here
exports.c:2871: error: redefinition of 'ap_hack_apr_xml_empty_elem'
exports.c:1826: error: previous definition of 'ap_hack_apr_xml_empty_elem' was here
exports.c:2872: error: redefinition of 'ap_hack_apr_xml_quote_string'
exports.c:1827: error: previous definition of 'ap_hack_apr_xml_quote_string' was here
exports.c:2873: error: redefinition of 'ap_hack_apr_xml_quote_elem'
exports.c:1828: error: previous definition of 'ap_hack_apr_xml_quote_elem' was here
exports.c:2874: error: redefinition of 'ap_hack_apr_xml_insert_uri'
exports.c:1829: error: previous definition of 'ap_hack_apr_xml_insert_uri' was here
exports.c:2883: error: redefinition of 'ap_hack_apu_version'
exports.c:1838: error: previous definition of 'ap_hack_apu_version' was here
exports.c:2884: error: redefinition of 'ap_hack_apu_version_string'
exports.c:1839: error: previous definition of 'ap_hack_apu_version_string' was here
make[2]: *** [exports.lo] 오류 1
make[2]: Leaving directory `/home/${사용자}/httpd-2.4.2/server'
make[1]: *** [all-recursive] 오류 1
make[1]: Leaving directory `/home/${사용자}/httpd-2.4.2/server'
make: *** [all-recursive] 오류 1
이 에러는 yum으로 낮은 버전의 APR을 설치한 후 다시 컴파일 설치로 최신버전의 APR이 설치되었을때 발생하는 문제로 낮은 버전의 APM을 지우면 됩니다.
#yum remove APR

[CentOS 5] MySQL 5.5.25 컴파일 설치하기

Published on: 2013. 11. 14. 13:09 by louis.dev
리눅스 서버에 MySQL을 설치하는 방식은 세가지 정도입니다.
  1. yum을 통한 간단한 설치
  2. rpm 패키지를 통한 설치
  3. 컴파일 설치
이 중 컴파일 설치로 진행해 보도록 하겠습니다. 1. CMAKE 설치 MySQL 5.5.x 버전 부터는 make가 아닌 cmake를 통해 컴파일 설치를 해야 합니다. 그렇기 때문에 먼저 cmake를 설치해야 합니다.
## cmake 설치에 필요한 라이브러리 설치
# yum -y install zlib curl
# yum -y install gcc g++ cpp gcc-c++
# yum -y install openssl openssl-devel
# yum -y install libtermcap-devel ncurses-devel libc-client-devel bzip2-devel
# yum -y install bison

## cmake 설치
# wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz
# tar xvfzp cmake-2.8.4.tar.gz
# cd cmake-2.8.4
# ./bootstrap
# make all
# make install
2. MySQL 설치에 필요한 라이브러리 설치
$ wget http://dev.mysql.com/get/Downloads/MySQL-5.5/MySQL-devel-5.5.25-1.rhel5.x86_64.rpm/from/http://ftp.jaist.ac.jp/pub/mysql/
$ su
# rpm -Uvh --force --nodeps MySQL-devel-5.5.25-1.rhel5.x86_64.rpm
3. MySQL 5.5.25 다운로드 후 설치
$ http://dev.mysql.com/get/Downloads/MySQL-5.5/mysql-5.5.25.tar.gz/from/http://ftp.iij.ad.jp/pub/db/mysql/
$ tar xvfz mysql-5.5.13.tar.gz
$ cd /mysql-5.5.13
$ su
# cmake -DCMAKE_INSTALL_PREFIX=${MySQL이 설치될 경로} 
-DWITH_EXTRA_CHARSETS=all 
-DMYSQL_DATADIR=/data -DENABLED_LOCAL_INFILE=1 
-DWITH_INNOBASE_STORAGE_ENGINE=1 
-DMYSQL_UNIX_ADDR=${MySQL이 설치될 경로}/mysql.sock 
-DMYSQL_DATADIR=${MySQL이 설치될 경로}/data 
-DDEFAULT_CHARSET=utf8 
-DDEFAULT_COLLATION=utf8_general_ci 
-DWITH_EXTRA_CHARSETS=all 
-DMYSQL_TCP_PORT=3306
4. 권한 설정 및 세팅
# groupadd mysql
# useradd -g mysql mysql
# chown -R mysql:mysql ${mysql 설지 경로}

# cd ${mysql 설지 경로}
#  ./scripts/mysql_install_db --user=mysql --datadir=${mysql 설치 경로}/data
# cp support-files/my-medium.cnf /etc/my.cnf
# cp support-files/mysql.server /etc/init.d/mysqld

## mysqld 파일의 datadir부분을 아래와 같이 수정한다.
# vi /etc/init.d/mysqld   

datadir=${mysql 설치 경로}/data
그리고 서비스를 실행시키면 됩니다.
# /sbin/service mysqld start
이후 작업사항은 아래 블로그에서 확인하세요

[Linux] PHP 설치하기

Published on: 2013. 11. 14. 13:08 by louis.dev
아파치 서버에 간단한 설정으로 PHP 구동을 확인할 수 있습니다.
$ wget http://kr2.php.net/get/php-5.4.3.tar.gz/from/kr.php.net/mirror
$ tar xvfz php-5.4.3.tar.gz
$ cd php-5.4.3

$ su
# ./configure 
--with-apxs2=${아파치 서버가 설치된 경로}/bin/apxs 
--with-mysql=${mysql이 설치된 경로} 
--with-config-file-path=${아파치 서버가 설치된 경로}/conf 
--with-exec-dir=${아파치 서버가 설치된 경로}/bin 
--enable-track-vars 
--enable-trans-sid 
--with-zlib

#make && make install
# cp php.ini-production ${아파치 서버가 설치된 경로}/conf/php.ini
php를 설치후에 아파치 설정파일에 php 설정을 추가해 줍니다.
$ vi ${아파치 서버가 설치된 경로}/conf/httpd.conf
아래 내용을 추가해 줍니다.
<IfModule mime_module>
	AddType application/x-httpd-php .php .phtm
</IfModule mime_module>

Linux ( CentOS 5 ) - Apache + SVN(Subvertion) 설치하기

Published on: 2011. 5. 20. 23:13 by louis.dev

자주 서버세팅을 하게 되는데 매일 찾아보는것도 그렇고 해서 기록으로 남깁니다.
yum을 통해 간단히 설치하고 설정해 보겠습니다.

따라 하시는 분들은 코드의 하이라이트된 부분만 입력하셔서 따라하시면 됩니다.

1. 아파치 설치하기

[root@localhost stylejg]# yum install httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.daum.net
 * extras: ftp.daum.net
 * updates: ftp.daum.net
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.2.3-45.el5.centos.1 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================================================================================================
 Package                                             Arch                                                 Version                                                                Repository                                             Size
=============================================================================================================================================================================================================================================
Updating:
 httpd                                               x86_64                                               2.2.3-45.el5.centos.1                                                  updates                                               1.2 M

Transaction Summary
=============================================================================================================================================================================================================================================
Install       0 Package(s)
Upgrade       1 Package(s)

Total size: 1.2 M
Is this ok [y/N]: y
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating       : httpd                                                                                                                                                                                                                 1/2
  Cleanup        : httpd                                                                                                                                                                                                                 2/2

Updated:
  httpd.x86_64 0:2.2.3-45.el5.centos.1

Complete!
간단하게 아파치 설정을 끝냈습니다.

 2. SVN(subversion) 설치
 
 

[root@localhost stylejg]# yum install -y subversion
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.daum.net
 * extras: ftp.daum.net
 * updates: ftp.daum.net
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package subversion.i386 0:1.6.11-7.el5_6.3 set to be updated
---> Package subversion.x86_64 0:1.6.11-7.el5_6.3 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================================================================================================
 Package                                                  Arch                                                 Version                                                           Repository                                             Size
=============================================================================================================================================================================================================================================
Updating:
 subversion                                               i386                                                 1.6.11-7.el5_6.3                                                  updates                                               3.1 M
 subversion                                               x86_64                                               1.6.11-7.el5_6.3                                                  updates                                               3.2 M

Transaction Summary
=============================================================================================================================================================================================================================================
Install       0 Package(s)
Upgrade       2 Package(s)

Total size: 6.4 M
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Updating       : subversion                                                                                                                                                                                                            1/4
  Updating       : subversion                                                                                                                                                                                                            2/4
  Cleanup        : subversion                                                                                                                                                                                                            3/4
  Cleanup        : subversion                                                                                                                                                                                                            4/4

Updated:
  subversion.i386 0:1.6.11-7.el5_6.3                                                                                   subversion.x86_64 0:1.6.11-7.el5_6.3

Complete!

3. SVN repository생성하기
소스코드의 버전을 관리할 SVN Repository를 생성합니다.


#루트에 "data" directory 생성
[root@localhost /]# mkdir /data
# "data" 디렉토리 안에 "svn"디렉토리 생성. "svn"이란 디렉토리가 svn root 디렉토리임. svn 디렉토리 아래에 프로젝트 별로 repository가 생성 됨
[root@localhost /]# mkdir /data/svn
[root@localhost /]# cd /data/svn/
# apache가 해당 디렉토리(svn 디렉토리)에 접근해야 함으로 디렉토리 소유자를 아파치로 변경
# cent OS의 경우 yum으로 아파치를 설치하면 apache:apache로 우분투에서는 www-data:www-data로 변경
[root@localhost /]#chown -R apache:apache svn
#svn Repository를 생성한다. svnadmin create [저장타입(현재는 파일시스템)] [RepositoryName] #저장타입은 파일시스템 타입과 버클리db타입이 있는데, 버클리db는 버그가 있기 때문에 파일 시스템으로 주로 선언합니다. #버클리db로 설정하려면 svnadmin create --fs-type bcb [RepositoryName] 으로 하면 됩니다. [root@localhost svn]# svnadmin create --fs-type fsfs svn_test #svn_test repository가 생성된걸 볼수 있다. [root@localhost svn]# ls -al 합계 8 drwxr-xr-x 6 root root 4096 5월 20 08:11 svn_test
3. 아파치와 SVN을 연동하기 위한 apache module 설치
[root@localhost svn]# yum install -y mod_dav_svn
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: ftp.daum.net
 * extras: ftp.daum.net
 * updates: ftp.daum.net
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package mod_dav_svn.x86_64 0:1.6.11-7.el5_6.3 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================================================================================================================================
 Package                                                   Arch                                                 Version                                                          Repository                                             Size
=============================================================================================================================================================================================================================================
Installing:
 mod_dav_svn                                               x86_64                                               1.6.11-7.el5_6.3                                                 updates                                                79 k

Transaction Summary
=============================================================================================================================================================================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 79 k
Downloading Packages:
mod_dav_svn-1.6.11-7.el5_6.3.x86_64.rpm                                                                                                                                                                               |  79 kB     00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : mod_dav_svn                                                                                                                                                                                                           1/1

Installed:
  mod_dav_svn.x86_64 0:1.6.11-7.el5_6.3

Complete!


4. 접근할 수 있는 사용자와 비밀번호 추가

#htpasswd [옵션 : -c 파일생성, 맨 처음 파일 생성 할때만 옵션 줌,] [접근권한을 저장한 파일위치 AND 파일이름(파일이름은 사용자 마음데로)] [사용자아이디]
#즉 처음엔 -c 옵션을 붙이고, 두번째 사용자 추가 부터는 htpasswd /data/svn/svn_test/.passwd 사용자아이디 
#형식으로 추가 하면 됨
[root@localhost svn]# htpasswd -c /data/svn/svn_test/.passwd stylejg
New password:
Re-type new password:
Adding password for user stylejg

5. 아파치 설정

아파치를 yum 으로 설치하게 되면 /etc/httpd에 설정파일이 생기게 됩니다. 이쪽에 있는 아파치 설정파일에 svn 설정을 해주시면 됩니다.


[root@localhost httpd]# cd /etc/httpd/conf.d
[root@localhost conf.d]# ls -al
합계 32
-rw-r--r-- 1 root root  392  5월  4 03:54 README
-rw-r--r-- 1 root root  566  5월  4 03:54 proxy_ajp.conf
-rw-r--r-- 1 root root 1181  4월 14 04:49 subversion.conf
-rw-r--r-- 1 root root  299  5월  4 03:54 welcome.conf
#subversion.conf 파일에 svn 설정을 넣어줍니다.
#subversion.conf 파일에 주석처리 되어있는 설정이 있는데 예제임으로 지우시던지, 아니면 그냥 주석이 남겨진 채로 두시던지 하시면 됩니다.
[root@localhost conf.d]# vi subversion.conf

LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module   modules/mod_authz_svn.so

#Location 태그 뒤의 path는 물리적인 위치, 즉 svn파일이 저장되어있는 위치가 아니라
#SVN URL을 나태냅니다. 즉 아래와 같이 /svn/test라 하면 http://userdomain.com/svn/test 가 되는 것입니다.
#그러므로 Location 의 값은 실제 경로와 맞지 않고, 원하시는데로 작성하시면 됩니다.
<Location /svn/test>
  DAV svn
  #실제 svn repository의 저장위치를 설정합니다. 
  #여기는 위와는 다르게 실제 물리적인 path를 설정해 주셔야 합니다.
  SVNPath /data/svn/svn_test
  AuthType Basic
  AuthName "Subversion Repository C2"
  #3번째 단계에서 만들었던 비밀번호가 저장된 파일 위치를 적어줍니다.
  AuthUserFile /data/svn/svn_test/.passwd
  #위에서 설정한 파일에 있는 사용자만 다운로드 & 커밋을 할수 있게 해줍니다.
  Require valid-user
</Location>