Linux2013. 6. 24. 21:41

* CentOS 6.x 64비트 환경에 php 5.4버전에 memcache 설치.

* yum 저장소 추가
rpm -Uhv http://apt.sw.be/redhat/el6/en/x86_64/rpmforge/RPMS/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm

yum -y install memcached


*****************************************************
만약 패키지가 없어서 설치가 안 되거나, 최신 버전으로 rpm을 만들어서 설치할려면 실행

최신 버전 다운로드
wget http://memcached.org/latest

* 의존성 에러가 날 경우
yum install gcc libevent libevent-devel

* 현재 1.4.15버전이 가장 최신 버전일 경우
rpmbuild -ta memcached-1.4.15.tar.gz

파일 생성시간이 조금 걸리니 에러없이 처리되면 rpm 파일을 생성된다.


* rpm 파일의 생성을 확인한다.
ll /root/rpmbuild/RPMS/x86_64/memcached-1.4.15-1.el6.x86_64.rpm


memcached-1.4.15-1.x86_64.rpm
memcached-debuginfo-1.4.15-1.x86_64.rpm

두개의 파일이 생성되어 있다.

* 설치
rpm -Uvh /root/rpmbuild/RPMS/x86_64/memcached-1.4.15-1.el6.x86_64.rpm
rpm -qa |grep memcached
*****************************************************


* 내용 확인
vi /etc/sysconfig/memcached
-----------------------------------------------
PORT=”11211″ #define on which port to urn
USER=”nobody” #same as apache user
MAXCONN=”1024″ #maximum number of connections allowed
CACHESIZE=”64″ #memory used for caching
OPTIONS=”" #use for any custom options
-----------------------------------------------

memcached -h

/etc/init.d/memcached start

/etc/init.d/memcached status

-----------------------------------------------

memcached (pid 9795)를 실행 중...

-----------------------------------------------


netstat -anp | grep 11211
-----------------------------------------------
tcp 0 0 0.0.0.0:11211 0.0.0.0:* LISTEN 9795/memcached
udp 0 0 0.0.0.0:11211 0.0.0.0:* 9795/memcached
-----------------------------------------------

* php 확장 모듈 설치


cd /home/admin/
wget http://pecl.php.net/get/memcache-2.2.7.tgz


tar zxvf memcache-2.2.7.tgz
cd memcache-2.2.7
phpize
./configure
make
make install


# 만약 아래의 에러가 발생할때에 추가해준다.

error: memcache support requires ZLIB.

yum install zlib-devel


php -i | grep php.ini
-----------------------------------------------
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini
-----------------------------------------------

# 아래의 에러가 발생할때 수정해준다.

PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function.


vi /etc/php.ini

[Date]
date.timezone = Asia/Seoul



ll /usr/lib64/php/modules/memcache.so

vi /etc/php.d/memcache.ini
-----------------------------------------------
extension = memcache.so
-----------------------------------------------

cat memcache.ini
-----------------------------------------------
extension = memcache.so
-----------------------------------------------

/etc/init.d/httpd restart

php -i | grep memcache
-----------------------------------------------
/etc/php.d/memcache.ini,
memcache
memcache support => enabled
memcache.allow_failover => 1 => 1
memcache.chunk_size => 8192 => 8192
memcache.default_port => 11211 => 11211
memcache.default_timeout_ms => 1000 => 1000
memcache.hash_function => crc32 => crc32
memcache.hash_strategy => standard => standard
memcache.max_failover_attempts => 20 => 20
Registered save handlers => files user memcache
-----------------------------------------------

* 모듈 확인
php -m
memcache


* 항상 실행

chkconfig memcached on

chkconfig --list |grep memcached


* 브라우저에서 확인
vi test_mem.php
-----------------------------------------------
<?php
$memcache = new Memcache;
$memcache->connect('localhost', 11211) or die ("Could not connect");

$version = $memcache->getVersion();
echo "Server's version: ".$version."<br/>\n";

$tmp_object = new stdClass;
$tmp_object->str_attr = 'test';
$tmp_object->int_attr = 123;

$memcache->set('key', $tmp_object, false, 10) or die ("Failed to save data at the server");
echo "Store data in the cache (data will expire in 10 seconds)<br/>\n";

$get_result = $memcache->get('key');
echo "Data from the cache:<br/>\n";

var_dump($get_result);
?>
-----------------------------------------------


브라우저에서 대략 이런 문자가 나타나면 성공
-----------------------------------------------
Server's version: 1.4.5
Store data in the cache (data will expire in 10 seconds)
Data from the cache:
object(stdClass)#3 (2) { ["str_attr"]=> string(4) "test" ["int_attr"]=> int(123) }
-----------------------------------------------

'Linux' 카테고리의 다른 글

linux 특정문자가 있는 파일 확인  (0) 2014.11.26
CentOS pear,soap 설치  (0) 2014.05.07
CentOs NFS설정  (0) 2014.03.20
CentOS 6.3 APM설치  (0) 2014.02.28
[Linux] ssh 디렉터리 삭제. 안지워지고 에러날때??  (0) 2013.05.23
Posted by E.No