반응형

 

Nginx의 auth_request 기능을 사용하고 싶었지만, apache에는 이와 비슷한 기능이 없는 것 같아

AuthType이라는것을 사용하였다.

 

1. 사용전 htpasswd 확인

htpasswd는 기본적으로 Apach생성 경로의 bin폴더에 있다.

# Apache 가 /usr/local 폴더에 있을경우
/usr/local/apache/bin/htpasswd

 

bin폴더에 없을경우 httpd를 설치한다. - https://httpd.apache.org/download.cgi#apache24

 

2. htpasswd를 통해 계정과 비밀번호를 생성

-c 는 create 옵션이고 /home/test 폴더 내에 .htpasswd 파일을 생성하고

해당 파일에 user1이라는 계정과 패스워드를 관리한다

# Input
./htpasswd -c /home/test/.htpasswd user1

# Output
cat /home/test.htpasswd
user1:$apr1$.0CAabqX$rsdf8sdSDFgs/p90SDGcvb1Gs/

 

 

3. AuthType 설정

사용 중인 conf파일에 설정 후 아파치 재시작한다.

<Location "/private">

AuthType Basic
AuthName "Authentication required"
AuthUserFile /home/test/.htpasswd
Require valid-uesr

</Location>

 

 

기타.

이렇게 설정할 경우 기본적으로 웹사이트에 로그인하는 로직이 있다면 해당 세션이 끊기게되는데

아래 설정을 추가할 경우 해결할 수 있긴하다.

RequestHeader unset Authorization
<Location "/private">

AuthType Basic
AuthName "Authentication required"
AuthUserFile /home/test/.htpasswd
Require valid-uesr

</Location>

 

 

https://httpd.apache.org/docs/2.4/en/howto/auth.html

반응형
반응형

 

Java에서 Inner Class 사용시 발생하는 No enclosing instance of type is accessible 해결 방법이다.

 

아래와 같이 java 파일들이 구성되어있고 Hello.java 파일안에 World 라는 inner class가 있을 경우

public class Hello {
	private int id;

	public Hello() {
		super();
	}

	public Hello(int id) {
		super();
		this.id = id;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public class World {		
		private String name;

		public World() {
			super();
		}

		public World(String name) {
			super();
			this.name = name;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}			
		
	}
}

 

Hello안에있는 World Class를 사용하기 위해서 Hello Class를 먼저 생성 후 World Class를 호출한다.

import test3.Hello.World;

public class Main {

