0088 | LUSCA CDN installation

Thursday, January 14th, 2010 Posted in Misc | No Comments »

จดไว้กันลืมครับ ไม่ต้องใส่ใจมากมาย

http://code.google.com/p/lusca-cache/downloads/list

./configure --prefix=/usr/local/lusca --with-maxfd=32768 --with-aio --with-pthreads --disable-ident-lookups --enable-snmp --enable-storeio="aufs" --enable-removal-policies="heap lru" --disable-wccp && make && make install
ln -s /usr/local/lusca/etc /etc/lusca
ln -s /usr/local/lusca/var/logs /var/log/lusca
mkdir /usr/local/lusca/var/cache
chown nobody /usr/local/lusca/var/cache /usr/local/lusca/var/logs
ln -s /usr/local/lusca/sbin/squid /usr/sbin/squid
ln -s /usr/local/lusca/bin/squidclient /usr/bin/squidclient

cron

4 * * * * /usr/sbin/squid -k rotate

config

acl all src all
acl manager proto cache_object
acl localhost src 127.0.0.1/32
acl CONNECT method CONNECT
http_access allow manager localhost
http_access deny manager
http_access deny CONNECT
acl upic_host dst 124.109.2.175 124.109.2.176
acl upic_port port 80
http_access allow upic_host upic_port
http_access deny all
icp_access deny all
http_port 80 accel vhost
cache_peer 124.109.2.176 parent 80 0 weight=5 no-query round-robin
cache_peer 124.109.2.175 parent 80 0 weight=5 no-query round-robin
cache_mem 32 MB
maximum_object_size_in_memory 16 KB
memory_replacement_policy heap GDSF
cache_replacement_policy heap LFUDA
cache_dir aufs /usr/local/lusca/var/cache 8192 16 256
logformat combined %>a %ui %un [%tl] "%rm %ru HTTP/%rv" %Hs %<st "%{Referer}>h" "%{User-Agent}>h" %Ss:%Sh
access_log /usr/local/lusca/var/logs/access.log combined
cache_store_log none
logfile_rotate 24
refresh_pattern ^ftp:           1440    20%     10080
refresh_pattern ^gopher:        1440    0%      1440
refresh_pattern -i (/cgi-bin/|\?) 0     0%      0
refresh_pattern .               0       20%     4320
acl shoutcast rep_header X-HTTP09-First-Line ^ICY.[0-9]
upgrade_http0.9 deny shoutcast
acl apache rep_header Server ^Apache
broken_vary_encoding allow apache
cache_effective_user nobody
server_persistent_connections off
acl nullreferer referer_regex ^$
cache deny nullreferer
visible_hostname cdn.upic.me
snmp_port 3401
acl snmppublic snmp_community public
snmp_access allow snmppublic localhost
snmp_access deny all
never_direct allow all
coredump_dir /usr/local/lusca/var/cache
pid_filename /var/run/lusca.pid

/etc/init.d/lusca

#!/bin/bash
# squid         This shell script takes care of starting and stopping
#               Squid Internet Object Cache
#
# chkconfig: - 90 25
# description: Squid - Internet Object Cache. Internet object caching is \
#       a way to store requested Internet objects (i.e., data available \
#       via the HTTP, FTP, and gopher protocols) on a system closer to the \
#       requesting site than to the source. Web browsers can then use the \
#       local Squid cache as a proxy HTTP server, reducing access time as \
#       well as bandwidth consumption.
# pidfile: /var/run/squid.pid
# config: /etc/squid/squid.conf
 
PATH=/usr/bin:/sbin:/bin:/usr/sbin
export PATH
 
# Source function library.
. /etc/rc.d/init.d/functions
 
# Source networking configuration.
. /etc/sysconfig/network
 
# don't raise an error if the config file is incomplete
# set defaults instead:
SQUID_OPTS=${SQUID_OPTS:-"-D"}
SQUID_PIDFILE_TIMEOUT=${SQUID_PIDFILE_TIMEOUT:-20}
SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-100}
 
# determine the name of the squid binary
[ -f /usr/sbin/squid ] && SQUID=squid
 
prog="$SQUID"
 
# determine which one is the cache_swap directory
CACHE_SWAP=`sed -e 's/#.*//g' /etc/lusca/squid.conf | \
        grep cache_dir |  awk '{ print $3 }'`
[ -z "$CACHE_SWAP" ] && CACHE_SWAP=/usr/local/lusca/var/cache/
 
