글 작성 하는 시점에서 Nginx Stable 버전은 1.6.0 버전 이다. 


1.1.x 버전을 사용하고 있었고, Nginx + WebSocket 을 사용할 수 있다는 글을 보고, 테스트 하는 도중 지원하지 않는 버전이라 테스트가 불가피 했다.

해당 글 URL (http://nodeqa.com/nodejs_ref/80) 흥미가 있다면 가보셔도 좋아요.



헉


Requirements

  • gzip module requires zlib library
  • rewrite module requires pcre library
  • ssl support requires openssl library

위 3가지 항목은 설치 전 요구되는 라이브러리다. 사전에 설치가 되어 있지 않다면, 진행을 할 수 없다.


1.  zlib library

C로 작성된 데이터 압축 라이브러리의 일종이다.

공식 사이트: http://www.zlib.net/

다운로드: http://zlib.net/zlib-1.2.8.tar.gz


tar zxvf zlib-1.2.8.tar.gz

cd zlib-1.2.8

./configure

make

sudo make install


2.  pcre library

PCRE 라이브러리, POSIX 정규식 API 지원

공식 사이트: http://www.pcre.org/

다운로드: http://sourceforge.net/projects/pcre/files/pcre/8.35/pcre-8.35.tar.gz/download


tar zxvf pcre-8.35.tar.gz

cd pcre-8.35

./configure

make

sudo make install


3. openssl library

일반적으로 Linux 설치 시 포함 되어 있다.


위 작업이 끝났다면, nginx 설치할 준비는 된 것이다.  오키



nginx Installation


다운로드: http://nginx.org/en/download.html


원하는 버전 파일을 다운로드 하도록 하자.


tar zxvf nginx-1.6.0.tar.gz

cd nginx-1.6.0

./configure

make

sudo make install


위 요구되는 라이브러리 설치만 성공적으로 끝났다면, 무사히 설치는 완료 되었을 것이다.


참고 사이트: http://wiki.nginx.org/GettingStarted





개발 시 보통 GET, POST 를 많이 사용 한다.


HTTP Method

  • GET
  • POST
  • HEAD
  • OPTIONS
  • PUT
  • DELETE
  • TRACE
  • CONNECT

사용하지 않는 아래의 Method로 서버에 대해 악용을 할 수 있기 때문에 서비스 오픈 시 보통은 차단 한다.


설정 방법


web.xml (root)

설정 파일 최하단에 아래와 같이 추가 한다.


<security-constraint> <web-resource-collection> <web-resource-name></web-resource-name> <url-pattern>/*</url-pattern> <http-method>PUT</http-method> <http-method>OPTIONS</http-method> </web-resource-collection> <auth-constraint> <role-name></role-name> </auth-constraint> </security-constraint>


테스트 방법 (telnet)

telnet 으로 tomcat 서버 에 접속 한 후 제한을 걸었던 메소드로 request 하자.


telnet 192.168.0.xxx xxxx
Trying 192.168.0.xxx...
Connected to 192.168.0.xxx.
Escape character is '^]'.
OPTIONS /
<html>
  <head>
    <title>Apache Tomcat/5.5.35 - Error report</title>
  </head>
  <body>
   // ... views
  </body>
</html>Connection closed by foreign host.


위 처럼 제한이 되었다면 성공적으로 막혔다고 볼 수 있다.


'Server,Was' 카테고리의 다른 글

Ubuntu Nginx 설치 및 테스트 하기  (0) 2014.09.21
Nginx 1.6.0 설치 하기  (0) 2014.07.17
CentOS 에서 JDK 설치 하기  (0) 2013.12.11
CentOS Gitlab 설치 시 Redis Port 변경 방법  (0) 2013.12.05
CentOS System Log 확인 하기  (0) 2013.09.06


최근에 서버 설치를 하면서 별도로 설치 하려고 하였으나, 패키지 설치 방법을 사용해 보았다.


Step 1.  OpenJDK Package 확인 하기

전체 패키지 목록에서 확인 한다.


[whitelife@whitelife library]$ yum list all | grep jdk

java-1.6.0-openjdk.x86_64           1:1.6.0.0-1.65.1.11.14.el6_4

java-1.6.0-openjdk.x86_64           1:1.6.0.0-1.66.1.13.0.el6

java-1.6.0-openjdk-demo.x86_64      1:1.6.0.0-1.66.1.13.0.el6

java-1.6.0-openjdk-devel.x86_64     1:1.6.0.0-1.66.1.13.0.el6

java-1.6.0-openjdk-javadoc.x86_64   1:1.6.0.0-1.66.1.13.0.el6

java-1.6.0-openjdk-src.x86_64       1:1.6.0.0-1.66.1.13.0.el6

java-1.7.0-openjdk.x86_64           1:1.7.0.45-2.4.3.4.el6_5

java-1.7.0-openjdk-demo.x86_64      1:1.7.0.45-2.4.3.4.el6_5

java-1.7.0-openjdk-devel.x86_64     1:1.7.0.45-2.4.3.4.el6_5

java-1.7.0-openjdk-javadoc.noarch   1:1.7.0.45-2.4.3.4.el6_5

java-1.7.0-openjdk-src.x86_64       1:1.7.0.45-2.4.3.4.el6_5

ldapjdk.x86_64                      4.18-6.el6             base

ldapjdk-javadoc.x86_64              4.18-6.el6             base


Step 2.  OpenJDK 설치 하기

java-1.6.0-openjdk, java-1.6.0-openjdk-devel 패키지를 설치 한다.


[whitelife@whitelife library]$ sudo yum install java-1.6.0-openjdk java-1.6.0-openjdk-devel

[sudo] password for game:

Loaded plugins: fastestmirror, refresh-packagekit, security

Loading mirror speeds from cached hostfile

 * PUIAS_6_computational: puias.math.ias.edu

 * base: mirror.premi.st

 * epel: mirror.premi.st

 * extras: mirror.premi.st

 * updates: mirror.premi.st

Setting up Install Process

Resolving Dependencies

--> Running transaction check

---> Package java-1.6.0-openjdk.x86_64 1:1.6.0.0-1.65.1.11.14.el6_4 will be updated

---> Package java-1.6.0-openjdk.x86_64 1:1.6.0.0-1.66.1.13.0.el6 will be an update

---> Package java-1.6.0-openjdk-devel.x86_64 1:1.6.0.0-1.66.1.13.0.el6 will be installed

--> Finished Dependency Resolution


// ...


Installed:

  java-1.6.0-openjdk-devel.x86_64 1:1.6.0.0-1.66.1.13.0.el6


Updated:

  java-1.6.0-openjdk.x86_64 1:1.6.0.0-1.66.1.13.0.el6


Complete!


Step 3.  설치 확인 하기

버전을 확인 한다.


[whitelife @whitelife library]$ javac -version

javac 1.6.0_28

[whitelife @whitelife library]$ java -version

java version "1.6.0_28"

OpenJDK Runtime Environment (IcedTea6 1.13.0pre) (rhel-1.66.1.13.0.el6-x86_64)

OpenJDK 64-Bit Server VM (build 23.25-b01, mixed mode)


직접 환경 변수 설정을 하지 않아도 되지만, 환경 변수에 대한 생각은 하고 있어야 한다.


※ 참고 사이트: http://gauryan.blogspot.kr/2011/04/centos-jdk.html


'Server,Was' 카테고리의 다른 글

Nginx 1.6.0 설치 하기  (0) 2014.07.17
Tomcat HTTP Method 제한하기  (0) 2014.04.30
CentOS Gitlab 설치 시 Redis Port 변경 방법  (0) 2013.12.05
CentOS System Log 확인 하기  (0) 2013.09.06
CentOS 타임 서버 ntp 설정 하기  (0) 2013.09.06


CentOS에서 Gitlab 설치 시 기본 포트 변경을 위해 Redis 설정 파일을 수정 하였습니다.


config/resque.yml
development: redis://localhost:00000
test: redis://localhost:00000
production: redis://localhost:00000

위와 같이 변경 후 설치 시 Redis Port 가 수정 되지 않았습니다. 


해결을 위해서는 Ruby 소스를 직접 수정 해야 합니다.


config/initializers/session_store.rb

# Be sure to restart your server when you modify this file.

config_file = Rails.root.join('config', 'resque.yml')

resque_url = if File.exists?(config_file)
                 YAML.load_file(config_file)[Rails.env]
               else
                 "redis://localhost:00000"
               end

Gitlab::Application.config.session_store(
  :redis_store, # Using the cookie_store would enable session replay attacks.
  key: '_gitlab_session',
  secure: Gitlab::Application.config.force_ssl,
  httponly: true,
  path: (Rails.application.config.relative_url_root.nil?) ? '/' : Rails.application.config.relative_url_root,
  servers: resque_url
)

3 ~ 9, 17 라인을 추가 합니다.


추가가 끝나면 변경된 포트가 적용 되는 것을 볼 수 있습니다.


※ 참고 사이트: https://github.com/gitlabhq/gitlabhq/issues/5406



공통 적으로 쓰이는 시스템 로그 가끔 확인 할 때가 필요 하다.


위치: /var/log/messages


Sep  6 11:27:52 localhost ntpd[5514]: ntpd 4.2.4p8@1.1612-o Fri Feb 22 11:23:27 UTC 2013 (1)

Sep  6 11:27:52 localhost ntpd[5515]: precision = 0.108 usec

Sep  6 11:27:52 localhost ntpd[5515]: Listening on interface #0 wildcard, 0.0.0.0#123 Disabled

Sep  6 11:27:52 localhost ntpd[5515]: Listening on interface #1 wildcard, ::#123 Disabled

Sep  6 11:27:52 localhost ntpd[5515]: Listening on interface #2 eth0, fe80::ea40:f2ff:feef:20d3#123 Enabled

Sep  6 11:27:52 localhost ntpd[5515]: Listening on interface #3 lo, ::1#123 Enabled

Sep  6 11:27:52 localhost ntpd[5515]: Listening on interface #4 lo, 127.0.0.1#123 Enabled

Sep  6 11:27:52 localhost ntpd[5515]: Listening on interface #5 eth0, 192.168.0.xx#123 Enabled

Sep  6 11:27:52 localhost ntpd[5515]: Listening on routing socket on fd #22 for interface updates

// ... ing


꾸준히 쌓이고 있다.. 날짜 별로 백업도 되는 거 같다.



 Server와 Client를 연동 할 경우 시간 오차가 발생 할 수 있다. 강제로 시간을 맞추어 보려고 하였으나, ntp 설정을 할 경우 해결이 가능 하다.


ntp 가 설치가 되어 있지 않는 경우 아래 명령어를 실행 하여 설치 하자.


[whitelife@localhost ~]$ yum install ntp


설정 하기

파일: /etc/ntp.conf

# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1

# Hosts on local network are less restricted.
restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org
#server 1.centos.pool.ntp.org
#server 2.centos.pool.ntp.org

server kr.pool.ntp.org
server time.bora.net
server time.nuri.net

#broadcast 192.168.1.255 autokey        # broadcast server
#broadcastclient                        # broadcast client
#broadcast 224.0.1.1 autokey            # multicast server
#multicastclient 224.0.1.1              # multicast client
#manycastserver 239.255.254.254         # manycast server
#manycastclient 239.255.254.254 autokey # manycast client

# Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available. 
#server 127.127.1.0     # local clock
#fudge  127.127.1.0 stratum 10  

# Enable public key cryptography.
#crypto

includefile /etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography. 
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8

# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
위와 같이 설정 파일을 수정 한다.
사설 IP 에 따라서 local network 설정을 192.168.x.x 로 설정 한다.

동기화 하기


[whitelife@localhost ~]$ sudo ntpdate -b time.bora.net

22 Dec 05:47:19 ntpdate[19906]: step time server 203.248.240.140 offset -0.030816 sec



발생 시점

Redis 시작 스크립트 사용 시


[whitelife@localhost init.d]$ sudo service redis stop

/var/run/redis_6379.pid does not exist, process is not running


위와 같이 redis 가 사용 중 인데 pid 를 찾지 못하여 스크립트가 process를 못 찾는 경우가 발생 한다.


해결 방법

설정 파일을 수정 아래와 같은 부분을 확인 하자.


설정 파일: redis.conf

# By default Redis does not run as a daemon. Use 'yes' if you need it.
# Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
daemonize yes

# When running daemonized, Redis writes a pid file in /var/run/redis.pid by
# default. You can specify a custom pid file location here.
pidfile /var/run/redis_6379.pid

# Accept connections on the specified port, default is 6379.
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379

스크립트 파일: redis

#!/bin/sh
#
# chkconfig: 2345 64 36
#
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379
EXEC=/usr/bin/redis-server
CLIEXEC=/usr/bin/redis-cli

PIDFILE=/var/run/redis.pid
CONF="/etc/redis/redis.conf"

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
        ;;
    *)
        echo "Please use start or stop as first argument"
        ;;
esac

1.  daemon 사용시 daemonize 옵션을 활성화 해야 한다.

2.  pidfile 경로를 확인 한다.


서비스 시작 하기

[whitelife@localhost init.d]$ sudo service redis start

Starting Redis server...

[whitelife@localhost init.d]$ sudo service redis stop

Stopping ...

Redis stopped


pid 파일 확인 하기

서비스가 시작 된 후 해당 경로에서 확인 하자.

[whitelife@localhost run]$ ll | grep redis

-rw-r--r--. 1 root      root         6 2013-09-05 12:03 redis.pid

[whitelife@localhost run]$ 






보통 브라우저에 403 응답이 올 경우 발생 한다.


default logs 경로:  /var/log/nginx/error.log 중...


2013/04/26 15:13:28 [error] 3390#0: *12 open() "***************" failed (13: Permission denied), client: 10.0.2.2, server: ***************, request: "GET *************** HTTP/1.1", host: "***************", referrer: "***************"
2013/04/26 15:13:28 [error] 3390#0: *7 open() "***************" failed (13: Permission denied), client: 10.0.2.2, server: ***************, request: "GET *************** HTTP/1.1", host: "***************", referrer: "***************"


권한이 없다. 


해결 방법


1.  /etc/nginx/conf.d/xxxx.conf 확인


// ...

root /home/xxxxx/work/

// ...


2.  root 그룹 확인


drwxr-xr-x 14 xxxxx 

xxxxx 4096  x월 xx xx:xx xxxxx

drwxr-xr-x 11 xxxxx xxxxx 4096  x월 xx xx:xx xxxxx

[xxxxx@localhost work]$ 


3.  /etc/nginx/nginx.conf 수정

해당 그룹으로 user 수정


#user  nginx;

user  xxxxx;

worker_processes  1;


error_log  /var/log/nginx/error.log warn;

pid        /var/run/nginx.pid;



events {

    worker_connections  1024;

}



http {

    include       /etc/nginx/mime.types;

    default_type  application/octet-stream;


    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '

                      '$status $body_bytes_sent "$http_referer" '

                      '"$http_user_agent" "$http_x_forwarded_for"';


    access_log  /var/log/nginx/access.log  main;


    sendfile        on;

    #tcp_nopush     on;


    keepalive_timeout  65;


    #gzip  on;


    include /etc/nginx/conf.d/*.conf;

}


4.  서버 재 시작



[xxxxx@localhost work]$ sudo /etc/init.d/nginx restart




+ Recent posts