	public static void main(String[] args) {

		Hello hello = new Hello();
		World world = hello.new World();
				
	}

}
반응형
반응형

Nginx에서 client에서 파일 업로드와 같은 작업 수행시

응답으로는 이미 max_client_body_size 설정으로 에러인 상황에서 Request가 중단되어야하지만

Request가 끝까지 진행되는 경우가 있는데

이 경우 send_timeout, proxy_send_timeout, proxy_connect_timeout, client_body_timeout 등의 설정이아니라

 

lingering_time으로 설정해야한다.

Syntax:	lingering_time time;
Default: lingering_time 30s;
Context: http, server, location

This directive applies to client requests with a request body. As soon as the number of uploaded data exceeds max_client_body_size, Nginx immediately sends a 413 Request entity too large HTTP error response. However, most browsers continue uploading data regardless of that notification. This directive defines the number of time Nginx should wait after sending this error response before closing the connection.

 

http://nginx.org/en/docs/http/ngx_http_core_module.html#lingering_time

https://www.oreilly.com/library/view/nginx-http-server/9781788623551/97c141a3-0e51-4786-b865-8c8770a643a5.xhtml

반응형
반응형

Nginx Error Page 처리방법으로는 error_page를 먼저 선언하고 뒤에 에러코드

그리고 표시할 html 파일 이름을 작성한 후 location을 선언한다.

location 안에는 html 파일경로를 작성한다.

또한, 한번에 여러 에러를 같은 페이지로 처리하기 위해서는 500 501 502 이런식으로 선언하여 사용한다.

server {

    error_page 400 /error_400.html;
    location = /error_400.html {
        root /usr/error/;
    }
    
    error_page 404 /error_404.html;
    location = /error_404.html {
    	root /usr/error/;
    }
    
    error_page 500 501 502 /error_500.html;
    location = /error_500.html {
    	root /usr/error/;
    }
}

 

 

간혹 에러페이지를 선언하였지만, 해당 에러페이지로 가지 않을 땐

발생하는 해당 location에 proxy_intercept_errors on;을 선언한다.

server {

	
    error_page 400 /error_400.html;
    location = /error_400.html {
        root /usr/error/;
    }
    
    error_page 404 /error_404.html;
    location = /error_404.html {
    	root /usr/error/;
    }
    
    error_page 500 501 502 /error_500.html;
    location = /error_500.html {
    	root /usr/error/;
    }
    
    location /api/test {
    	proxy_intercept_errors on;
    }
}

 

반응형
반응형

Jenknis 에서 Git Checkout 할 경우 파일 용량이 클 때 아래와 같이 기본으로 사용할 경우 10분이 넘어갈 경우 timeout 이 발생한다.

pipeline {
    agent any 
    stages {
        stage('checkout') { 
            steps {
                git branch: 'master', credentialsId: 'credentialsId', url: 'git Repo URL"
            }
        }

    }
}

 

이를 해결하기 위해 스크립트를 사용할 경우 아래와 같이 사용하여 timeout 시간을 늘려준다.

pipeline {
    agent any 
    stages {
        stage('checkout') { 
            steps {
                checkout([
                	$class: "GitSCM",
                	branche: [[name: "master"]],
                	extensions: [
                    	[$class: "CheckoutOption", timeout: 120],
                    	[$class: "CloneOption", timeout: 120]
                    ],
                	gitTool "Default",
                	userRemoteConfigs: [[credentialsId: "credentialsId", url: "git Repo URL"]]
                ])
            }
        }

    }
}

 

반응형
반응형

 

Windows 에서의 Android Studio에서 발생하는 'unable to find valid certification path to requested target' 에러 해결방법

 

1. Chrome에서 아무 사이트 접속하여 상단의 자물쇠 모양을 마우스 우클릭한다.

2. 이 사이트는 보안 연결(HTTPS)이 사용되었습니다. 클릭

3. 인증서가 유효함 클릭

4.인증서 창에서 상단의 '인증경로'로 접속한후 '맨위의 항목'을 클릭한 다음 '인증서 보기' 클릭

5. 창이 하나 더 나타나며, 상단의 '자세히' 클릭 후 '파일에 복사' 클릭

6. 인증서 내보내기 마법사에서 먼저 다음 누른 뒤 Base 64로 인코딩된 X.509로 바탕화면이든 아무곳에 저장

반응형

7. Android Stuido에서 해당 프로젝트 우클릭 후 Open Module Settings 클릭

8. 좌측 메뉴의 SDK Location 클릭 후 JDK location 확인

'C:\Program Files\Android\Android Studio\jre'

9. C:\Program Files\Android\Android Studio\jre 폴더로 이동 후 bin폴더로 이동

-> C:\Program Files\Android\Android Studio\jre\bin 으로 이동

bin폴더에 keytools.exe가 있음

C:\Program Files\Android\Android Studio\jre\bin 에서 폴더 Windows PowerShell 관리자로 열기

10. keytool 명령어 입력

cacert 파일은 jre\lib\security 폴더에 들어가면 확인할 수 있는데 아래의 명령어를 통해 cacert에 인증서 등록

-file 옵션에는 아까 저장한 인증서 경로를 적으면되고 -alias 옵션을 통해 별칭 저장

또한, 입력하게 되면 패스워드를 입력하라고 하는데 패스워드는 changeit 이다

Password : changeit

.\keytool -import -keystore "C:\Program Files\Android\Android Studio\jre\lib\security" -file "C:\Users\root\Desktop\testcert.cer" -alias testcert

11. 저장 후 안되면 재부팅 또는 Android Studio를 종료 후 다시 실행

반응형
반응형

.

 

Jenkins 에서 Lambda Plugin을 사용한 코드배포 및 함수 실행이다.

 

1. 람다 생성 및 기본적인 플러그인 세팅

1.1) jenkinsTest 람다 함수생성

