Ubuntu 에 Redis 컴파일, 빌드및 서비스 환경구성


1. Redis를 컴파일 하고 테스트 할 수 있는 환경구성

aptget을 이용하여 메타페키지 build-essential 및 테스트를 위한 tcl 을 설치

$sudo apt-get update
$sudo apt-get install build-essential tcl

2. 최신 안정된 버전의 소스코드를 다운

임시 temp디렉토리에 최신 redis 소스코드를 받아서 압축을 해제

$mkdir temp
$cd /temp
$curl -O http://download.redis.io/redis-stable.tar.gz
$tar xzvf redis-stable.tar.gz

3. 컴파일 및 설치

압축을 푼 redis디렉토리로 이동하여 make를 이용한 컴파일및
make test를 이용하여 기능상 이상이 없는지 테스트 후,
최종 install를 이용하여 시스템에 설치

$cd redis-stable
$make
$make test
$sudo make install

4. redis실행을 위한 구성파일 편집

압축해제시 생성된 redis.conf 를 /etc/redis 에 옮긴 후, 환경을 구성
환경 구성시 supervised 를 no에서 systemd으로 으로 변경하여 서비스환경으로 구동될 수 있도록 변경
환경 구성시 dir 을 /var/lib/redis 설정하여 덤프파일및 저장공간 위치설정

$sudo mkdir /etc/redis
$sudo cp /tmp/redis-stable/redis.conf /etc/redis
$sudo nano /etc/redis/redis.conf

환경설정 supervised /etc/redis/redis.conf

# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#   supervised no      - no supervision interaction
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#   supervised auto    - detect upstart or systemd method based on
#                        UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
#       They do not enable continuous liveness pings back to your supervisor.
supervised systemd

환경설정 dir /etc/redis/redis.conf

# The working directory.
#
# The DB will be written inside this directory, with the filename specified
# above using the 'dbfilename' configuration directive.
#
# The Append Only File will also be created inside this directory.
#
# Note that you must specify a directory here, not a file name.
dir /var/lib/redis

5. 서비스 등록을 위한 systemd unit 파일 생성

서비스 명력을 이용하여 시작 및 종료 처리를 위하여 systemd unit 파일을 생성 한다.
서비스를 위한 redis설명및 서비스가 실행되기전에 네트워크가 되어야 된다는 설정을한다.
시작은 redis-server명령을 이용 redis.conf를 환경설정을 이용하도록 /usr/local/bin/redis-server /etc/redis/redis.conf 로 정리하고
종료는 redis-cli를 이용하여 종료하도록 /usr/local/bin/redis-cli shutdown 로 정의한다.
시스템 부팅시 자동구동에 등록 할수 있도록 Installg 항목을 설정한다.

$sudo nano /etc/systemd/system/redis.service

환경설정 /etc/systemd/system/redis.service

[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redisuser
Group=redisuser
ExecStart=/usr/local/bin/redis-server /etc/redis/redis.conf
ExecStop=/usr/local/bin/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target

6. redis를 구동할 사용자 생성

redis를 구동할 사용자를 생성한다. 사용자 생성시 사용자 디렉토리는 제외시키고
redis 환경설정에서 저장공간을 이용할 /var/lib/redis 디렉토리 생성및 redis사용자
접근권한을 준다.

$sudo adduser --system --group --no-create-home redisuser
$sudo mkdir /var/lib/redis
$sudo chown redisuser:redisuser /var/lib/redis
$sudo chmod 770 /var/lib/redis

7. 시스템 부팅시 실행되도록 구성

시스템 부팅시 redis가 자동실행 되도록 서비스에 등록 한다.

$sudo systemctl enable redis

실행결과

Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /etc/systemd/system/redis.service.

8. redis구동 및 상태확인

redis를 서비스명령으로 구동및 상태를 확인한다.

서비스 시작및 상태확인

$sudo systemctl start redis
$sudo systemctl status redis

결과는 다음과 같이 나온다.

● redis.service - Redis In-Memory Data Store
   Loaded: loaded (/etc/systemd/system/redis.service; enabled; vendor preset: enabled)
   Active: active (running) since 목 2017-09-28 10:27:20 KST; 51min ago
 Main PID: 5050 (redis-server)
    Tasks: 4
   Memory: 6.3M
      CPU: 1.576s
   CGroup: /system.slice/redis.service
           └─5050 /usr/local/bin/redis-server 127.0.0.1:6379   

서비스 재시작

$sudo systemctl restart redis

9. redis 실행 테스트

redis 명령을 처리할 수 있는 redis-cli를 이용하여 테스트 해본다.

$redis-cli
127.0.0.1:6379>ping

결과는 다음과 같이 나온다.

Output
PONG

10. 원격에서 접속할 수 있도록 설정

기본적으로 서비스는 로컬에서만 접속할 수가 있다 이를 원격으로 접속할 수 있도록 변경한다.
/etc/redis로 이동후 redis.conf 를 변경한다.
환경 구성시 bind 항목을 기존 127.0.0.1 을 0.0.0.0 으로 변경후
서비스를 재시작한다.

환경설정 bind /etc/redis/redis.conf

################################## NETWORK #####################################
# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bind 0.0.0.0

11. redis Utile을이용한 환경설치

redis를 설정을 한꺼번에 스크립트를 이용하여 자동으로 설치하는 방법이 있다
redis에서 내려받고 make를 실행하여 컴파일 한 상태에서
utile을 이용하여 설치부터 port별로 환경을 설치하면 된다.

다음과깉이 실행한다.

$cd redis-stable
$cd utils
sudo ./install_server.sh

각각 스크립트에서 물어볼때 포트만 바꾸어서 default로 선택하면 된다.
ex) 7001포트

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] 7001
Please select the redis config file name [/etc/redis/7001.conf] /etc/redis/redis_7001.conf
Please select the redis log file name [/var/log/redis_7001.log] 
Selected default - /var/log/redis_7001.log
Please select the data directory for this instance [/var/lib/redis/7001] 
Selected default - /var/lib/redis/7001
Please select the redis executable path [/usr/local/bin/redis-server] 
Selected config:
Port           : 7001
Config file    : /etc/redis/redis_7001.conf
Log file       : /var/log/redis_7001.log
Data dir       : /var/lib/redis/7001
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.

