2019년 3월 7일 목요일

[docker] tomcat8 docker image 생성 후, image 실행, 실행중인 container 접속 방법

[docker] tomcat8 docker image 생성 후, image 실행, 실행중인 container 접속 방법

명령어로  실행하는 방법을 정리함.

host 환경
* host os : window 7
* host docker tool : docker toolbox

$ docker pull tomcat:8
-> docker hub 로부터 tomcat8 image를 다운로드


$ docker run -d -i -t --name="tomcat8" -p 8080:8080 tomcat:8
-> tomcat:8이미지로 컨테이너 생성(생성과 함께 tomcat service start 됨)

$ docker cp ./stest.war tomcat8:/usr/local/tomcat/webapps/
-> 테스트 stest.war파일을 tomcat8 컨테이너 내부의 폴더로 복사

$ winpty docker exec -it eb4f //bin//bash
-> eb4f 라는 앞자를 가진 컨테이너아이디 값으로 tomcat8 서버 console 접속
-> /usr/local/tomcat/webapps/ 폴더에서 복사한 stest.war 파일 확인 가능

host os 의 브라우저 stest 웹사이트 접속 확인






 




2019년 3월 6일 수요일

[docker] mysql 5.7 docker image 생성 후, image 실행, 실행중인 container 접속 방법

[docker] mysql 5.7 docker image 생성 후, image 실행, 실행중인 container 접속 방법

host 환경
* host os : window 7
* host docker tool : docker toolbox



start.sh 실행.

$ docker --help
-> 각종 docker 명령어를 확인 가능

$ docker pull mysql:5.7
-> name : mysql, tagname : 5.7 의 image 파일 다운로드

$ docker images
-> 다운받거나 생성한 docker image 파일 목록을 확인할수 있다.





$ docker run -d -p 3306:3306 -e MYSQL_ROOT_PASSWORD=root --name ems_mysql mysql:5.7
-> image 파일 실행하여 ems_mysql container 생성

$ docker ps -a
-> container 목록 확인




$ winpty docker exec -it ems_mysql //bin//bash
-> ems_mysql 컨테이너 서버 접속

주의)
1] 윈도우7 환경에서, MINGW64 실행 실행시(start.sh), /bin/bash => //bin//bash 로 작성

2] winpty 붙이지 않은경우, 

the input device is not a TTY. If you are using mintty, try prefixing the command with 'winpty' 에러발생
-> 해결방법
winpty 를 docker 명령 앞에 붙인다.


root@7815e476dfb2:/# mysql -u root -p
-> 접속한 컨테이너에서 mysql 접속이 가능하다.

MySQL Workbench 접속










2019년 3월 5일 화요일

[spring boot] ubuntu tomcat8 설치경로

[spring boot] ubuntu tomcat8 설치경로

sudo apt-get install tomcat8 

설치경로

HOME : /usr/share/tomcat8 
CONF :  /etc/tomcat8 
LOG :  /var/log/tomcat8 
ROOT : /var/lib/tomcat8 

[spring boot] org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [HikariDataSource (HikariPool-16)] with key 'dataSource'; nested exception is javax.management.InstanceAlreadyExistsException: com.zaxxer.hikari:name=dataSource,type=HikariDataSource

[spring boot] org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [HikariDataSource (HikariPool-16)] with key 'dataSource'; nested exception is javax.management.InstanceAlreadyExistsException: com.zaxxer.hikari:name=dataSource,type=HikariDataSource



org.springframework.jmx.export.UnableToRegisterMBeanException: Unable to register MBean [HikariDataSource (HikariPool-16)] with key 'dataSource'; nested exception is javax.management.InstanceAlreadyExistsException: com.zaxxer.hikari:name=dataSource,type=HikariDataSource

war 파일 배포시, 해당 Exception 이 발생한다면,

application.properties 파일내에

 spring.jmx.enabled= false

를 추가 한다.

[spring boot] 스프링부트에서 외부jar파일 추가 방법(배포시에도 정상적으로 추가됨)

[spring boot] method of including external jar on spring boot maven project

스프링부트에서 외부jar파일 추가 방법(배포시에도 정상적으로 추가됨)

1. 아래 이미지 처럼, 프로젝트에 lib 폴더 생성 후, 외부jar를 추가한다.
2. 아래 이미지 우측처럼, pom.xml 에,

<properties>
         ...
<webapp.lib>${basedir}/lib</webapp.lib>
</properties>

추가 후,

