2018년 6월 30일 토요일

Wildcard SSL 설정

목표

  • letsencrypt wildcard SSL 설정

환경

  • CentOS7
  • Nnginx 1.13.8
  • DigitalOcean Droplet

예상 결과

  • www.{domain}.com 및 {domain}.com 호출시 SSL 접속


Certbot으로 인증서 발급

command

sudo certbot certonly \
--server https://acme-v02.api.letsencrypt.org/directory \
--manual \
--preferred-challenges dns \
-d *.{domain}.com \
-d {domain}.com \

  • wildcard 도메인 뿐 아니라 서브도메인이 없는 경우가 필요하다면 함께 추가

Issuing

Please deploy a DNS TXT record under the name
_acme-challenge.{domain}.com with the following value:

{value}

Before continuing, verify the record is deployed.

  • 위 값을 _acme-challenge 도메인의 DNS TXT 타입으로 등록
  • DNS record가 등록되어야만 다음단계 진행 가능
    • DNS Record 등록 부분 확인

성공시

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/{domain}.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/{domain}.com/privkey.pem
   Your cert will expire on 2018-09-28. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot
   again. To non-interactively renew *all* of your certificates, run
   "certbot renew"
 - 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


DNS Record 등록

  • TXT
    • _acme-challenge.thebudding.com => 위에서 제시한 값
    • 확인방법
      • nslookup -q=TXT {domain}
  • CNAME
    • wildcard 도메인을 redirect 하기 위함
    • *.{domain}.com => {domain}.com
  • NS / A


Nginx 설정

  • server {
        listen       80;
        server_name  ~.;
        return 301 https://$host$request_uri;
    }
    
    server {
        server_name  ~.;
        listen 443;
        
        ssl                  on;
        ssl_certificate      /etc/letsencrypt/live/{domain}/fullchain.pem;
        ssl_certificate_key  /etc/letsencrypt/live/{domain}/privkey.pem;
        ssl_session_cache shared:SSL:1m;
        ssl_session_timeout  10m;
        ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
        ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+ED';
        ssl_prefer_server_ciphers   on;
    
        location / {
         root   html;
         index  index.html index.htm;
      }
    }

참고자료

  • https://www.netmanias.com/ko/post/blog/5365/dns-network-protocol/three-types-of-dns-message-a-ns-and-cname
  • https://levelup.gitconnected.com/how-to-get-certbot-wildcard-certificates-3d25618a81e0
  • https://www.lesstif.com/pages/viewpage.action?pageId=27984443
  • https://certbot.eff.org/lets-encrypt/centosrhel7-nginx
  • https://blog.perfectacle.com/2017/10/05/letsencrypt-with-certbot-feat-aws/




2018년 2월 14일 수요일

Vue js 스터디

목표


  • vue js 로 프로젝트를 할 수 있을 정도 지식 획득
  • 스터디 책: vue.js 이정도는 알아야지 / 김지환.이선협 공저 / 비제이퍼블릭
  • webstorm

기반 프로젝트 생성

  • 참고
    • https://medium.com/codingthesmartway-com-blog/vue-js-2-quickstart-tutorial-2017-246195cfbdd2
    • https://medium.com/witinweb/vue-cli-%EB%A1%9C-vue-js-%EC%8B%9C%EC%9E%91%ED%95%98%EA%B8%B0-browserify-webpack-22582202cd52
    • https://kr.vuejs.org/v2/guide/installation.html
  • Command
    • npm install -g vue-cli
    • vue init webpack vueapp01
    • cd vueapp01
    • npm install
    • npm run dev
    • npm run build


2018년 1월 27일 토요일

Server Setting

목표

  • 서버 설정방법을 자꾸 잊어버려 기록을 위해 정리 시작
  • 목표를 세분화하고 목적을 해결하는 방식으로 진행
  • 명령형으로 작성하고 내용을 시간순서로 추가하되 되도록 수정하지 않음
    • 결과가 잘못될 수 있으니, 꼭 마지막을 확인 바람

