01-08-2012, 10:05 AM
|
#1 |
| عضو | شرح تسطيب memcached المسرع الرائع مع ضبط الاعدادات السلام عليكم ورحمة الله وبركاته
اليوم سوف نتطرق الى شرح كيفية تركيب memcached اخر اصدار له حاليا ( حصري ) , memcached غني عن التعريف فهو مسرع جيد ورائع ينافس على الصدارة يمتز في تسريع تطبيقات الويب الديناميكية من خلال التخفيف من تحميل قاعدة البيانات وكذلك الذاكرة توزيع نظام التخزين المؤقت .
اول شيئ ، ننفد الامر التالي :
لتركيب libevent :
رمز Code:
yum install libevent libevent-devel -y
ثم
رمز Code:
wget http://memcached.googlecode.com/file...-1.4.10.tar.gz
ثم
رمز Code:
tar xvf memcached-1.4.10.tar.gz
ثم
رمز Code:
cd memcached-1.4.10
ثم
رمز Code:
./configure && make && make install
ثم الان سوف نفتح ملف: /etc/memcached.conf لتعديله نفد الكود التالي لفتحه :
رمز Code:
pico /etc/memcached.conf
قم الان بنقل التالي للملف :
رمز Code:
#Memory a usar
-m 16
# default port
-p 11211
# user to run daemon nobody/apache/www-data
-u nobody
# only listen locally
-l 127.0.0.1
وقم بحفظ ملف بعد تلصيق البيانات ( Ctrl + x ) + y + ( ok)
ثم , الان نفد التالي:
رمز Code:
touch /etc/init.d/memcached
ثم
رمز Code:
chmod +x /etc/init.d/memcached
الان نفس الطريقة السابقة سوف نعدل على ملف : /etc/init.d/memcached نفد التالي :
رمز Code:
pico /etc/init.d/memcached
قم الان بنقل التالي للملف :
رمز Code:
#!/bin/bash
#
# memcached This shell script takes care of starting and stopping
# standalone memcached.
#
# chkconfig: - 80 12
# description: memcached is a high-performance, distributed memory
# object caching system, generic in nature, but
# intended for use in speeding up dynamic web
# applications by alleviating database load.
# processname: memcached
# config: /etc/memcached.conf
# Source function library.
. /etc/rc.d/init.d/functions
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/local/bin/memcached
DAEMONBOOTSTRAP=/usr/local/bin/start-memcached
DAEMONCONF=/etc/memcached.conf
NAME=memcached
DESC=memcached
PIDFILE=/var/run/$NAME.pid
[ -x $DAEMON ] || exit 0
[ -x $DAEMONBOOTSTRAP ] || exit 0
RETVAL=0
start() {
echo -n $"Starting $DESC: "
daemon $DAEMONBOOTSTRAP $DAEMONCONF
RETVAL=$?
[ $RETVAL -eq 0 ] && touch $PIDFILE
echo
return $RETVAL
}
stop() {
echo -n $"Shutting down $DESC: "
killproc $NAME
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && rm -f $PIDFILE
return $RETVAL
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
restart|reload)
stop
start
RETVAL=$?
;;
status)
status $prog
RETVAL=$?
;;
*)
echo $"Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit $RETVAL
وقم بحفظ ملف بعد تلصيق البيانات ( Ctrl + x ) + y + ( ok)
ثم، نفد التالي:
رمز Code:
touch /usr/local/bin/start-memcached
ثم
رمز Code:
chmod +x /usr/local/bin/start-memcached
الان نفس الطريقة السابقة سوف نعدل على ملف : /usr/local/bin/start-memcached نفد التالي :
رمز Code:
pico /usr/local/bin/start-memcached
قم الان بنقل التالي للملف :
رمز Code:
#!/usr/bin/perl -w
# start-memcached
# 2003/2004 – Jay Bonci
# This script handles the parsing of the /etc/memcached.conf file
# and was originally created for the Debian distribution.
# Anyone may use this little script under the same terms as
# memcached itself.
use strict;
if ($> != 0 and $< != 0) {
print STDERR “Only root wants to run start-memcached.\n”;
exit;
}
my $etcfile = shift || “/etc/memcached.conf”;
my $params = [];
my $etchandle;
# This script assumes that memcached is located at /usr/bin/memcached, and
# that the pidfile is writable at /var/run/memcached.pid
my $memcached = “/usr/local/bin/memcached”;
my $pidfile = “/var/run/memcached.pid”;
# If we don’t get a valid logfile parameter in the /etc/memcached.conf file,
# we’ll just throw away all of our in-daemon output. We need to re-tie it so
# that non-bash shells will not hang on logout. Thanks to Michael Renner for
# the tip
my $fd_reopened = “/dev/null”;
sub handle_logfile {
my ($logfile) = @_;
$fd_reopened = $logfile;
}
sub reopen_logfile {
my ($logfile) = @_;
open *STDERR, “>>$logfile”;
open *STDOUT, “>>$logfile”;
open *STDIN, “>>/dev/null”;
$fd_reopened = $logfile;
}
# This is set up in place here to support other non -[a-z] directives
my $conf_directives = {
“logfile” => \&handle_logfile
};
if (open $etchandle, $etcfile) {
foreach my $line () {
$line =~ s/\#.*//go;
$line = join ‘ ‘, split ‘ ‘, $line;
next unless $line;
next if $line =~ /^\-[dh]/o;
if ($line =~ /^[^\-]/o) {
my ($directive, $arg) = $line =~ /^(.*?)\s+(.*)/;
$conf_directives->{$directive}->($arg);
next;
}
push @$params, $line;
}
}
unshift @$params, “-u root” unless (grep $_ eq ‘-u’, @$params);
$params = join ” “, @$params;
if (-e $pidfile) {
open PIDHANDLE, “$pidfile”;
my $localpid = ;
close PIDHANDLE;
chomp $localpid;
if (-d “/proc/$localpid”) {
print STDERR “memcached is already running.\n”;
exit;
} else {
`rm -f $localpid`;
}
}
my $pid = fork();
if ($pid == 0) {
reopen_logfile($fd_reopened);
exec “$memcached $params”;
exit(0);
} elsif (open PIDHANDLE,”>$pidfile”) {
print PIDHANDLE $pid;
close PIDHANDLE;
} else {
print STDERR “Can’t write pidfile to $pidfile.\n”;
}
وقم بحفظ ملف بعد تلصيق البيانات ( Ctrl + x ) + y + ( ok)
الان نعمل ريستار لــــ memcached بتنفيد التالي :
رمز Code:
/etc/init.d/memcached restart
لتأكد من تشغيله :
رمز Code:
ps aux | grep memcached
من المتوقع سوف يظهر لك هكذا :
رمز Code:
ps aux | grep memcached
nobody 5960 0.4 0.2 18118 16334 pts/0 S 18:05 0:00 /usr/local/bin/me
الآن سوف نضعه يشغل نفد التالي :
رمز Code:
/sbin/chkconfig memcached on
رمز Code:
/sbin/chkconfig –list | grep memcached
الآن سوف نقوم بتثبيت البرنامج المساعد لmemcache PHP.
سوف نركب ان شاء الله اخر نسخة له
نفد فقط الاوامر التالية :
رمز Code:
wget http://pecl.php.net/get/memcache-3.0.6.tgz
رمز Code:
tar xvf memcache-3.0.6.tgz
رمز Code:
cd memcache-3.0.6
رمز Code:
phpize
رمز Code:
./configure && make && make install
الان نفتح ملف : /usr/local/lib/php.ini
نفد التالي :
رمز Code:
pico /usr/local/lib/php.ini
اضف في اخره التالي :
رمز Code:
extension=memcache.so
الآن إعادة تشغيل اباتشي نفد التالي :
رمز Code:
service httpd restart
وسوف نتحقق الآن للتأكد من اشتغاله
ننشأ مثلا ملف باسم test.php
لفتحه سوف ننفد التالي :
رمز Code:
cat > test.php
نفتحه الان :
رمز Code:
pico test.php
نضع فيه هذا الكود :
رمز Code:
نحفظه ونطبق التالي :
رمز Code:
php -f test.php | grep “memcache support”
اذا كتب لنا :
رمز Code:
memcache support => enabled
فأنه شغال, بعدها سوف تحدف ملف test.php.
مبارك عليكم المسرع .
لكم ودي وتقديري
|
| |