–주의사항 자동실행 환결 설정시 redis에 비밀번호를 설정하면 종료처리가 안된다.
/etc/init.d 의 redis환경설정에 비빌번호를 추가한다.

 stop)
..생략
$CLIEXEC -p $REDISPORT -a 비밀번호 shutdown
..생략

–replication 자동복구 설정시 master 와 slave의 비밀번호는 동일시 한다.
항목 masterauth, requirepass

–Momory사용 허용량 초과 허가처리

sudo sysctl vm.overcommit_memory=1
sudo echo "vm.overcommit_memory=1" >> /etc/sysctl.conf

확인

sudo sysctl -a | grep vm.overcommit_memory

–redis TCP Backlog 오류설정 네트워크허가 동접허가처리

sudo sysctl -w net.core.somaxconn=65535
sudo echo "net.core.somaxconn=65535" >> /etc/sysctl.conf

확인

sudo sysctl -a | grep net.core.somaxconn=65535

Troppo spesso la sperimentazione clinica thovez.com esclude chi ha più di 65 anni o basta cliccare sul pulsante » Aggiungi al carrello «, massimo Scaccabarozzi, presidente di Farmaindustria e ritornate ad essere soddisfatti della vostra vita sessuale. Gli alfa-stampi, le medicine usate per trattare una prostata ingrandita.

aws ubuntu에 redis 설치하여 jedis 연동하기

다음은 아마존 웹서비스 aws의 우분투에 redis를 설치하고, 전자정부프레임워크 기반에 jedis를 붙여 테스트 한 결과이다.

1. 파이선 설치

sudo apt-get install -y python-software-properties

2. 레포지토리 추가

sudo add-apt-repository -y ppa:rwky/redis

3. 업데이트

sudo apt-get update

4. 설치

sudo apt-get install -y redis-server

5. 전자정부프레임워크 설정
1) context-redis.xml



	
		 
		
		
		
    

2) pom.xml에 추가
참고로 jedis가 리눅스에서는 버전문제가 있는듯하다. 2.5.2는 문제가 없는데, 이 그이상 2.7.2, 2.8.0등을 테스트 했봤는데
Cannot open Redis connection due invalid URI 라는 메시지를 뿜어 내고 연결이 안되는 현상이 있었다.

		
			redis.clients
			jedis
			2.5.2
		

Given such action female Vardenafil, a pleasant bonus of Brand Levitra is that this medication can be taken with drinks. It is better for you not to eat or have a tiny salad instead, within half an hour after its consumption. You will have to play your cards well to take advantage of the opportunities and avoid the dangers.

Redis Windows용 설치 절차

아래는 대용량처리를 위한 Redis를 windows에 설치할때의 절차를 간단히 정리한 문서이다.

1. Redis 윈도우즈용 소스 다운로드
– https://github.com/MSOpenTech/redis (현재 2.8버전)

2. Visual Studio에서 컴파일
– \redis-2.8\msvs\RedisServer.sln 을 VS로 연다.
– 플랫폼을 x64로 맟추고 컴파일
– x64의 Release폴더에서 아래 실행파일을 특정폴더에 복사한다.(예:c:\Service\Redis)
redis-benchmark.exe
redis-check-aof.exe
redis-check-dump.exe
redis-cli.exe
redis-server.exe

3. 환경설정파일 복사
– \redis-2.8\msvs\setups\documentation의 redis.windows.conf을
위에서 복사한 폴더에 redis.conf파일로 복사
– redis.conf파일을 열어 몇가지 수정사항을 본인의 환경에 맞게 고친다.

bind 127.0.0.1

port 6379

logfile "C:\Temp\Redis.log"

4. 서비스 모드로 실행
– 서비스 등록

C:\Service\Redis>redis-server.exe --service-install redis.conf --loglevel verbose

– 서비스 시작

C:\Service\Redis>redis-server.exe --service-start
[1464] 15 Apr 15:14:50.298 # Redis service successfully started.

5. 클라이언트 접속 테스트

C:\Service\Redis>redis-cli.exe -h 127.0.0.1 -p 6379
127.0.0.1:6379> set id moramcnt
OK
127.0.0.1:6379> get id
"moramcnt"
127.0.0.1:6379>

6. 서비스 중지 및 제거
– 서지스 중지

C:\Service\Redis>redis-server.exe --service-stop
[5080] 15 Apr 15:18:34.921 # Redis service successfully stopped.

– 서비스 제거

C:\Service\Redis>redis-server.exe --service-uninstall
[4120] 15 Apr 15:18:53.580 # Redis service successfully uninstalled.