NOSQL – Redis 설치 CentOS or Window
Redis는 Memcache와 같은 NoSQL이지만, 기능이나 확장성이 현저히 좋습니다.
보안은 기본적으로 사용자단에서 iptables와 같은 것으로 접근제어를 해야 하구요.
vmware에서 후원 합니다.
1. window
1) redis 사이트에서 redis 다운 및 설치 : https://github.com/MSOpenTech/redis
D:\F\server\redis2.8\bin\release\redis-2.8.12
RedisService.docx 참조
서비스 등록 Installing the Service redis-server --service-install redis.windows.conf --loglevel verbose 서비스 삭제 redis-server --service-uninstall 서비스 시작 redis-server --service-start 서비스 중지 redis-server --service-stop
2) php_redis.dll 다운 및 설치 : https://github.com/nicolasff/phpredis/downloads
– 자신의 버젼에 맞는 php 모듈을 다운로드 한다.
C:\_theingka\apm\php-5.2.10\ext\모둘 copy
php.ini 편집
extension=php_redis.dll
3) 참고 사이트
http://www.phpschool.com/link/tipntech/77300
http://sir.co.kr/bbs/board.php?bo_table=g5_tip&wr_id=1930
2. CentOS
1) redis 설치
– Centos 6.4 리눅스 서버에 redis.io 사이트에서 다운받은 redis를 설치하였습니다.
설치과정은 아래와 같이 간단합니다. 설치 위치는 각자 알아서 ~
# cd /usr/local/src/ # wget http://download.redis.io/releases/redis-2.8.12.tar.gz # tar xzf redis-2.8.12.tar.gz # cd redis-2.8.12 # make
– 요건 걍 테스트로 실행
#redis-server & (백그라운드 실행)
#redis-server /etc/redis/redis.conf (설치 파일의 redis.conf 수정하여 /etc/redis로 복사. daemonize를 yes로 하면 백그라운드 실행)
Redis 서버는 기본적으로 비밀번호로 잠겨있지 않기 때문에 별도의 설정이 필요합니다.
redis.conf : requirepass 접속비밀번호 편집가능
– 서버 시작
redis-server (redis-server) #cd src/ #cd utils/install_server.sh (요기서 포트 및 conf위치 설정가능함)
[root@theingka utils]# ./install_server.sh Welcome to the redis service installer This script will help you easily set up a running redis server Please select the redis port for this instance: [6379] Selecting default: 6379 Please select the redis config file name [/etc/redis/6379.conf] Selected default - /etc/redis/6379.conf Please select the redis log file name [/var/log/redis_6379.log] Selected default - /var/log/redis_6379.log Please select the data directory for this instance [/var/lib/redis/6379] Selected default - /var/lib/redis/6379 Please select the redis executable path [/usr/local/bin/redis-server] Selected config: Port : 6379 Config file : /etc/redis/6379.conf Log file : /var/log/redis_6379.log Data dir : /var/lib/redis/6379 Executable : /usr/local/bin/redis-server Cli Executable : /usr/local/bin/redis-cli Is this ok? Then press ENTER to go on or Ctrl-C to abort. Copied /tmp/6379.conf => /etc/init.d/redis_6379 Installing service... Successfully added to chkconfig! Successfully added to runlevels 345! Starting Redis server... Installation successful!
서버에 redis 정상 작동하는지 테스트 해봅니다. redis-cli (redis-client) $src/redis-cli redis> set foo bar OK redis> get foo "bar" redis-benchmark (redis로 처리가능한 성능을 알려주는 프로그램) # redis-benchmark ... 96.62% <= 1 milliseconds 100.00% <= 1 milliseconds 67567.57 requests per second
– 테스트가 진행되지 않는다면 tcl 설치후
yum install tcl (8.x 버젼 이상의 tcl이 있어야 test가 가능) make test make install
2) redis.so 설치
– unzip : http://dev.wo.tc/archives/37 참고
wget https://github.com/nicolasff/phpredis/zipball/master -O phpredis.zip unzip phpredis.zip
phpize
– php의 확장모듈 (php extention) 을 올리는 유틸
-but 내 서버에서 안된다.
# phpize -bash: phpize: command not found # php -m | grep phpize # rpm -qa | grep php-devel
– yum으로 설치
# yum install php-devel Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile ......... Complete! phpize ./configure make && make install
/usr/lib64/php/modules/redis.so 생성됨
php.ini 파일 편집
; Dynamic Extensions ; extension=redis.so
apache를 재시작 하면 됩니다.
3) 참고사이트
http://trend21c.tistory.com/1645
http://sir.co.kr/bbs/board.php?bo_table=g5_tip&wr_id=1930
http://www.phpschool.com/link/tipntech/77091
https://github.com/nicolasff/phpredis#installation
3. 사이트 연동
1) PHP 소스정의
- 세션 정의된 파일 수정 @ini_set('session.save_handler', 'redis'); @ini_set('session.save_path', 'tcp://127.0.0.1:6379'); - redis 저장 key, values $call_key = "latest-{$bo_table}-{$skin_dir}-{$rows}-{$subject_len}"; $list = array( "list" => $list_temp, "bo_subject" => $bo_subject, ); $redis->setex($call_key, $cache_time, $list); - redis 추출 $call_key = "latest-{$bo_table}-{$skin_dir}-{$rows}-{$subject_len}"; $redis = new Redis(); $redis->connect('127.0.0.1', 6379); $redis->setOption(Redis::OPT_SERIALIZER, Redis::SERIALIZER_PHP); if($redis->ttl($call_key) > 0) { $list = $redis->get($call_key); }
2) 참고사이트
http://sir.co.kr/bbs/board.php?bo_table=g5_tip&wr_id=1930
워드프레스 편집기로 다 적으니 완전 빡셈
텍스트 파일 첨부함 : redis_설치