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.

aws ubuntu에 웹개발환경 구축하기

다음은 아마존 웹서비스 AWS(Amazon Web Services)에 전자정부 프레임워크로 된 프로젝트를 올려보는것 까지 하여 테스트한결과이다.

1. JDK 설치
1) Oracle Java(JDK)8을 설치하기 위해 webupd8team 레포지터리 추가

sudo add-apt-repository ppa:webupd8team/java

2) 업데이트

sudo apt-get update

3) 설치
여기에서는 JDK 8을 설치하기로 함.

sudo apt-get install oracle-java8-installer

4) JDK 환경 변수 추가
vi에디터로 profile파일에 JAVA_HOME, PATH등을 export해도 되지만,
아래와 같이 명령을 입력하면 자동으로 환경변수를 추가해 준다.

sudo apt-get install oracle-java8-set-default

5) 환경변수 확인

sudo su - root -c 'printenv'

2. 아파치(Apache) 설치
1) 설치

sudo apt-get install apache2

2) 서비스 시작

sudo service apache2 start

3) IP로 웹이 뜨는지 확인
안뜨면 AWS의 관리 콘솔의 Security Group(방화벽)에서 80포트를 오픈한다.

3. 톰캣(Tomcat) 설치

1) 설치

sudo apt-get install tomcat7

– 설치중 아래와 같이 JDK가 없다고 나온다면 JDK 8을 인식못한것이므로

Setting up libcommons-collections3-java (3.2.1-6) ...
Setting up libcommons-pool-java (1.6-2) ...
Setting up libcommons-dbcp-java (1.4-3ubuntu1) ...
Setting up libecj-java (3.9.0-1) ...
Setting up libgeronimo-jta-1.1-spec-java (1.1.1-3ubuntu1) ...
Setting up libservlet3.0-java (7.0.52-1ubuntu0.3) ...
Setting up libtomcat7-java (7.0.52-1ubuntu0.3) ...
Setting up tomcat7-common (7.0.52-1ubuntu0.3) ...
Setting up tomcat7 (7.0.52-1ubuntu0.3) ...

Creating config file /etc/default/tomcat7 with new version
Adding system user `tomcat7' (UID 106) ...
Adding new user `tomcat7' (UID 106) with group `tomcat7' ...
Not creating home directory `/usr/share/tomcat7'.

Creating config file /etc/logrotate.d/tomcat7 with new version
 * no JDK or JRE found - please set JAVA_HOME
invoke-rc.d: initscript tomcat7, action "start" failed.
Setting up authbind (2.1.1) ...
Processing triggers for ureadahead (0.100.0-16) ...

sudo vi /etc/init.d/tomcat7 로 파일을 열어

JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-7-oracle"

아래와같이 /usr/lib/jvm/java-8-oracle 을 추가한다.

JDK_DIRS="/usr/lib/jvm/default-java ${OPENJDKS} /usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-7-oracle /usr/lib/jvm/java-8-oracle"

2) 서비스 시작

sudo service tomcat7 start

3) 서비스 확인
http://접속아이피:8080/으로 뜨는지 확인, 이때도 마찬가지로 안뜬다면
AWS의 관리 콘솔의 Security Group(방화벽)에서 8080포트를 오픈했는지 확인해야 한다.

4. libapache2-mod-jk 설치
아파치와 톰캣 연동을 위한 mod-jk를 설치한다.
1) 설치

sudo apt-get install libapache2-mod-jk

2) 설정

sudo vi /etc/libapache2-mod-jk/workers.properties

아래 부분을 설치 경로에 맞게 수정

workers.tomcat_home=/usr/share/tomcat7
workers.java_home=/usr/lib/jvm/java-8-oracle

5. 톰캣 설정
1) server.xml 수정

sudo vi /etc/tomcat7/server.xml

AJP를 이용하기 위해 아래 주석 해제

    
    
    
    

6. AJP 모듈 활성화

sudo a2enmod proxy_ajp 
sudo service apache2 restart

7. 아파치 설정
000-default.conf 파일을 열어 수정한다.

 sudo vi /etc/apache2/sites-available/000-default.conf

하단에 아래와 같이 추가한다.

JkMount /* ajp13_worker

8. 서비스 재시작

sudo service tomcat7 restart
sudo service apache2 restart