람다 함수 생성

1.2) Jenkins Lambda Plugin 세팅

젠킨스 플러그인 설치

반응형

2. 파이프라인 세팅

pipeline {
    agent any
    
    stages {
        stage('Git CheckOut'){
            steps{
                git branch: 'main', url: 'https://github.com/ / .git'
            }
        }
        stage('Make .zip'){
            steps{
                zip zipFile: 'test.zip'
            }
        }
        stage('lambda deploy'){
            steps{
                 withCredentials([[$class: 'AmazonWebServicesCredentialsBinding', credentialsId: 'pangyeon',
                    accessKeyVariable: 'AWS_ACCESS_KEY_ID', secretKeyVariable: 'AWS_SECRET_ACCESS_KEY']]){
                    deployLambda(
                        awsRegion: 'ap-northeast-2',
                        awsAccessKeyId: "${AWS_ACCESS_KEY_ID}",
                        awsSecretKey: "${AWS_SECRET_ACCESS_KEY}",
                        functionName: 'jenkinsTest',
                        artifactLocation: 'test.zip',
                        updateMode: 'code'
                    )
                }
            }
        }
        stage('lambda invoke'){
            steps{
                withAWS(region:'ap-northeast-2', credentials:'pangyeon') {
                    invokeLambda(
                        functionName: 'jenkinsTest'
                    )
                }
            }
        }
    }
    post { 
        always { 
            sh 'rm test.zip'
        }
    }
}

 

3. 실행

 

4. 배포 확인

4.1) 이전 코드

이전 코드

4.2) 배포 후 코드

배포 후 코드

5. 실행 확인

5.1) Jenkins 실행 로그

RequestId : d019e541-92df-4fac-9021-96f150b793c2

Jenkins 실행 로그

5.2) Lambda 로그

RequestId :  d019e541-92df-4fac-9021-96f150b793c2

Lambda 로그

5.1, 5.2의 RequestId가 동일하다는 것을 볼 수 있다.

 

반응형
반응형

Groovy 에서 REST API호출을 위해 HttpBuilder란 것을 사용한다.

아래는 간단히 Groovy에서 Jenkins 빌드를 위한 예제

 

import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.JSON

def http = new HTTPBuilder( 'http://jenkinsUrl.com' )
def crumb =''

http.request(GET) { 
  uri.path = '/crumbissuer/api/json' // CSRF 때문에 먼저 token 호출
  headers.'Authorization' = 'Basic id:paswword' // Base64Encode 해야함
 
  response.success = { resp, reader ->
    crumb = reader['crumb']
  }
 
  
  response.failure = { resp ->
    println 'Error'
  }
}

http.request(POST) {
  uri.path = '/job/test/build' // 빌드할 Jenkins Job
  headers.'Authorization' = 'Basic id:paswword' // Base64Encode 해야함
  headers.'Jenkins-Crumb' = crumb // 위에서 호출한 Token값 필요
 
  response.success = { resp, reader ->
    // 성공하면 젠킨스 빌드됨.
  }
 
  
  response.failure = { resp ->
    println 'Error'
  }
}

 

참조 : https://github.com/jgritman/httpbuilder/wiki

 

GitHub - jgritman/httpbuilder

Contribute to jgritman/httpbuilder development by creating an account on GitHub.

github.com

 

반응형
반응형

 

Window에서 Keycloak 포트 변경을 위해 아래와 같이 입력하였으나

.\standalone.bat -Djboss.socket.binding.port-offset=100

 

실행 시 아래와 같은 에러가 발생하였다.

