레이블이 jenkins인 게시물을 표시합니다. 모든 게시물 표시
레이블이 jenkins인 게시물을 표시합니다. 모든 게시물 표시

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는 워커 프로세스의 실행권한

2014년 4월 5일 토요일

[jenkins] github의 일부 project만 빌드


0. 환경

macbook-pro 13” 2012 mid / 10GB
parallels9 ubuntu 12.04 LTS
tomcat7, jenkins, maven project


jenkins와 연동된 github 중 일부 프로젝트만 빌드해야 할 때

요약

pom.xml빌드 결과물의 위치를 신경쓰자


1. github 상황

아래 github에 Crawler project 폴더와 wildgoose project 폴더가 있다.
github

그리고 wildgoose project만 jenkins의 job으로 선택하고자 한다.

아래의 사진은 wildgoose 폴더의 내부이고 maven project로 생성되었다.
wildgoose project


2. job 설정

pom.xml 위치 지정

아래 그림처럼 jenkins의 job(item)을 Build a maven2/3 project 로 생성하면
jenkins maven project

이때 jeckins에게 pom.xml의 위치를 알려줘야 하는데
github의 상위 directory를 기준으로 pom.xml이 있는 상대위치를 적어주면 된다.
pom.xml location


3. 결과물 위치

일반적으로 (ubuntu 기준) 결과물은 [user home directory]/.jenkins/workspace/[job name] 이하 에 위치하며 project의 위치에 따라 약간씩 달라질 수 있다.

빌드 결과

job의 빌드를 실행 후 결과를 보면 결과물이 어디에 위치했는지를 알 수 있다.


Written with Dec7.

2014년 3월 30일 일요일

[jenkins] poll SCM


0. 환경

macbook-pro 13” 2012 mid / 10GB
parallels9 ubuntu 12.04 LTS
apache2 / tomcat7.0.52(수동설치) / java7


1. Build Periodically와 차이점

Build Periodically

  • 특별한 규칙이 필요없고 무조건 주기적으로 빌드를 실행한다. (매 10분 이라고 함)

Poll SCM

  • Cron Expression을 이용하여 주기를 지정함
  • 지정된 주기에 형상관리 툴(git)의 버전을 확인하여 변동이 있을 경우만 실행됨

참고자료


2. Cron Expression

작성중


* 참고자료


Written with Dec7.