환경

  • DigitalOcean droplet (2 vCPUs, 4GB, 80GB ssd, $20/mo)
  • CentOS 7.4 x64

설정 목표

  1. admin, adminsu 등록
  2. nginx 컴파일
  3. jenkins 설치
  4. gitlab gitpush 등록
  5. /resource path에 static 연동
  6. static build ci 적용
  7. /index.html에 hello world 노출

서버 생성

  • 2 vCPUs, 4GB, 80GB ssd, $20/mo, Singapore
  • CentOS 7.4 x64
  • root 로그인 (pw 메일로 전송받음) 후 비밀번호 변경
  • sudo yum update -y
    • prm, yum 차이
      • http://blackub.tistory.com/15

CentOS7

  • systemd 이해
    • http://linux.systemv.pe.kr/centos-7-systemd-%EC%9D%B4%ED%95%B4%ED%95%98%EA%B8%B0/
  • centos6와 차이
    • http://signpen.kr/sp_view.php?cat=D02&fid=155&sk=LHDS

admin, adminsu 계정 등록

  • 목적
    • admin은 일반 사용계정
    • adminsu는 sudo 권한 제공
  • 참고
    • http://kit2013.tistory.com/187
    • http://blog.freezner.com/archives/1094
      • adduser, useradd 차이는 debian 계열 linux만 차이가 있음
  • adduser admin, passwd admin
    • 일반사용자 su 권한 제한
      • http://klero.tistory.com/entry/root-%EA%B3%84%EC%A0%95-su-%EC%A0%9C%ED%95%9C
    • vi /etc/pam.d/su
  • adduser adminsu, passwd adminsu
    • su사용자 sudoer 권한 제공
      • https://slobell.com/blogs/40
    • usermod -aG wheel adminsu 
      • adminsu에 wheel 그룹 추가
    • /etc/sudoers 
      • ## Same thing without a password 
        %wheel ALL=(ALL) NOPASSWD: ALL  // 주석제거