RETVAL=0
 
start() {
        ulimit -HSn 32768
        #check if the squid conf file is present
        if [ ! -f /etc/lusca/squid.conf ]; then
            echo "Configuration file /etc/lusca/squid.conf missing" 1>&2
            exit 6
        fi
 
        # don't raise an error if the config file is incomplete.
        # set defaults instead:
        SQUID_OPTS=${SQUID_OPTS:-"-D"}
        SQUID_PIDFILE_TIMEOUT=${SQUID_PIDFILE_TIMEOUT:-20}
        SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-100}
 
        if [ -z "$SQUID" ]; then
                echo "Insufficient privilege" 1>&2
                exit 4
        fi
 
        for adir in $CACHE_SWAP; do
        if [ ! -d $adir/00 ]; then
             echo -n "init_cache_dir $adir... "
             $SQUID -z -F -D >> /var/log/lusca/squid.out 2>&1
        fi
    done
    echo -n $"Starting $prog: "
    $SQUID $SQUID_OPTS >> /var/log/lusca/squid.out 2>&1
    RETVAL=$?
    if [ $RETVAL -eq 0 ]; then
       timeout=0;
       while : ; do
          [ ! -f /var/run/lusca.pid ] || break
          if [ $timeout -ge $SQUID_PIDFILE_TIMEOUT ]; then
             RETVAL=1
             break
          fi
          sleep 1 && echo -n "."
          timeout=$((timeout+1))
       done
    fi
    [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$SQUID
    [ $RETVAL -eq 0 ] && echo_success
    [ $RETVAL -ne 0 ] && echo_failure
    echo
    return $RETVAL
}
 
stop() {
 
    # don't raise an error if the config file is incomplete.
    # set defaults instead:
    SQUID_SHUTDOWN_TIMEOUT=${SQUID_SHUTDOWN_TIMEOUT:-100}
 
    echo -n  $"Stopping $prog: "
    $SQUID -k check >> /var/log/lusca/squid.out 2>&1
    RETVAL=$?
    if [ $RETVAL -eq 0 ] ; then
        $SQUID -k shutdown &
        rm -f /var/lock/subsys/$SQUID
        timeout=0
        while : ; do
                [ -f /var/run/lusca.pid ] || break
                if [ $timeout -ge $SQUID_SHUTDOWN_TIMEOUT ]; then
                    echo
                    return 1
                fi
                sleep 2 && echo -n "."
                timeout=$((timeout+2))
        done
        echo_success
        echo
    else
        echo_failure
        echo
    fi
    return $RETVAL
}
 
reload() {
#    . /etc/sysconfig/squid
    # don't raise an error if the config file is incomplete.
    # set defaults instead:
    SQUID_OPTS=${SQUID_OPTS:-"-D"}
 
    $SQUID $SQUID_OPTS -k reconfigure
}
 
restart() {
    stop
    start
}
 
condrestart() {
    [ -e /var/lock/subsys/squid ] && restart || :
}
 
rhstatus() {
    status $SQUID && $SQUID -k check
}
 
probe() {
    return 0
}
 
case "$1" in
start)
    start
    ;;
 
stop)
    stop
    ;;
 
reload)
    reload
    ;;
 
restart)
    restart
    ;;
 
condrestart)
    condrestart
    ;;
 
status)
    rhstatus
    ;;
 
probe)
    exit 0
    ;;
 
*)
    echo $"Usage: $0 {start|stop|status|reload|restart|condrestart}"
    exit 2
esac
 
exit $?

Tags: , ,

0085 | DirectAdmin + mod_fcgid + php fastcgi

Saturday, November 14th, 2009 Posted in Linux, Web Server | 12 Comments »

ก่อนอื่น copy & paste ตามสูตร

cd /usr/local/src
wget http://mirrors.issp.co.th/apache/httpd/mod_fcgid/mod_fcgid-2.3.4.tar.bz2
tar jxf mod_fcgid-2.3.4.tar.bz2
cd mod_fcgid-2.3.4
APXS=/usr/sbin/apxs ./configure.apxs && make && make install
chmod 755 -R /var/lib/httpd
mkdir /fcgi

ไปที่ /usr/local/directadmin/custombuild/
เปิดไฟล์ options.conf แก้ php5_cgi=yes ส่วน php อันอื่น no ให้หมด
แล้วสั่ง ./build php จนเสร็จ