WFLYSRV0073: Invalid option '.socket.binding.port-offset=100'

 

해결방법은 아래와 같이 옵션 양끝에 쌍따옴표를 붙여 해결 할 수 있다.

.\standalone.bat "-Djboss.socket.binding.port-offset=100"

 

 

반응형
반응형

Python - 2023.04.27 - [Develop/Python] - Python Package Nexus Upload (whl 파일, Offline 환경)

 

오프라인 서버에 Nexus가 설치되어 있을 경우, Nexus Repository에 Maven 라이브러리들을 대량 업로드할 필요가 있다.

shell script를 이용한방법과 proxy repository를 이용한 방법이있다.

 

 

1. Shell Script를 이용한 방법.

1.1 mavenimport.sh

아래의 주소에 접속해서 Nexus 설치 서버에 mavenimport.sh를 다운받는다.

github.com/sonatype-nexus-community/nexus-repository-import-scripts

 

sonatype-nexus-community/nexus-repository-import-scripts

A few scripts for importing artifacts into Nexus Repository - sonatype-nexus-community/nexus-repository-import-scripts

github.com

 

1.2 Repository 이동

Window라면 User/.m2/repository에 있는 Maven폴더들을 Nexus가 설치되어 있는 서버에 옮긴다.

아래와 같이 mavenimport.sh와 같은 위치에 라이브러리들을 위치시킨다.

1.3 명령어 실행

넥서스 계정과 비밀번호 및 IP와 PORT 저장할 repository들을 지정하고 실행한다.

./mavenimport.sh -u ID -p PASSWORD -r http://IP:PORT/repository/maven-releases/

실행 후 Nexus 저장소를 확인하면 라이브러리들이 들어가있는 것을 확인할 수 있다.

반응형

2. Proxy Repository를 이용하는 방법

2.1 Local Server 또는 Online Server에 Nexus 설치

인터넷이 되는 서버에 Nexus를 먼저 설치한다.

 

 

2.2 Proxy Repository 생성

Offline으로 Nexus가 설치되어 있는 서버에 maven2 (proxy) 저장소를 생성한다.

생성하는 항목의 Remote storage 부분에 인터넷이 되는 서버의 Nexus Maven Central Repository 또는 이미 사용하고 있는 저장소의 URL을 입력한다.

 

2.3 Settings.xml 설정

Maven Settings.xml을 설정한다 Window일 경우 User/.m2/ 폴더에 있다. 만약 없으면 아래와 같이 생성한다.

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">


</settings>

생성하였으면, 아래와 같이 <server> 와 <mirror>를 설정한다.

1. <servers>

<id>에는 <mirror>에 입력할 id 이므로 적절하게 사용한다.

<username>은 Nexus 아이디이다. Nexus에 anonymous가 허용되어있다면 입력해도 무관하다.

<password>는 Nexus 아이디의 비밀번호이다.

 

2. <mirros>

<id> 에는 위에 생성한 id를 입력한다

<name> 은 저장소의 설명이다.

<url> 에는 위에서 생성한 Offline Nexus Server의 maven2 (proxy) URL을 입력하면 된다.

<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0
                      http://maven.apache.org/xsd/settings-1.0.0.xsd">


 <servers>
    <server>
      <id>nexus</id>
      <username> </username>
      <password> </password>
    </server>
  
  </servers>

  <mirrors>
    <mirror>
      <id>nexus</id>
      <name>nexus</name>
      <url>http://주소:8081/repository/home/</url>
      <mirrorOf>*</mirrorOf>
    </mirror>
  </mirrors>

</settings>

 

설정 후 프로젝트에 Maven Dependency를 추가하거나 Jenkins 빌드를 하게 되면 자동으로 Nexus에 라이브러리들이 업로드되어 Nexus Repository를 사용할 수 있는 것을 확인할 수 있다.

 

끝으로..

2가지 방법 중 하나를 선택해 적절히 사용하면 될 것 같다.

반응형

+ Recent posts