Nginx 컴파일

  • 참고
    • https://www.vultr.com/docs/how-to-compile-nginx-from-source-on-centos-7
  • 준비, 추가패키지, 의존 패키지 설치
    • sudo yum groupinstall -y 'Development Tools'
    • sudo yum install -y vim
    • sudo yum install -y epel-release
    • sudo yum install -y wget
  • nginx 다운 및 압축해제
    • wget http://nginx.org/download/nginx-1.13.8.tar.gz
    • tar -zxvf nginx-1.13.8.tar.gz
  • nginx package 다운
    • pcre
      • wget https://ftp.pcre.org/pub/pcre/pcre-8.41.tar.gz
      • tar xzvf pcre-8.41.tar.gz
    • zlib
      • wget https://www.zlib.net/zlib-1.2.11.tar.gz
      • tar xzvf zlib-1.2.11.tar.gz
    • openssl
      • wget https://www.openssl.org/source/openssl-1.1.0g.tar.gz
      • tar xzvf openssl-1.1.0g.tar.gz
  • nginx configuration
    • ./configure --prefix=/etc/nginx \
                  --sbin-path=/usr/sbin/nginx \
                  --modules-path=/usr/lib64/nginx/modules \
                  --conf-path=/etc/nginx/nginx.conf \
                  --error-log-path=/var/log/nginx/error.log \
                  --pid-path=/var/run/nginx.pid \
                  --lock-path=/var/run/nginx.lock \
                  --user=nginx \
                  --group=nginx \
                  --build=CentOS \
                  --builddir=nginx-1.13.8 \
                  --with-select_module \
                  --with-poll_module \
                  --with-threads \
                  --with-file-aio \
                  --with-http_ssl_module \
                  --with-http_v2_module \
                  --with-http_realip_module \
                  --with-http_addition_module \
                  --with-http_xslt_module=dynamic \
                  --with-http_image_filter_module=dynamic \
                  --with-http_geoip_module=dynamic \
                  --with-http_sub_module \
                  --with-http_dav_module \
                  --with-http_flv_module \
                  --with-http_mp4_module \
                  --with-http_gunzip_module \
                  --with-http_gzip_static_module \
                  --with-http_auth_request_module \
                  --with-http_random_index_module \
                  --with-http_secure_link_module \
                  --with-http_degradation_module \
                  --with-http_slice_module \
                  --with-http_stub_status_module \
                  --http-log-path=/var/log/nginx/access.log \
                  --http-client-body-temp-path=/var/cache/nginx/client_temp \
                  --http-proxy-temp-path=/var/cache/nginx/proxy_temp \
                  --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
                  --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
                  --http-scgi-temp-path=/var/cache/nginx/scgi_temp \
                  --with-mail=dynamic \
                  --with-mail_ssl_module \
                  --with-stream=dynamic \
                  --with-stream_ssl_module \
                  --with-stream_realip_module \
                  --with-stream_geoip_module=dynamic \
                  --with-stream_ssl_preread_module \
                  --with-compat \
                  --with-pcre=../packages/pcre-8.41 \
                  --with-pcre-jit \
                  --with-zlib=../packages/zlib-1.2.11 \
                  --with-openssl=../packages/openssl-1.1.0g \
                  --with-openssl-opt=no-nextprotoneg \
                  --with-debug
    • nginx modules 링크
      • sudo ln -s /usr/lib64/nginx/modules /etc/nginx/modules
    • nginx system 유저 및 그룹 등록
      • sudo useradd --system --home /var/cache/nginx --shell /sbin/nologin --comment "nginx user" --user-group nginx
    • nginx-t
      • 실패시 sudo mkdir -p /var/cache/nginx 생성후 다시 테스트
    • nginx server 시작 및 활성화
      • sudo systemctl start nginx.service
      • sudo systemctl enable nginx.service
      • sudo systemctl is-enabled nginx.service
      • sudo systemctl status nginx.service
    • 초기 파일 삭제
      • sudo rm /etc/nginx/koi-utf /etc/nginx/koi-win /etc/nginx/win-utf
    • nginx syntax highlighting
      • mkdir ~/.vim/
      • sudo cp -r ~/nginx-1.13.8/contrib/vim/* ~/.vim/
      • (cp -R /home/admin/apps/nginx-1.13.8/contrib/vim/* /home/adminsu/.vim/)

Jenkins 설치

  • JDK 설치가 먼저 필요하단걸 깜박함-_-

JDK 설치

  • 참조
    • https://tecadmin.net/install-java-8-on-centos-rhel-and-fedora/#
  • JDK 다운
    • wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/8u161-b12/2f38c3b165be4555a1fa6e98c45e0808/jdk-8u161-linux-x64.tar.gz"
  • /opt 로 이동 후 압축하제
    • cd /opt
    • tar xzf jdk-8u161-linux-x64.tar.gz
  • alternatives 명령어
    • https://skyoo2003.github.io/post/2017/03/17/what-is-alternatives-command
    • https://donghwi-kim.github.io/jekyll/update/2015/04/17/update-alternatives.html
  • alternatives 명령어로 심볼릭 링크 생성
    • alternatives --install /usr/bin/java java /opt/jdk1.8.0_161/bin/java 2
    • alternatives --config java
    • alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_161/bin/jar 2
    • alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_161/bin/javac 2
    • alternatives --set jar /opt/jdk1.8.0_161/bin/jar
    • alternatives --set javac /opt/jdk1.8.0_161/bin/javac
  • 확인
    • java -version

Tomcat 멀티 인스턴스 설치

  • 멀티 인스턴스를 시도하는 특별한 이유는 없음
    • 그냥, 예전 기억을 되살리기 위해 시도함
  • Jenkins용 서버와 SpringBatch용 서버로 활용할 예정
    • 추후 서비스가 커지는 경우 외부 장비로 이동할 예정 (그럴일이 없을수도 있음)
  • 참고
    • https://cocagolau.blogspot.kr/2014/03/blog-post_4571.html
  • 하려다가, 뭐 귀찮게 할 필요가 있나란 생각이 들어 포기함

Tomcat 설치

  • 톰켓8을 다운받으려 했으나, 9.0.4 버전이 나옴. 잠시 고민했지만, 8버전을 다운받기로 함
  • 참고
    • https://gs.saro.me/#!m=elec&jn=768
  • 다운
    • wget http://apache.tt.co.kr/tomcat/tomcat-8/v8.5.27/bin/apache-tomcat-8.5.27.tar.gz
  • 설정 변경
    • 포트번호 수정, ajp 포트 주석처리
  • 서버 실행 후 서버 접근
    • 방화벽에 막혀 있으므로 해당포트 방화벽 제거 (digitalocean)
    • 그래도 ERR_CONNECTION_REFUSED 발생
  • SeLinux
    • https://ko.wikipedia.org/wiki/%EB%B3%B4%EC%95%88_%EA%B0%95%ED%99%94_%EB%A6%AC%EB%88%85%EC%8A%A4
    • https://lesstif.gitbooks.io/web-service-hardening/content/selinux.html
    • http://navs.tistory.com/entry/SELinux-%EC%99%80-httpd-%ED%8F%AC%ED%8A%B8-%EB%B0%94%EC%9D%B8%EB%94%A9-%ED%95%98%EA%B8%B0
  • 설정된 포트를 SeLinux에 추가
    • semanage port -l | grep http
    • semanage port -a -t http_port_t -p tcp 포트번호
  • .. 서버는 뜨지만, 접근이 안됨. 이유를 모르겠음. 좀더 찾아보겠음 바로 다시 됨. 이놈 세계는 알수 없다.
  • Tomcat context 설정
    • https://ohjongsung.io/2017/06/24/tomcat-8%EC%97%90-root%EB%A1%9C-%EA%B2%8C%EC%8B%9C%ED%95%98%EA%B8%B0

Jenkins 설치

  • 다운로드
    • wget http://mirrors.jenkins.io/war/2.103/jenkins.war
  • 톰켓 배포 후 시작
  • 설정에서 역방향 프록시 설정이 잘못되었다고 나올 때
    • http://www.comsvc.kr/xe/comsvc_tip02/3846
    • sudo getsebool -a
    • sudo setsebool -P httpd_can_network_connect on
    • https://www.lesstif.com/pages/viewpage.action?pageId=22053077
    • '해제' 버튼을 눌러서 끝냄.

Gitlab push event 적용

  • 참고
    • http://yg-park.github.io/2015/03/10/gitlab-jenkins/
    • https://github.com/jenkinsci/gitlab-plugin/issues/375
  • 설치목록
    • Credentials Plugin, GIT plugin, GitLab Plugin, embeddable-build-status
  • 내용
    • jenkins 설정에서 secret key 꼭 설정

Nginx 와 Jenkins 연동


  • 목표
    • jenkins 의 endpoint를 nginx를 사용하도록 수정
  • 참조
    • https://nginx.org/en/docs/
    • https://www.nginx.com/resources/wiki/start/topics/examples/full/
    • https://www.digitalocean.com/community/tutorials/understanding-the-nginx-configuration-file-structure-and-configuration-contexts
    • https://blog.lael.be/demo-generator/nginx/default.conf.php
    • http://nginx.org/en/docs/example.html
    • https://www.digitalocean.com/community/tutorials/understanding-nginx-http-proxying-load-balancing-buffering-and-caching
    • http://nginx.org/en/docs/http/server_names.html
    • http://nginx.org/en/docs/http/request_processing.html
    • http://sarc.io/index.php/nginx/61-nginx-nginx-conf
    • https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms

static build ci 적용

  • 목포
    • jenkins 2.0 파이프라인 기능을 사용하여 배포를 자동화 설정
  • 참고
    • http://kingbbode.tistory.com/42
    • https://jenkins.io/doc/book/pipeline/getting-started/
    • https://jenkins.io/doc/book/pipeline/syntax/

Index.html을 root로 변경

  • 참고
    • https://www.nginx.com/resources/admin-guide/serving-static-content/
  • Nginx conf중 user
    • https://opentutorials.org/module/384/4530
    • 마스터 프로세스는 root로
    • conf의 user는 워커 프로세스의 실행권한