• Redis 설치 및 셋팅 [EC2] :: 마이구미
    리눅스 2017. 3. 2. 15:55
    반응형

    이번 글은 Redis 설치 및 셋팅에 대해 다뤄본다.

    본인은 Amazon EC2 인스턴스를 사용한다.

    12개월간 무료인 서비스가 있으니 몰랐다면 좋은 경험이 될 것이다. (Amazon EC2 Free Tier)


    OS는 Amazon Linux AMI 기준으로 글을 작성한다.


    Redis 설치와 셋팅을 알아보자.

    여기서 셋팅은 조금 더 효율적으로 Redis를 설치하여 사용하는 법을 말한다.

    예를 들어 일반적으로 설치를 하면 Redis Server를 실행하더라도 Server가 죽으면 Redis Server 또한 죽는다.

    개발 시에는 문제가 없지만, 실제 서비스라면 문제가 된다.


    우선, Server를 업데이트하고, Toolchain을 설치해야한다.

    *Toolchain - System의 Compile 환경이라고 생각하면 된다.


    sudo yum -y update

    sudo yum -y install gcc make


    그 후, Redis를 다운로드하자.

    다운로드 URL은 자신이 원하는 버젼이 있다면 확인하여 다운로드해야한다. (Download)


    sudo wget http://download.redis.io/redis-stable.tar.gz

    sudo tar xvzf redis-stable.tar.gz

    cd redis-stable

    make


    사실상 Redis 설치가 끝났다.

    Redis 작동 여부는 명령어를 통해 확인할 수 있다.


    redis-stable/src 디렉토리 기준

    redis-server

    redis-cli ping

    => PONG


    결과적으로 Redis 작동에 문제가 없지만 FULL PATH 를 통해 명령어를 실행하는 불편함이 존재한다.

    경로없이 실행하게 셋팅해보자.


    redis-stable 디렉토리 기준

    sudo cp src/redis-server /usr/local/bin/

    sudo cp src/redis-cli /usr/local/bin/


    OR


    sudo make install


    어느 경로에서도 redis-server 명령어가 실행되는 것을 볼 수 있다.

    AMI는 /usr/local/src 환경 변수 경로이다. OS마다 다르므로 다른 OS일 경우 확인하길 바란다.



    위 절차를 통해 설치 후 사용해도 무관하다.

    하지만 위에서 언급했듯이 매번 서버를 시작해야하는 문제가 발생한다.


    해결하기 위한 효율적인 방법을 통해 이어나가보자.

    먼저 디렉토리 생성과 파일들을 복사해야한다.


    redis-stable 디렉토리 기준

    sudo mkdir -p /etc/redis /var/lib/redis /var/redis/6379

    sudo cp redis.conf /etc/redis/6379.conf


    그 후, config 파일을 열어보자.


    sudo vi /etc/redis/6379.conf


    파일 안의 옵션들을 아래와 같이 수정하자.


    bind 127.0.0.1


    daemonize yes // default => no


    logfile /var/log/redis_6379.log


    dir /var/redis/6379


    수정을 했다면, init script를 설치하자.


    sudo wget https://raw.githubusercontent.com/saxenap/install-redis-amazon-linux-centos/master/redis-server


    sudo mv redis-server /etc/init.d

    sudo chmod 755 /etc/init.d/redis-server


    redis-server 를 열어보자.


    sudo vi /etc/init.d/redis-server


    그 후, config 파일 참조 경로를 변경해주면 된다.


    REDIS_CONF_FILE="/etc/redis/6379.conf"


    이제 Redis Server의 자동 실행을 위해 chkconfig 명령어를 사용한다.


    sudo chkconfig --add redis-server

    sudo chkconfig --level 345 redis-server on

    sudo service reids-server start


    결과적으로, 서버를 재시작하여도 Redis Server 또한 재시작 되는 것을 볼 수 있다.


    마지막으로 Redis는 비밀번호(암호)를 설정할 수 있다.

    관련 config 파일의 옵션을 수정해주면 된다.


    sudo vi /etc/redis/6379.conf


    requirepass는 주석 처리(#)가 되어있을 것이다.


    requirepass 1234


    수정 후 Redis Server를 재시작해주면 비밀번호가 설정이 된다.


    혹시나 문제점이 있다면 댓글을 통해 알려주면 감사하겠다.


    참고  URL

    https://redis.io/topics/quickstart

    https://medium.com/@andrewcbass/install-redis-v3-2-on-aws-ec2-instance-93259d40a3ce#.iu8eo6rno

    반응형

    댓글

Designed by Tistory.