[Redis]Redis 시작하기, 서버 설치 스크립트 사용법

DB/Redis · 2021. 6. 16. 14:34

redis사용시 새로운 서버를 생성하기 위해서 conf파일 복사하고.. 설정하고 경로 잡아주고..

이것저것 손봐주는게 여간 귀찮은 일이아니지요.

 

redis에서 기본 제공해주는 스크립트 파일을 이용해 서버를 생성하면 1분안에 서버를 뚝딱 생성할 수 있습니다.

일단 설치되어있는 redis폴더로 이동합니다.

cd /redis-6.0.8/

저는 6.0.8버전을 사용중이라 6.0.8폴더로 이동했습니다.

해당하시는 redis폴더로 이동하시면 됩니다.

 

이동하면 다양한 하위폴더가있지요?

# ls
00-RELEASENOTES  COPYING    Makefile   deps        runtest-cluster    sentinel.conf  utils
BUGS             INSTALL    README.md  redis.conf  runtest-moduleapi  src
CONTRIBUTING     MANIFESTO  TLS.md     runtest     runtest-sentinel   tests

 

여기에서 utils 폴더로 이동합니다.

# cd ./utils/
# ls
build-static-symbols.tcl  graphs             redis-sha1.rb          systemd-redis_multiple_servers@.service
cluster_fail_time.tcl     hashtable          redis_init_script      systemd-redis_server.service
corrupt_rdb.c             hyperloglog        redis_init_script.tpl  tracking_collisions.c
create-cluster            install_server.sh  releasetools           whatisdoing.sh
gen-test-certs.sh         lru                speed-regression.tcl
generate-command-help.rb  redis-copy.rb      srandmember

역시 많은 하위 파일들이 존재하는 것을 볼 수 있습니다.

이중에서 install_server.sh 스크립트를 사용할 것 입니다.

사용하기전에 주석만 살짝 볼까요?

#################################################################################
#
# Service installer for redis server, runs interactively by default.
#
# To run this script non-interactively (for automation/provisioning purposes),
# feed the variables into the script. Any missing variables will be prompted!
# Tip: Environment variables also support command substitution (see REDIS_EXECUTABLE)
#
# Example:
#
# sudo REDIS_PORT=1234 \
#                REDIS_CONFIG_FILE=/etc/redis/1234.conf \
#                REDIS_LOG_FILE=/var/log/redis_1234.log \
#                REDIS_DATA_DIR=/var/lib/redis/1234 \
#                REDIS_EXECUTABLE=`command -v redis-server` ./utils/install_server.sh
#
# This generates a redis config file and an /etc/init.d script, and installs them.
#
# /!\ This script should be run as root
#
# NOTE: This script will not work on Mac OSX.
#       It supports Debian and Ubuntu Linux.
#
################################################################################

기본적으로 대화식으로 실행되며, 자동화나 프로비저닝 목적으로 비대화형으로 실행할 시에는 스크립트에 변수를 입력하면 됩니다.

redis 설정 파일과 /etc/init.d 스크립트를 생성하고 설치하고, 스크립트는 루트로 실행되어야합니다.
그리고 이 스크립트는 Mac OSX에서 작동하지 않습니다.

 

알아둬야할 사항은 이정도면 된 것 같고, 스크립트를 이용해 서버를 빠르게 생성해볼까요?

# ./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]

친절하게 다 설명을 해주면서 스크립트가 실행이됩니다.

redis의 기본 포트는 6379번이기 때문에 그대로 엔터를 누르면 6379번 포트로 생성됩니다.

저는 이미 6379번 포트를 사용중이기에 다른 포트로 만들어야겠네요.

사용할 포트를 입력하고 엔터를 눌러 넘어가주면됩니다.

i love U 3000..ㅠ...

저는 3000번 포트를 사용할 예정이라 3000번 포트를 입력해주었습니다.

그러면 이제 conf파일, log파일, dir 패치경로등을 물어봅니다.

역시 기본값으로 하시려면 엔터로 넘어가시며되고, 수정사항이있을 시엔 따로 기입해주며됩니다.

저는 3000번 포트를 사용하는 것 외엔 수정사항이없기에 다 엔터를 눌러 넘어갔습니다.

Please select the redis port for this instance: [6379] 3000
Please select the redis config file name [/etc/redis/3000.conf]
Selected default - /etc/redis/3000.conf
Please select the redis log file name [/var/log/redis_3000.log]
Selected default - /var/log/redis_3000.log
Please select the data directory for this instance [/var/lib/redis/3000]
Selected default - /var/lib/redis/3000
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port           : 3000
Config file    : /etc/redis/3000.conf
Log file       : /var/log/redis_3000.log
Data dir       : /var/lib/redis/3000
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/3000.conf => /etc/init.d/redis_3000
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!

마지막으로 포트,파일 경로등을 정리해 보여주면서 Is this ok? 라고 친절히 물어봐줍니다.

모든것이 완벽하면 엔터를 누르면 successful! 하고 redis 서버가 생성이됩니다.

 

Starting Redis server... 후에 successful!이 아닌 Error메시지가 뜰 수도 있습니다.

*** FATAL CONFIG FILE ERROR ***
Reading the configuration file, at line 356
>>> 'rdb-del-sync-files no'
Bad directive or wrong number of arguments
ERROR: Failed starting service.... Aborting!

보통 2가지 원인입니다.

첫번째 이미 해당 포트가 사용중이거나, 두번째 위와 같은 경우입니다.

위와 같은 경우는 redis를 여러가지 버전을 사용중일때 패치에 등록된 redis-server의 버전과 실행하려는 redis서버가 호환이 되지않아서입니다. 

# ps -ef|grep redis
root      4645 22753  0 11:25 pts/0    00:00:00 grep --color=auto redis

# /redis-6.0.8/src/redis-server /etc/redis/3000.conf

# ps -ef|grep redis
root      4853     1  0 11:26 ?        00:00:00 /redis-6.0.8/src/redis-server 127.0.0.1:3000
root      4866 22753  0 11:26 pts/0    00:00:00 grep --color=auto redis

서버가 실행이 되지 않았을 뿐, 서버가 생성은 되었기 때문에 해당 버전에 맞게 서버를 실행시켜주면 서버가 잘 실행되는 것을 볼 수 있습니다.

 

+++++++++++++

스크립트가 실행되지 않고 다음과 같은 메시지만 뜰 수 있습니다.

# ./redis-6.0.8/utils/install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server

This systems seems to use systemd.
Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!

systemd 사용할 것 같으니 확인하라는 내용 같습니다.

 

스크립트를 열어서 아래 부분을 주석처리해 주면됩니다.

# vi ./redis-6.0.8/utils/install_server.sh

#check for root user
if [ "$(id -u)" -ne 0 ] ; then
       echo "You must run this script as root. Sorry!"
       exit 1
fi

#bail if this system is managed by systemd
_pid_1_exe="$(readlink -f /proc/1/exe)"
if [ "${_pid_1_exe##*/}" = systemd ]
then
       echo "This systems seems to use systemd."
       echo "Please take a look at the provided example service unit files in this directory, and adapt and install them. Sorry!"
       exit 1
fi

 

반응형