뭐든 즐기면서 ;)

Jenkins install with tomcat/ Jenkins 설치 with tomcat 본문

서버/JENKINS

Jenkins install with tomcat/ Jenkins 설치 with tomcat

Tada.*+ 2022. 5. 17. 11:40
728x90

Jenkins에 대한 간단한 설명

  • CI/CD 툴입니다.
  • tomcat에 의해 구동되어 집니다. 즉, war파일로 패키징되어 있는 application입니다.
  • jenkins는 tomcat 8 또는 11버전에서만 구동가능합니다.

Jenkins를 설치하는 2가지 방법

jenkins를 설치하는 방법은 2가지가 있으며, 여기서는 2번 방법을 이용한 설치를 설명하고자 합니다.

1번 방법의 경우 custom방식이 많이 나와 있지 않으며, 2번 방법을 쓸 경우 tomcat을 통해 설정하기 때문에 좀 더 익숙한 방식으로 custom을 할 수가 있습니다.

  1. package 명령어 yum을 이용하여 서버에 설치하는 방법.
  2. jenkins.war파일을 tomcat에 배포하여 직접적으로 설치하는 방법.

설치 환경

  • CentOS
  • tomcat 8.5 ( 기본 8080포트가 아닌 10000 포트를 사용하고, context path /jenkins로 설정할 것입니다. 그리고 기존 ssl 설정이 되어 있는 nginx와 연결할 예정입니다. )
  • jenkins 2.347
  • proxy server nginx ( context path /jenkins 와 10000 포트를 사용하여 연결합니다. )

설치 진행

1. jenkins war 파일 다운로드

2. tomcat 8 ver 다운로드

3. linux 서버에 톰캣 파일을 업로드 합니다.

  • 업로드 후 tar 압축을 풀어 톰캣 설정을 먼저 진행합니다. 
  • CATALINA_HOME = /home/sample/tomcat-jenkins
  • vim /home/sample/tomcat-jenkins/conf/server.xml 파일 수정 ( 아래 리스트는 수정 부분 중 중요한 부분만 따로 정리한 것입니다. )
    • <Connector port="10000" protocol="HTTP/1.1" URIEncoding="UTF-8" ... />
    • <Context path="/jenkins" docBase="/home/sample/tomcat-jenkins/webapps/ROOT" ... />
# port 변경
<Connector port="10000" protocol="HTTP/1.1"
               connectionTimeout="20000"
               URIEncoding="UTF-8"
               redirectPort="8443" />


# path와 docBase 변경
<Host name="localhost"  appBase="webapps"
            unpackWARs="true" autoDeploy="true">

    <Context path="/jenkins" docBase="/home/sample/tomcat-jenkins/webapps/ROOT" reloadable="false" />

    <!-- SingleSignOn valve, share authentication between web applications
         Documentation at: /docs/config/valve.html -->
    <!--
    <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
    -->

    <!-- Access log processes all example.
         Documentation at: /docs/config/valve.html
         Note: The pattern used is equivalent to using pattern="common" -->
    <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
           prefix="localhost_access_log" suffix=".txt"
           pattern="%h %l %u %t &quot;%r&quot; %s %b" />

</Host>

 

4. Jenkins.war를 배포합니다.

  • tomcat에서 설정한 경로 /home/sample/tomcat-jenkins/webapps에 jenkins.war 파일을 ROOT.war파일로 변경하여 올려줍니다.
  • /home/sample/tomcat-jenkins/bin 경로에서 ./startup.sh 를 실행 시킵니다.

jenkins 설치까지는 여기서 끝이 납니다. 다만, 개발서버에 설치를 하는 과정이기 때문에 직접적으로 http://ip주소:10000/jenkins로 접근을 하려 한다면 방화벽 등의 문제로 접근이 되지 않을 것입니다. 이 포스팅에서는 이미 nginx설정이 되어 있는 서버에 jenkins를 연결하여 사용할 것이기 때문에 방화벽 설정 단계는 생략할 것이며, 바로 nginx와의 연결을 설명하도록 하겠습니다.


5. NginX 설정

  • vim /etc/nginx/conf/nginx.conf 파일 수정 ( 아래 리스트는 수정 부분 중 중요한 부분만 따로 정리한 것입니다. )
  • upstream jenkins { ... server 127.0.0.1:10000 }
  • server { ... server_name  domain.com;  location /jenkins { proxy_pass http://jenkins; }  }
    • /jenkins는 context path로 톰캣에서 설정한  path="/jenkins"와도 일치해야 합니다.
  • nginx.conf를 수정하였으니 service nginx reload 명령어를 통하여 수정된 것을 적용시켜 줍니다.
http {
    
    ...

    upstream tomcat {
        ip_hash;
        server 127.0.0.1:8080;
    }
    upstream tomcat_renewal {
        ip_hash;
        server 127.0.0.1:9099;
    }
    upstream jenkins {
        ip_hash;
        server 127.0.0.1:10000;
    }
    
    # http 80포트로 접근할 경우 return 301 response status 리다이렉트 https://url
    server {
        listen          80;
        server_name     domain.com;
        return          301 https://$host$request_uri;
    }
    
    
    
    server {
        # listen       80 default_server;
        # listen       [::]:80 default_server;
        server_name  domain.com;
        root         /usr/share/nginx/html;

        # ssl 설정
        listen 443 ssl;
        listen [::]:443 ssl;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;
        
        # 인증서 설정
        ssl_certificate         /etc/pki/tls/certs/domain.crt;
        ssl_certificate_key     /etc/pki/tls/private/domain.key;

        ssl_session_cache shared:SSL:10m;
        ssl_session_timeout     10m;
        ssl_ciphers HIGH:!aNULL:!MD5;
        ssl_prefer_server_ciphers on;
        
        location /builder {
                proxy_set_header        Host $http_host;
                proxy_set_header        X-Real-IP $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header        X-Forwarded-Proto $scheme;
                proxy_set_header        X-NginX-Proxy true;

                proxy_pass http://tomcat;
                proxy_redirect off;
                charset utf-8;
        }
        
        location /renewal {
                proxy_set_header        Host $http_host;
                proxy_set_header        X-Real-IP $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header        X-Forwarded-Proto $scheme;
                proxy_set_header        X-NginX-Proxy true;

                proxy_pass http://tomcat_renewal;
                proxy_redirect off;
                charset utf-8;
        }

        location /jenkins {
                proxy_set_header        Host $http_host;
                proxy_set_header        X-Real-IP $remote_addr;
                proxy_set_header        X-Forwarded-For $proxy_add_x_forwarded_for;
                proxy_set_header        X-Forwarded-Proto $scheme;
                proxy_set_header        X-NginX-Proxy true;

                proxy_pass http://jenkins;
                proxy_redirect off;
                charset utf-8;
        }
        
    } # //server
        
        
}

 

6. 설치 확인 후 jenkins 설정

  • 주소창에 입력 domain.com/jenkins
  • 화면에 보이는 경로의 파일을 cat 명령어를 통하여 확인하면, Administrator password 내용이 보일 것입니다.
  • 해당 내용을 복사하여 입력해 주세요.
[root@ip:/etc/nginx]cat /home/minds/.jenkins/secrets/initialAdminPassword
f4a480498cd34504951sfsdfwerdf2

  • 기본 도구 설치

  • 설치 진행중 ( 완료가 될 때까지 기다려 주세요. ) 완료 후 간단 설정들(계정 생성 등) 쭉쭉 진행해 주시면 됩니다.

  • 완료

 

다음 글 : Jenkins Github 연동

728x90
Comments