2017년 4월 11일 화요일

[EtC] SVN 서버 구성(SVN Protocol)


# apt-get install subversion

# useradd -r svn
# passwd svn
새 UNIX 암호 입력:
새 UNIX 암호 재입력:
passwd: password updated successfully

# su - svn

$ mkdir -p ~/repo/web
$ svnadmin create --fs-type fsfs /home/svn/repo/web
$ vi /home/svn/repo/web/conf/svnserve.conf
----- svnserve.conf 파일 내용 // -----
[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
----- // svnserve.conf 파일 내용 -----


$ vi /home/svn/repo/web/conf/passwd
----- passwd 파일 내용 // -----
[users]
svnuser1 = P@ssw0rd
----- // passwd 파일 내용 -----

$ vi /home/svn/repo/web/conf/authz
----- authz 파일 내용 // -----
[/]
svnuser1 = rw
----- // authz 파일 내용 -----


서비스 등록
$ su -
암호:

# vi /etc/init/svnserve.conf
----- svnserve.conf 파일 내용 // -----
description "Subversion server"
start on (local-filesystems and net-device-up IFACE=lo and started udev-finish)
stop on runlevel [06]
chdir /home/svn
respawn
respawn limit 2 3600
exec /usr/bin/svnserve --foreground --daemon --config-file /home/svn/repo/web/conf/svnserve.conf --root /home/svn/
----- // svnserve.conf 파일 내용 -----
# initctl restart svnserve





2017년 4월 5일 수요일

[EtC] letsencrypt SSL 적용

- 테스트 환경
OS : Ubuntu 12.x 64Bit

https://letsencrypt.org/ 에서 무료로 발급해 주는 SSL 을 Apache 에 적용.



관리자 권한으로 아래의 명령을 실행 한다.

# apt-get install git python2.7

# mkdir SSL

# cd SSL

# git clone https://github.com/letsencrypt/letsencrypt

# cd letsencrypt

# ./letsencrypt-auto
Bootstrapping dependencies for Debian-based OSes...
무시http://ftp.daum.net trusty InRelease
기존 http://ftp.daum.net trusty-updates InRelease
기존 http://ftp.daum.net trusty-backports InRelease
... 중략 ...
Creating virtual environment...
Installing Python packages...
Installation succeeded.
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Failed to find apache2ctl in PATH: /usr/local/jdk1.7.0_80/bin:/usr/local/apache-tomcat-7.0.63/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/apache-2.4.25/bin
Certbot doesn't know how to automatically configure the web server on this system. However, it can still get a certificate for you. Please run "letsencrypt-auto certonly" to do so. You'll need to manually configure your web server to use the resulting certificate.

apache 를 패키지로 설치 하지 않고, 컴파일 하여 설치 한 경우라 그런지 PATH 에서 apache2ctl 명령을 찾을 수 없다고 한다. 

# ./letsencrypt-auto certonly

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Failed to find apache2ctl in PATH: /usr/local/jdk1.7.0_80/bin:/usr/local/apache-tomcat-7.0.63/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/apache-2.4.25/bin

아래의 물음에서는 본인의 상황에 따라 선택 하여 입력 하도록 한다.

How would you like to authenticate with the ACME CA?
-------------------------------------------------------------------------------
1: Place files in webroot directory (webroot)
2: Spin up a temporary webserver (standalone)
-------------------------------------------------------------------------------
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2


이메일 주소를 입력 한다. 해당 이메일 주소로 확인 메일이 발송 된다.
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): YOUR_EMAIL_ADDRESS

-------------------------------------------------------------------------------
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.1.1-August-1-2016.pdf. You must agree
in order to register with the ACME server at
https://acme-v01.api.letsencrypt.org/directory
-------------------------------------------------------------------------------
(A)gree/(C)ancel: A

-------------------------------------------------------------------------------
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about EFF and
our work to encrypt the web, protect its users and defend digital rights.
-------------------------------------------------------------------------------
(Y)es/(N)o: Y
Please enter in your domain name(s) (comma and/or space separated)  (Enter 'c'
to cancel): freecatz.pe.kr
Obtaining a new certificate
Performing the following challenges:
tls-sni-01 challenge for freecatz.pe.kr
Waiting for verification...
Cleaning up challenges
Generating key (2048 bits): /etc/letsencrypt/keys/0000_key-certbot.pem
Creating CSR: /etc/letsencrypt/csr/0000_csr-certbot.pem

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at
   /etc/letsencrypt/live/freecatz.pe.kr/fullchain.pem. Your cert will
   expire on 2017-07-04. To obtain a new or tweaked version of this
   certificate in the future, simply run letsencrypt-auto again. To
   non-interactively renew *all* of your certificates, run
   "letsencrypt-auto renew"
 - Your account credentials have been saved in your Certbot
   configuration directory at /etc/letsencrypt. You should make a
   secure backup of this folder now. This configuration directory will
   also contain certificates and private keys obtained by Certbot so
   making regular backups of this folder is ideal.
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le


