본문 바로가기

TroubleShooting/Etc

memcached 설치 / redis 설치 on CentOS

728x90

Memcached


# yum install memcached


memcached 설정 확인(포트 또는 cachesize 변경)

# vi /etc/sysconfig/memcached


시작

# systemctl start  memcached


서비스 시작 등록

# systemctl enable memcached



Redis


- 설치(최신 버전을 다운)

# tar xvfz redis-3.2.6.tar.gz

# cd redis-3.2.6

# make; make install

- redis 설정 파일 생성(redis.conf(또는 6379.conf) 는 install_server.sh 스크립트에서 자동 생성)

# cd redis-3.2.6/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!



- protected mode 변경시 redis.conf 수정

# vi /etc/redis/6379.conf

...

bind 127.0.0.1 -> 앞에 # 추가해서 코멘트 처리


protected-mode no -> 추가해서 protected-mode 를 no 로 설정


- redis 서비스 등록(old 방식 : chkconfig 이용)


위의 install_server.sh 을 실행하면 아래 내용을 가진 스크립트 파일이 /etc/init.d 에 생성된 것을 확인할 수 있다.

#!/bin/sh


EXEC=/usr/bin/redis-server

CLIEXEC=/usr/bin/redis-cli

PIDFILE=/var/run/redis_6379.pid

CONF="/etc/redis.conf"

REDISPORT="6379"

###############

# SysV Init Information

# chkconfig: - 58 74

# description: redis_6379 is the redis daemon.

### BEGIN INIT INFO

# Provides: redis_6379

# Required-Start: $network $local_fs $remote_fs

# Required-Stop: $network $local_fs $remote_fs

# Default-Start: 2 3 4 5

# Default-Stop: 0 1 6

# Should-Start: $syslog $named

# Should-Stop: $syslog $named

# Short-Description: start and stop redis_6379

# Description: Redis daemon

### END INIT INFO



case "$1" in

    start)

        if [ -f $PIDFILE ]

        then

            echo "$PIDFILE exists, process is already running or crashed"

        else

            echo "Starting Redis server..."

            $EXEC $CONF

        fi

        ;;

    stop)

        if [ ! -f $PIDFILE ]

        then

            echo "$PIDFILE does not exist, process is not running"

        else

            PID=$(cat $PIDFILE)

            echo "Stopping ..."

            $CLIEXEC -p $REDISPORT shutdown

            while [ -x /proc/${PID} ]

            do

                echo "Waiting for Redis to shutdown ..."

                sleep 1

            done

            echo "Redis stopped"

        fi

        ;;

    status)

        PID=$(cat $PIDFILE)

        if [ ! -x /proc/${PID} ]

        then

            echo 'Redis is not running'

        else

            echo "Redis is running ($PID)"

        fi

        ;;

    restart)

        $0 stop

        $0 start

        ;;

    *)

        echo "Please use start, stop, restart or status as first argument"

        ;;

esac


- 서비스 등록 및 확인

# cd /etc/init.d

# chkconfig --add redis_6379


# chkconfig --list


알림: 이 출력 결과에서는 SysV 서비스만을 보여주며 기존의 systemd 서비스는

포함되어 있지 않습니다. SysV 설정 데이터는 기존의 systemd  설정에 의해

덮어쓰여질 수 있습니다.


      'systemctl list-unit-files'를 사용하여 systemd 서비스를 나열하실 수 있습니다.

       특정 대상에 활성화된 서비스를 확인하려면

       'systemctl list-dependencies [target]'을 사용하십시오.


netconsole      0:해제  1:해제  2:해제  3:해제  4:해제  5:해제  6:해제

network         0:해제  1:해제  2:활성  3:활성  4:활성  5:활성  6:해제

redis_6379      0:해제  1:해제  2:활성  3:활성  4:활성  5:활성  6:해제