CentOS 5.x APM(UTF-8) 셋업 (Apache-2.2.3-6 / PHP 5.1.6-12 / MySQL 5.0.22-2.1)

    [원문 출처] http://www.starhost.co.kr/xe/blog/textyle/145637

    CentOS 5.x APM(UTF-8) 셋업 (Apache-2.2.3-6 / PHP 5.1.6-12 / MySQL 5.0.22-2.1)

    시간 맞추기.

    rdate -s time.bora.net

    Selinux 삭제

    yum remove selinux*

    1. 방화벽 설정

    lokkit

    1. Apache 2.x 설치

    yum install httpd

    1. mysql 설치

    yum install mysql

    yum install mysql-server

    1. php 설치

    yum install php

    yum -y install zlib zlib-devel freetype freetype-devel freetype-utils gd gd-devel libjpeg libjpeg-devel libpng libpng-devel php-gd

    1. php-mysql 연동 설치

    yum install php-mysql

    1. Yum 업데이트

    yum -y update

    1. CentOS 서버 Euc-KR 설정 및 APM 설정 파일 UTF-8 설정

    vi /etc/sysconfig/i18n

    LANG="ko_KR.EUC-KR"
    SUPPORTED="ko_KR.EUC-KR:ko_KR:ko"
    SYSFONT="latarcyrheb-sun16"

    vi /etc/httpd/conf/httpd.conf 에서 캐릭터셋 수정

    AddDefaultCharset UTF-8

    vi /etc/php.ini

    ;default_charset = "iso-8859-1"
    default_charset = "utf-8"

    vi /etc/my.cnf

    [mysqld]
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock

    Default to using old password format for compatibility with mysql 3.x

    clients (those using the mysqlclient10 compatibility package).

    old_passwords=1

    [mysql.server]
    user=mysql
    basedir=/var/lib

    [mysqld_safe]
    err-log=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid

    [client]
    default-character-set = utf8

    [mysqld]
    init_connect = 'set names utf8'

    old_passwords=1

    Charset 설정

    character-set-server = utf8
    default-collation = utf8_general_ci

    service httpd restart

    service mysqld restart

    mysql> use mysql;

    mysql> update user set password = password('루트패스워드') where user = 'root';
    Query OK, 1 row affected (0.00 sec)
    
    mysql> flush privileges;
    Query OK, 0 rows affected (0.00 sec)
    mysql> quit

    mysql -uroot -p

    mysql> use test;
    Database changed
    mysql> show variables like 'c%';
    +--------------------------+----------------------------+
    | Variable_name | Value |
    +--------------------------+----------------------------+
    | character_set_client | utf8 |
    | character_set_connection | utf8 |
    | character_set_database | utf8 |
    | character_set_filesystem | binary |
    | character_set_results | utf8 |
    | character_set_server | utf8 |
    | character_set_system | utf8 |
    | character_sets_dir | /usr/share/mysql/charsets/ |
    | collation_connection | utf8_general_ci |
    | collation_database | utf8_general_ci |
    | collation_server | utf8_general_ci |
    | completion_type | 0 |
    | concurrent_insert | 1 |
    | connect_timeout | 5 |
    +--------------------------+----------------------------+
    14 rows in set (0.00 sec)

    vi /etc/sysconfig/i18n

    한글 셋팅

    LANG="ko_KR.eucKR"
    SUPPORTED="ko_KR.eucKR:ko_KR:ko:en_US:en"
    SYSFONT="lat0-sun16"
    SYSFONTACM="iso01"

    UTF-8 셋팅

    LANG="ko_KR.UTF-8"
    SUPPORTED="ko_KR.UTF-8:ko_KR:ko:en_US:en"
    SYSFONT="lat0-sun16"
    SYSFONTACM="iso01"

    ###########ZeroBoard 5 설치 하기###############

    mysql -uroot -p

    create database kalrielradb default character set utf8 collate utf8_general_ci;
    use mysql
    insert into db values('%','kalrielradb','kalrielra','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y','y');
    insert into user (host,user,password) values ('localhost','kalrielra',password('패스워드'));
    flush privileges;

    ########### VsFTP 설정 #########

    vi /etc/vsftpd/vsftpd.conf

    anonymous_enable=NO

    PAM 파일명을 지정 (설치할 때 /etc/pam.d/vsftpd명으로 복사함)

    pam_service_name=vsftpd

    wtmp에 로그 남기기 (YES로 해야만 last 명령어로 접속 여부 확인 가능)

    session_support=YES

    사용자가 자신의 home directory를 벗어나지 못하도록 설정

    chroot_local_user=YES

    전송속도 제한 (0은 제한없음, 단위는 초당 bytes)

    anon_max_rate=0
    local_max_rate=0
    trans_chunk_size=0

    service vsftpd restart

    *** SELINUX

    설치할때 SELinux 로 설정했다면 디폴트로 사용자의 home 디렉토리에 쓰기를 막아놓는다.
    SELinux 설정에서 FTP 부분을 변경하자.

    setsebool -P ftp_home_dir 1

    SELinux 비활성화 하기
    #vi /etc/selinx/config
    SELINUX=disabled

    ############ Oops-Firewall SRPM 설치 ########

    yum install -y rpm-build rpm-devel

    yum install -y gcc

    yum install -y bridge-utils.i386 bridge-utils-devel.i386

    rpm -Uvh oops-firewall-6.2.1-1.src.rpm

    cd /usr/src/redhat/SPECS

    vi oops-firewall.spec

    Copyright -> License 로 변경

    rpmbuild -ba /usr/src/redhat/SPECS/oops-firewall.spec

    cd /usr/src/redhat/RPMS/noarch

    rpm -Uvh oops-firewall-*

    service oops-firewall start

    rm -rf /usr/src/redhat/SOURCES/oops-firewall-6.2.1.tar.bz2

    rm -rf /usr/src/redhat/SPECS/oops-firewall.spec

    rm -rf /usr/src/redhat/SRPMS/oops-firewall-6.2.1-1.src.rpm

    ############ 필요없는 설정툴 없애기 #########

    yum list installed system-config*

    yum remove system-config*

    ############ Apache DOS 모듈 설치 하기 위한 apxs 설치하기 ###

    yum -y install httpd-devel.i386

    ############ Apache 2.x 에서 트래픽 제한을 위한 CBand 설치하기 ###

    tar xvzpf mod-cband-0.9.7.5.tgz

    cd mod-cband-0.9.7.5

    ./configure

    make

    make install

    vi /etc/httpd/conf/httpd.conf

    LoadModule cband_module modules/mod_cband.so

    vi /etc/httpd/conf.d/cband.conf

    SetHandler cband-status SetHandler cband-status-me SetHandler cband-status-me Order deny,allow Deny from all Allow from all

    vi /etc/httpd/conf.d/cband_user.conf

    CBandUserLimit 1Gi CBandUserPeriod 1D

    vi /etc/httpd/conf.d/virtualhost.conf

    DocumentRoot /home/user/public_html Servername Domain ServerAlias www.Domain CBandLimit 300Mi CBandPeriod 1D

    확인하는 방법 : http://Domain/cband-status
    확인하는 방법 : http://Domain/cband-status-me

    ########## Cband 관리자 모드 인증 하기 #######

    htpasswd -c /var/www/html/.htpasswd kalrielra

    vi /var/www/html/.htpaccess

    AuthUserFile /var/www/html/.htpasswd
    AuthName "Cband Administrator"
    AuthType Basic

    require valid-user

    vi /etc/httpd/conf.d/cband.conf

    SetHandler cband-status AuthName "Cband Administrator" AuthType Basic AuthUserFile /var/www/html/.htpasswd require valid-user SetHandler cband-status-me SetHandler cband-status-me Order deny,allow Deny from all Allow from all

    vi /etc/httpd/conf.d/cband_user.conf

    CBandUserLimit 1Gi CBandUserPeriod 1D

    vi /etc/httpd/conf.d/virtualhost.conf

    DocumentRoot /home/user/public_html Servername Domain ServerAlias www.Domain CBandLimit 300Mi CBandPeriod 1D

    vi /etc/httpd/conf/httpd.conf

    아래처럼 설정 한다.

    AllowOverride controls what directives may be placed in .htaccess files.

    It can be "All", "None", or any combination of the keywords:

    Options FileInfo AuthConfig Limit

    #
    AllowOverride None <------ All 일때에는 해당 디렉토리에 패스워드를 걸어준다.

    service httpd restart

    http://127.0.0.1/cband-status

    Modsecurity 1.9.5 설치

    modsecurity-apache_2.1.1 은 Apache 2.x 버전에서만 설치된다.

    tar xvzpf modsecurity-apache_1.9.5.tar.gz

    cd modsecurity-apache_1.9.5

    apxs -cia modsecurity-apache_1.9.5/apache1/mod_security.c

    vi /etc/httpd/conf/httpd.conf

    LoadModule security_module modules/mod_security.so

    vi /etc/httpd/conf.d/security.conf

    # Enable ModSecurity
    SecFilterEngine On
    
    # Reject requests with status 403
    SecFilterDefaultAction "deny,log,status:403"
    
    # Some sane defaults
    SecFilterScanPOST On
    SecFilterCheckURLEncoding On
    SecFilterCheckUnicodeEncoding Off
    
    # Accept almost all byte values
    SecFilterForceByteRange 1 255
    
    # Server masking is optional
    # SecServerSignature "Microsoft-IIS/5.0"
    
    # Designate a directory for temporary files
    # storage. It is a good idea to change the
    # value below to a private directory, just as
    # an additional measure against race conditions
    SecUploadDir /tmp
    SecUploadKeepFiles Off
    
    # Only record the interesting stuff
    SecAuditEngine RelevantOnly
    # Uncomment below to record responses with unusual statuses
    # SecAuditLogRelevantStatus ^5
    SecAuditLog logs/modsec_audit.log
    
    # You normally won't need debug logging
    SecFilterDebugLevel 0
    SecFilterDebugLog logs/modsec_debug.log
    
    # Only accept request encodings we know how to handle
    # we exclude GET requests from this because some (automated)
    # clients supply "text/html" as Content-Type
    SecFilterSelective REQUEST_METHOD "!^(GET|HEAD)$" chain
    SecFilterSelective HTTP_Content-Type "!(^application/x-www-form-urlencoded$|^multipart/form-data;)"
    
    # Do not accept GET or HEAD requests with bodies
    SecFilterSelective REQUEST_METHOD "^(GET|HEAD)$" chain
    SecFilterSelective HTTP_Content-Length "!^$"
    
    # Require Content-Length to be provided with
    # every POST request
    SecFilterSelective REQUEST_METHOD "^POST$" chain
    SecFilterSelective HTTP_Content-Length "^$"
    
    # Don't accept transfer encodings we know we don't handle
    SecFilterSelective HTTP_Transfer-Encoding "!^$"
    
    #¸만약 요청중 ‘../’ 이 포함돼 있다면 이는 상위 디렉토리에 접근하기 위한 시도임을 알 수 있는데, 
    # 정상적인 웹 접속과 같은 상황에서는 불필요하며, 주로 시스템 명령어를 실행하기 위한 목적으로
    # 사용되므로 필터링하는 것이 좋다.
    SecFilter "../"
    
    # XSS(Cross site scripting) 공격에 대비하기 위한 설정으로 XSS 공격은 공격자가 HTML이나
    # 자바 스크립트 등을 웹 페이지에 몰래 삽입해 다른 사용자가 실행해 쿠키 등의 정보를
    # 획득하는 것을 말한다. 
    SecFilter "<[[:space:]]*script"
    SecFilter "<(.|n)+>"
    
    # SQL Injection 등 SQL과 관련된 공격을 차단할 때 사용한다. 
    # 그러나 잘못 사용했을 경우에는 정상적인 SQL 질의도 필터링되므로 적용 시 주의해야 한다.
    SecFilter "delete[[:space:]]+from"
    SecFilter "insert[[:space:]]+into"
    SecFilter "select.+from"

    테스트 방법

    curl --head http://127.0.0.1/

    Modsecurity 2.1.1 설치

    modsecurity-apache_2.1.1 은 Apache 2.x 버전에서만 설치된다.

    yum install -y pcre.i386 pcre-devel.i386

    yum install -y libxml2.i386 libxml2-python.i386 libxml2-devel.i386

    tar xvzpf modsecurity-apache_2.1.1.tar.gz

    cd modsecurity-apache_2.1.1/apache2

    vi Makefile

    top_dir = /etc/httpd
    INCLUDES = -I /usr/include/libxml2

    Apache 2.2.x 이상에서는 httpd Build 디렉토리를 링크를 시켜준다.

    Makefile:25: /etc/httpd/build/special.mk: 그런 파일이나 디렉토리가 없음.
    make: *** 타겟 /etc/httpd/build/special.mk'를 만들 규칙이 없음. 멈춤.

    위와 같은 에러시 Build 디렉토리를 링크 시킨다.

    cd /etc/httpd

    ln -s ../../usr/lib/httpd/build build

    cd modsecurity-apache_2.1.1/apache2

    make; make install

    vi /etc/httpd/conf/httpd.conf

    ModSecurity2

    LoadFile /usr/lib/libxml2.so
    LoadModule security2_module modules/mod_security2.so

    Include conf.d/modsecurity2/*.conf

    mkdir /etc/httpd/conf.d/modsecurity2

    cp -arv modsecurity-apache_2.1.1/rules/*.conf /etc/httpd/conf.d/modsecurity2/

    cp -arv modsecurity-apache_2.1.1/rules/blocking/*.conf /etc/httpd/conf.d/modsecurity2/

    service httpd restart

    ######## Quota 설정

    vi /etc/fstab

    LABEL=/home /home ext3 defaults,usrquota,grpquota 1 2

    touch /home/aquota.user

    touch /home/aquota.group

    chmod 600 /home/aquota.*

    mount -o remount,rw /home

    quotacheck -avug

    quotaon -avug

    vi /etc/rc.local

    Check quota and then turn quota on.

    if [ -x /usr/sbin/quotacheck ]
    then
    echo "Checking quotas. This may take some time."
    /usr/sbin/quotacheck -avug
    echo " Done."
    fi

    if [ -x /usr/sbin/quotaon ]
    then
    echo "Turning on quota."
    /usr/sbin/quotaon -avug
    fi

    edquota -u Account

    edquota -g Account

    quota -v Account 명령어로 현재 설정된 쿼타를 확인할 수 있다.

    Disk quotas for user Account (uid 500):
    Filesystem blocks quota limit grace files quota limit grace
    /dev/sda7 32 0 0 7 0 0

    • Filesystem : 쿼타를 적용할 대상의 파일시스템
    • blocks : 사용자가 사용중인 파티션의 총 블럭(kb단위)을 의미
    • soft : soft limit는 사용자가 사용할 수 있는 최대 용량을 의미하며 이 용량 이상 사용은 불가능합니다.
          그러나 만약 Grace Period가 설정되어 있다면 사용자는 soft limit를 초과했을 경우에
          시스템의 경고를 받지만 hard limit까지 사용할 수 있습니다.
    • hard : hard limit는 Grace Period가 설정되어 있을 경우에만 동작하며, 실제 최대용량을 의미합니다.
    • inodes : 사용자가 사용하는 현재 파일의 갯수를 의미
    • soft : 두번째 soft limit는 사용자가 사용할 수 있는 최대 파일갯수를 의미합니다.
    • hard : 두번째 hard limit 역시 Grace Period가 설정되어 있을 경우만 작동하게 됩니다.
    • grace period : 유예기간은 사용자의 soft limit을 초과했을 경우부터 적용되어 지는 시간제한입니다.
          시간은 sec, min, hour, day, week, month 단위로 사용할 수 있으며 디폴트는 7일 입니다

    repquota -a 명령어를 통해 현재 설정된 파일시스템에 한해 quota 보고서를 출력

    ########## Webalizer 호스팅을 위한 설정 ####

    mkdir /home/webalizer_conf

    #vi /etc/weballizer.conf

    아래 처럼 주석처리 한다.

    LogFile /var/log/httpd/access_log

    OutputDir /var/www/usage

    HostName localhost

    cp -arv /etc/webalizer.conf /home/webalizer_conf/default.conf

    mkdir /home/kalrielra/weblog

    cp -arv /home/webalizer_conf/default.conf /home/webalizer_conf/kalrielra.co.kr.conf

    vi /home/webalizer_conf/kalrielra.co.kr.conf

    • LogFile /home/kalrielra/logs/kalrielra.co.kr-access_log ==>httpd.conf 의 로그와 같아야 한다!!
    • OutputDir /home/kalrielra/weblog/
    • HostName www.kalrielra.co.kr

      weblizer -c /home/webalizer_conf/kalrielra.co.kr.conf

    crontab -e

    10분마다 리프레쉬

    /10 * * * * /usr/bin/webalizer -c /home/webalizer_conf/.conf

    vi /usr/local/bin/webalizer.sh

    /usr/bin/webalizer -c /home/webalizer_conf/*.conf

    crontab -e

    매일 04시 02분 리프레쉬

    02 4 * * * root run-parts /usr/local/bin/webalizer.sh

    ######### AWStats 설치

    rpm -Uvh awstats-6.6-1.noarch.rpm

    ----- AWStats 6.6 - Laurent Destailleur -----
    AWStats files have been installed in /usr/local/awstats

    If first install, follow instructions in documentation
    (/usr/local/awstats/docs/index.html) to setup AWStats in 3 steps:
    Step 1 : Install and Setup with awstats_configure.pl (or manually)
    Step 2 : Build/Update Statistics with awstats.pl
    Step 3 : Read Statistics

    rpm -Uvh awstats-6.6-1.noarch.rpm

    /usr/local/awstats/wwwroot/cgi-bin/awstats.pl

    1. Enter full config file path of your Web server.
      /etc/httpd/conf/httpd.conf
    2. Need to create a new config file ?
      Y
    3. Define config file name to create
      joy.to
    4. Enter
    5. Enter

    vi /etc/awstats/awstats.joy.to.conf

    Lang="ko"
    LogFile="/home/joy/logs/jo.to-access.log"
    DirData="/home/joy/public_html/weblog/"

    mkdir /var/lib/awstats -->> DirData 디렉토리가 없을경우 생성해준다.

    /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=joy.to

    http://www.joy.to/awstats/awstats.pl?config=joy.to

    vi /etc/crontab

    0-59/6 * * * * root /usr/local/awstats/wwwroot/cgi-bin/awstats.pl awstats -update -config=joy.to

    반응형

    댓글

    Designed by JB FACTORY