2017-07-04 만료 된다고 나와 있다. 90일 이후에는 letsencrypt-auto renew 명령으로 연장 해야 한다. crontab 을 이용하여 매일 갱신을 시도 하여도 문제가 없다고 한다.


vi /etc/crontab
------------- /etc/crontab 파일 내용 -------------
... 중략 ...
# m h dom mon dow user  command
... 중략 ...


00 23   * * *   root    /root/letsencrypt/letsencrypt-auto renew
------------- /etc/crontab 파일 내용 -------------


# vi /usr/local/apache-2.4.25/conf/httpd.conf

LoadModule ssl_module modules/mod_ssl.so
LoadModule rewrite_module modules/mod_rewrite.so

* 위의 모듈들을 로드 할 수 있도록 주석 해제 한다.


# vi /usr/local/apache-2.4.25/conf/extra/httpd-vhosts.conf
<VirtualHost *:80>
   ServerName freecatz.pe.kr
   ServerAdmin root@freecatz.pe.kr

   RewriteEngine on
   RewriteCond %{SERVER_NAME} =freecatz.pe.kr
   RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]

</VirtualHost>

<IfModule mod_ssl.c>

        Listen 443

        SSLProtocol            ALL -SSLv2 -SSLv3
        SSLCipherSuite         ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:!aNULL:!eNULL:!EXPORT:!DES:!RC4:!3DES:!MD5:!PSK
        SSLHonorCipherOrder    on

<VirtualHost *:443>
   ServerName freecatz.pe.kr
   ServerAdmin root@freecatz.pe.kr

   <Proxy balancer://myCluster stickysession=JSESSIONID|jsessionid scolonpathdelim=On>
     BalancerMember http://127.0.0.1:8080 route=1
     BalancerMember http://127.0.0.1:8081 route=2
     BalancerMember http://127.0.0.1:8082 route=3
   </Proxy>

   ProxyRequests Off
   ProxyPass / balancer://myCluster/
   ProxyPassReverse / balancer://myCluster

   SSLEngine on
   SSLCertificateFile /etc/letsencrypt/live/freecatz.pe.kr/cert.pem
   SSLCertificateKeyFile /etc/letsencrypt/live/freecatz.pe.kr/privkey.pem
   SSLCertificateChainFile /etc/letsencrypt/live/freecatz.pe.kr/chain.pem
   SSLCACertificateFile /etc/letsencrypt/live/freecatz.pe.kr/fullchain.pem
   Header always set Strict-Transport-Security "max-age=15552000"

</VirtualHost>

</IfModule>

* 편의상 httpd-vhosts.conf 에 모든 내용을 넣었으나, 분리 하여도 된다.


https://www.ssllabs.com/ssltest 에서 SSL 테스트 진행 한다.

[EtC] Tomcat Manager 사용 가능 하도록 설정


# vi /home/tomcat/server/apache-tomcat-7.0.76_1/conf/tomcat-users.xml

<?xml version='1.0' encoding='utf-8'?>
  <role rolename="manager-gui"/>
  <role rolename="manager-script"/>
  <role rolename="manager-status"/>
  <user username="tomcat" password="P@ssw0rd1234" roles="manager-gui,manager-script,manager-status"/>
</tomcat-users>

# shutdown.sh
# startup.sh

http://<IP or Domain>/manager/html 에 브라우저로 접근 하여 확인 한다.

[EtC] Tomcat Session 끊기는 문제


- 테스트 환경 :
   OS : Ubuntu 12.x 64Bit
   WAS : Tomcat7.x 64Bit


한 서버에 여러대의 톰켓을 포트만 다르게 하여 서비스를 구동 할 경우 로그인 세션이 끊기는 현상이 발생 하게 된다. 이는 쿠키의 경우 도메인이나 IP 주소만 구분 하며, 포트 단위로 구분을 하지는 못하기 때문에 발생 하는 문제라고 한다.

이러한 경우 톰켓의 server.xml 에 sessionCookieName 속성을 추가 하여 구분 지어 준다.

<!-- 톰켓 1호기(8080포트 사용)의 server.xml -->
<Context className="org.apache.catalina.core.StandardContext"
             ... 중략 ...
             sessionCookieName="JSESSIONID1"
             ... 중략 ...
</Context>

<!-- 톰켓 2호기(8081포트 사용)의 server.xml -->
<Context className="org.apache.catalina.core.StandardContext"
             ... 중략 ...
             sessionCookieName="JSESSIONID2"
             ... 중략 ...
</Context>


참고 : http://lng1982.tistory.com/143