<dependencies>
<dependency>
<groupId>external</groupId>
<artifactId>external</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${webapp.lib}/external.jar</systemPath>
</dependency>
</dependencies>

를 추가해준다. (주의] scope 는 system이다.







설정후, 프로젝트 클린&빌드를 한다.

여기까지 설정하면,
프로젝트에서 외부jar파일을 프로젝트에 포함되어 프로젝트가 해당 jar를 인식한다.

스프링부트의 boot dashboard 상으로 local실행시에 외부 jar가 빌드시 프로젝트내에 추가되어 잘 실행된다.

그러나, 배포를 위해 maven install 시에는, 설정한 jar파일들이 프로젝트의 WEB-INF/classes 폴더 (기본설정값) 로 저장되어, 배포시 외부jar를 사용하는 class에서 org.springframework.beans.factory.BeanCreationException: 
을 발생 시킨다.

따라서, 외부jar를 maven install 시, WEB-INF/lib 폴더에 저장되도록
Build Path > Configure Build Path... 에서 설정 해 줘야한다.

아래 그림처럼 설정한다.(지운부분은 프로젝트명 영역)



프로젝트에 추가한 lib 폴더를 우측 Add Folder 버튼을 이용해서 추가해주고,
Output folder: 를 선택 후, 우측에 활성화된 Edit 버튼을 이용해서 해당 프로젝트의
project/target/project/WEB-INF/lib 를 선택하고
Apply로 적용해 주면 설정 끝.

프로젝특 의 target 폴더 내의 모든 파일과 폴더를 삭제후, 프로젝트 클린&빌드 후,
maven install을 실행 하게 되면, 생성된 배포 war 파일이 만들어지는데,

해당 war 파일을 열어보면, WEB-INF/lib 폴더에 저장됨을 확인 할 수 있고,

tomcat8/webapp 폴더에 배포시, 정상실행된다.












2019년 2월 13일 수요일

[spring boot] @Component 선언한 class 파일 불러오는 방법

@Component 선언한 class 파일 불러오는 방법

예)

@Component
public class Scheduler {
}

라고 작성한 class 파일이있을때,

Scheduler s = ApplicationContextLocator.getApplicationContext().getBean(Scheduler.class);

처럼 class를 불러올수 있다.


2018년 5월 4일 금요일

[ubuntu] git 서버 구축

ubuntu 서버에 git 서버 구축 하기



$$ ubuntu 에서 git 서버 설치 및 설정


1. 먼저 서버 최신 정보로 업데이트와 업그레이드 하기



> sudo apt-get update
> sudo apt-get upgrade


2. git 설치



> sudo add-apt-repository ppa:git-core/ppa
> sudo apt-get install git-core


3. git 설정



3-1. git 사용을 위한 대표계정 생성

> sudo adduser git

*) 비번은 잊어 먹지 않도록 주의


3-2. 새 git 계정으로 로그인

> su git


3-3. home 디렉토리로 이동후, repos 디렉토리 생성

> cd ~
> mkdir repos
> cd repos

3-4. 프로젝트 폴더 생성.
> cd /home/git/repos/project.gitls

> git init --bare --shared



$$ client pc 에서 ubuntu 에 생성한 원격 git 저장소 복사하기(windows 기준)



1. git-bash.exe 설치



2. git-bash.exe 실행



3. 원격 git 저장소를 복사할 위치 에서



> git clone ssh://git@<host name or ip>:<port>/home/git/repos/project.git

=> ssh:// 다음 git 은 ubuntu에서 생성항 대표 계정
=> port 는 22 로 우분투에 설정되어 있으면 생략가능

> git@<host name or ip> password :   git 패스워드 입력


4. 원격 저장소 가 client 에 복사된 폴더가 확인 가능 함. 폴더 내로 들어가서,
파일 생성 후 아래의 git 사용 명령을 통해 로컬파일을 원격저장소에 저장가능하다.



5. git 에 추가할 파일들 추가명령 실행


> git add * -f

=> 명령 실행시 추가하는 파일목록들이 화면에 표시되면, 다시 한번 명령을 실행.
     아무 메시지없으면 정상적으로로컬에 추가된상태임


6. 로컬 저장소에 변경사항 저장


> git commit -m "commit message 입력"


7. 로컬저장소에 저장된 사항을 원격지 git 저장소에 반영


> git push origin master

=> 에러나는경우(error: remote unpack failed: unable to create temporary object directory)

권한변경

=>  chown -R git:git [프로젝트네임].git/