แล้วเปิดไฟล์ /etc/httpd/conf/extra/httpd-info.conf
เพิ่มไอ้นี่ต่อท้าย

LoadModule fcgid_module /usr/lib/apache/mod_fcgid.so
 
SharememPath /var/run/fcgid_shm
SocketPath /var/lib/httpd/fcgid/sock
 
 
 
<IfModule mod_fcgid.c>
  IdleTimeout 3600
  ProcessLifeTime 7200
  MaxProcessCount 128
  DefaultMaxClassProcessCount 4
  IPCConnectTimeout 60
  IPCCommTimeout 90
  DefaultInitEnv RAILS_ENV production
#  DefaultInitEnv PHP_FCGI_CHILDREN 4
#  MaxRequestsPerProcess 500
</IfModule>
 
<Directory "/home">
        AllowOverride All
        Options SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
        <IfModule sapi_apache2.c>
        php_admin_flag engine off
        </IfModule>
        <IfModule mod_php5.c>
        php_admin_flag engine off
        </IfModule>
</Directory>

เสร็จแล้วเข้าไป folder /usr/local/directadmin/data/templates
เปิดไฟล์ที่ขึ้นต้นด้วย virtual_host2*.conf (มีทั้งหมด 4 ไฟล์)
ใน section เดิมที่เป็น PHP ทั้งหมด ให้ comment ไว้ จะได้ประมาณนี้

|*if CLI="1"|
#               php_admin_flag engine |PHP|
#               <IfModule !mod_php6.c>
#                       php_admin_flag safe_mode |SAFE_MODE|
#               </IfModule>
#               php_admin_value sendmail_path '/usr/sbin/sendmail -t -i -f |USER|@|DOMAIN|'
|*endif|
|*if OPEN_BASEDIR="ON"|
#               php_admin_value open_basedir |OPEN_BASEDIR_PATH|
|*endif|
|*if SUPHP="1"|
#                suPHP_Engine |PHP|
#               suPHP_UserGroup |USER| |GROUP|
|*endif|

แล้วแทรกไอ้นี่เข้าไปด้านบนของไอ้เมื่อกี้

	<IfModule mod_fcgid.c>
		<Files ~ (\.fcgi)>
			SetHandler fcgid-script
			Options +FollowSymLinks +ExecCGI
		</Files>
	</IfModule>
	<IfModule mod_fcgid.c>
	<Files ~ (\.php)>
		SetHandler fcgid-script
		FCGIWrapper "/fcgi/|USER|/public_html/fcgid.sh" .php
		Options +ExecCGI
		allow from all
	</Files>
	</IfModule>

แล้วเข้าไป folder /usr/local/directadmin/scripts/custom/
สร้างไฟล์ชื่อ fcgid.sh ใส่ข้อมูลตามนี้

#!/bin/sh
export PHP_FCGI_MAX_REQUESTS=0
exec /usr/local/php5/bin/php-cgi

ใน folder เดียวกัน สร้างไฟล์ชื่อ domain_create_post.sh ใส่ข้อมูลตามนี้

#!/bin/sh
 
mkdir -p /fcgi/${username}/public_html
cp /usr/local/directadmin/scripts/custom/fcgid.sh /fcgi/${username}/public_html/fcgid.sh && chmod 0700 /fcgi/${username}/public_html/fcgid.sh
cp /usr/local/directadmin/scripts/custom/php.ini /fcgi/${username}/public_html/php.ini
perl -pi -w -e "s/PHPCFG_BASEDIR/\/home\/${username}\//g;" /fcgi/${username}/public_html/php.ini
chown -R ${username}:${username} /fcgi/${username}
echo "`date`  ${domain} created  " >> /var/log/directadmin/domain_create.log

แล้วสั่ง copy file php.ini มาใส่ไว้ใน /usr/local/directadmin/scripts/custom/php.ini
เปิดไฟล์ /usr/local/directadmin/scripts/custom/php.ini ที่ก๊อปมาเมื่อกี้ แล้วหา open_basedir
ซึ่งปกติมันจะ comment ไว้ ให้แก้เป็นประมาณนี้

open_basedir = PHPCFG_BASEDIR:/tmp:/var/tmp

เสร็จแล้วสั่ง chmod a+x /usr/local/directadmin/scripts/custom/*.sh

*** วิธีทั้งหมดไม่รับประกันผล และควรใช้กับเครื่องเพิ่งลงใหม่เท่านั้น

Tags: , , ,