slipp study를 통해 정리했던 내용들 다시 옮겨 놓음. ( SLiPP wiki 바로가기 )
1. 사전 세팅.
git repository : https://github.com/slipp-hipster/jhipster_msa_exam.git
msa 폴더로 클론 :
git clone https:
//github.com/slipp-hipster/jhipster_msa_exam.git msa
submodule 초기화 및 업데이트
cd msa && git submodule init && git submodule update
gateway node_module 추가 및 rebuild ( 이 과정을 생략하면 localhost:8080 접근 시 빈 화면만 보여집니다. )
gateway> yarn install && yarn start
jhipster-registry 서버 배포 ( docker-compose 이용 )
uaa> docker-compose -f ./src/main/docker/jhipster-registry.yml up -d
uaa, gateway, app1, app2 배포
각 서비스별로 root> ./gradlew
gradlew 실행시 node/ npm 관련 오류 발생 시 삭제 후 재설치 하는것을 추천함. (ex. A problem occurred starting process 'command 'npm'' )
-> brew update | brew uninstall node | brew install node
2. generator-jhipster 업그레이드.
yarn global upgrade generator-jhipster |
3. jhipster msa 설치 ( uaa, gateway, app1, app2 )
http://www.jhipster.tech/microservices-architecture/
http://www.jhipster.tech/using-uaa/
각 서버를 세팅할 디렉토리를 생성하고 각 디렉토리에서 jhipster를 실행하여 서버를 세팅한다
msa> mkdir uaa gateway app1 app2
uaa> jhipster
Welcome to the JHipster Generator v4. 10.0 Documentation for creating an application: http: //www.jhipster.tech/creating-an-app/ Application files will be generated in folder: /Users/hkp/study/slipp/13_jhipster/msa/uaa ? ( 1 / 16 ) Which *type* of application would you like to create? JHipster UAA server ( for microservice OAuth2 authentication) ? ( 2 / 16 ) What is the base name of your application? uaa ? ( 3 / 16 ) As you are running in a microservice architecture, on which port would like your server to run? It should be unique to avoid port conflicts. 9999 ? ( 4 / 16 ) What is your default Java package name? net.slipp.jhipster ? ( 5 / 16 ) Which service discovery server do you want to use? JHipster Registry (uses Eureka, provides Spring Cloud Config support and monitoring dashboards) ? ( 6 / 16 ) Which *type* of database would you like to use? SQL (H2, MySQL, MariaDB, PostgreSQL, Oracle, MSSQL) ? ( 7 / 16 ) Which *production* database would you like to use? MySQL ? ( 8 / 16 ) Which *development* database would you like to use? H2 with disk-based persistence ? ( 9 / 16 ) Do you want to use Hibernate 2nd level cache? Yes, with HazelCast (distributed cache, for multiple nodes) ? ( 10 / 16 ) Would you like to use Maven or Gradle for building the backend? Gradle ? ( 11 / 16 ) Which other technologies would you like to use? ? ( 12 / 16 ) Would you like to enable internationalization support? Yes ? Please choose the native language of the application Korean ? Please choose additional languages to install English ? ( 13 / 16 ) Besides JUnit and Karma, which testing frameworks would you like to use? Gatling, Cucumber ? ( 14 / 16 ) Would you like to install other generators from the JHipster Marketplace? No |
gateway> jhipster
Welcome to the JHipster Generator v4. 10.0 Documentation for creating an application: http: //www.jhipster.tech/creating-an-app/ Application files will be generated in folder: /Users/hkp/study/slipp/13_jhipster/msa/gateway ? ( 1 / 16 ) Which *type* of application would you like to create? Microservice gateway ? ( 2 / 16 ) What is the base name of your application? gateway ? ( 3 / 16 ) As you are running in a microservice architecture, on which port would like your server to run? It should be unique to avoid port conflicts. 8080 ? ( 4 / 16 ) What is your default Java package name? net.slipp.jhipster ? ( 5 / 16 ) Which service discovery server do you want to use? JHipster Registry (uses Eureka, provides Spring Cloud Config support and monitoring dashboards) ? ( 6 / 16 ) Which *type* of authentication would you like to use? Authentication with JHipster UAA server (the server must be generated separately) ? ( 7 / 16 ) What is the folder path of your UAA application? ../uaa ? ( 8 / 16 ) Which *type* of database would you like to use? SQL (H2, MySQL, MariaDB, PostgreSQL, Oracle) ? ( 9 / 16 ) Which *production* database would you like to use? MySQL ? ( 10 / 16 ) Which *development* database would you like to use? H2 with disk-based persistence ? ( 11 / 16 ) Would you like to use Maven or Gradle for building the backend? Gradle ? ( 12 / 16 ) Which other technologies would you like to use? Clustered HTTP sessions using Hazelcast ? ( 13 / 16 ) Which *Framework* would you like to use for the client? Angular 4 ? ( 14 / 16 ) Would you like to use the LibSass stylesheet preprocessor for your CSS? No ? ( 15 / 16 ) Would you like to enable internationalization support? Yes ? Please choose the native language of the application Korean ? Please choose additional languages to install English ? ( 16 / 16 ) Besides JUnit and Karma, which testing frameworks would you like to use? Gatling, Cucumber, Protractor ? ( 17 / 16 ) Would you like to install other generators from the JHipster Marketplace? No |
app1> jhipster
Welcome to the JHipster Generator v4. 10.0 Documentation for creating an application: http: //www.jhipster.tech/creating-an-app/ Application files will be generated in folder: /Users/hkp/study/slipp/13_jhipster/msa/app1 ? ( 1 / 16 ) Which *type* of application would you like to create? Microservice application ? ( 2 / 16 ) What is the base name of your application? app1 ? ( 3 / 16 ) As you are running in a microservice architecture, on which port would like your server to run? It should be unique to avoid port conflicts. 8081 ? ( 4 / 16 ) What is your default Java package name? net.slipp.jhipster ? ( 5 / 16 ) Which service discovery server do you want to use? JHipster Registry (uses Eureka, provides Spring Cloud Config support and monitoring dashboards) ? ( 6 / 16 ) Which *type* of authentication would you like to use? Authentication with JHipster UAA server (the server must be generated separately) ? ( 7 / 16 ) What is the folder path of your UAA application? ../uaa ? ( 8 / 16 ) Which *type* of database would you like to use? SQL (H2, MySQL, MariaDB, PostgreSQL, Oracle) ? ( 9 / 16 ) Which *production* database would you like to use? MySQL ? ( 10 / 16 ) Which *development* database would you like to use? H2 with disk-based persistence ? ( 11 / 16 ) Do you want to use Hibernate 2nd level cache? Yes, with HazelCast (distributed cache, for multiple nodes) ? ( 12 / 16 ) Would you like to use Maven or Gradle for building the backend? Gradle ? ( 13 / 16 ) Which other technologies would you like to use? ? ( 14 / 16 ) Would you like to enable internationalization support? Yes ? Please choose the native language of the application Korean ? Please choose additional languages to install English ? ( 15 / 16 ) Besides JUnit and Karma, which testing frameworks would you like to use? Gatling, Cucumber ? ( 16 / 16 ) Would you like to install other generators from the JHipster Marketplace? No |
app2> jhipster
Welcome to the JHipster Generator v4. 10.0 Documentation for creating an application: http: //www.jhipster.tech/creating-an-app/ Application files will be generated in folder: /Users/hkpking/study/slipp_msa_uaa/slipp-app2 ? ( 1 / 16 ) Which *type* of application would you like to create? Microservice application ? ( 2 / 16 ) What is the base name of your application? app2 ? ( 3 / 16 ) As you are running in a microservice architecture, on which port would like your server to run? It should be unique to avoid port conflicts. 8082 ? ( 4 / 16 ) What is your default Java package name? net.slipp.jhipster ? ( 5 / 16 ) Which service discovery server do you want to use? JHipster Registry (uses Eureka, provides Spring Cloud Config support and monitoring dashboards) ? ( 6 / 16 ) Which *type* of authentication would you like to use? Authentication with JHipster UAA server (the server must be generated separately) ? ( 7 / 16 ) What is the folder path of your UAA application? ../slipp-uaa ? ( 8 / 16 ) Which *type* of database would you like to use? SQL (H2, MySQL, MariaDB, PostgreSQL, Oracle) ? ( 9 / 16 ) Which *production* database would you like to use? MySQL ? ( 10 / 16 ) Which *development* database would you like to use? H2 with disk-based persistence ? ( 11 / 16 ) Do you want to use Hibernate 2nd level cache? Yes, with HazelCast (distributed cache, for multiple nodes) ? ( 12 / 16 ) Would you like to use Maven or Gradle for building the backend? Gradle ? ( 13 / 16 ) Which other technologies would you like to use? ? ( 14 / 16 ) Would you like to enable internationalization support? Yes ? Please choose the native language of the application Korean ? Please choose additional languages to install English ? ( 15 / 16 ) Besides JUnit and Karma, which testing frameworks would you like to use? Gatling, Cucumber ? ( 16 / 16 ) Would you like to install other generators from the JHipster Marketplace? No |
3. Entity 추가
* app1 : Owner, Contents
* app2 : Product
* gateway : Owner, Contents, Product
각 서버에 해당 Entity를 추가한다. 각 서버의 디렉토리 위치에서 다음 명령어를 실행.
app1> jhipster entity owner
Using JHipster version installed locally in current project's node_modules
Executing jhipster:entity owner
Options:
The entity owner is being created.
Generating field #1
? Do you want to add a field to your entity? Yes
? What is the name of your field? login
? What is the type of your field? String
? Do you want to add validation rules to your field? No
================= Owner =================
Fields
login (String)
Generating field #2
? Do you want to add a field to your entity? Yes
? What is the name of your field? firstName
? What is the type of your field? String
? Do you want to add validation rules to your field? No
================= Owner =================
Fields
login (String)
firstName (String)
Generating field #3
? Do you want to add a field to your entity? Yes
? What is the name of your field? lastName
? What is the type of your field? String
? Do you want to add validation rules to your field? No
================= Owner =================
Fields
login (String)
firstName (String)
lastName (String)
Generating field #4
? Do you want to add a field to your entity? Yes
? What is the name of your field? email
? What is the type of your field? String
? Do you want to add validation rules to your field? No
================= Owner =================
Fields
login (String)
firstName (String)
lastName (String)
email (String)
Generating field #5
? Do you want to add a field to your entity? No
================= Owner =================
Fields
login (String)
firstName (String)
lastName (String)
email (String)
Generating relationships to other entities
? Do you want to add a relationship to another entity? No
================= Owner =================
Fields
login (String)
firstName (String)
lastName (String)
email (String)
? Do you want to use a Data Transfer Object (DTO)? No, use the entity directly
? Do you want to use separate service class for your business logic? No, the REST controller should use the repository directly
? Do you want pagination on your entity? No
Everything is configured, generating the entity...
create .jhipster/Owner.json
create src/main/resources/config/liquibase/changelog/20171023071920_added_entity_Owner.xml
create src/main/java/net/slipp/jhipster/domain/Owner.java
create src/main/java/net/slipp/jhipster/repository/OwnerRepository.java
create src/main/java/net/slipp/jhipster/web/rest/OwnerResource.java
create src/test/java/net/slipp/jhipster/web/rest/OwnerResourceIntTest.java
create src/test/gatling/user-files/simulations/OwnerGatlingTest.scala
conflict src/main/resources/config/liquibase/master.xml
? Overwrite src/main/resources/config/liquibase/master.xml? overwrite this and all others
force src/main/resources/config/liquibase/master.xml
Entity generation completed
Congratulations, JHipster execution is complete!
app1> jhipster entity contents
Using JHipster version installed locally in current project's node_modules
Executing jhipster:entity contents
Options:
The entity contents is being created.
Generating field #1
? Do you want to add a field to your entity? Yes
? What is the name of your field? title
? What is the type of your field? String
? Do you want to add validation rules to your field? No
================= Contents =================
Fields
title (String)
Generating field #2
? Do you want to add a field to your entity? Yes
? What is the name of your field? desc
? What is the type of your field? String
? Do you want to add validation rules to your field? No
================= Contents =================
Fields
title (String)
desc (String)
Generating field #3
? Do you want to add a field to your entity? No
================= Contents =================
Fields
title (String)
desc (String)
Generating relationships to other entities
? Do you want to add a relationship to another entity? Yes
? What is the name of the other entity? owner
? What is the name of the relationship? owner
? What is the type of the relationship? many-to-one
? When you display this relationship with Angular, which field from 'owner' do you want to use? This field will be displayed as a String, so it cannot be a Blob login
? Do you want to add any validation rules to this relationship? No
================= Contents =================
Fields
title (String)
desc (String)
Relationships
owner (Owner) many-to-one
Generating relationships to other entities
? Do you want to add a relationship to another entity? No
================= Contents =================
Fields
title (String)
desc (String)
Relationships
owner (Owner) many-to-one
? Do you want to use a Data Transfer Object (DTO)? No, use the entity directly
? Do you want to use separate service class for your business logic? No, the REST controller should use the repository directly
? Do you want pagination on your entity? No
Everything is configured, generating the entity...
create .jhipster/Contents.json
create src/main/resources/config/liquibase/changelog/20171023072346_added_entity_Contents.xml
create src/main/resources/config/liquibase/changelog/20171023072346_added_entity_constraints_Contents.xml
create src/main/java/net/slipp/jhipster/domain/Contents.java
create src/main/java/net/slipp/jhipster/repository/ContentsRepository.java
create src/main/java/net/slipp/jhipster/web/rest/ContentsResource.java
create src/test/java/net/slipp/jhipster/web/rest/ContentsResourceIntTest.java
create src/test/gatling/user-files/simulations/ContentsGatlingTest.scala
conflict src/main/resources/config/liquibase/master.xml
? Overwrite src/main/resources/config/liquibase/master.xml? overwrite this and all others
force src/main/resources/config/liquibase/master.xml
Entity generation completed
Congratulations, JHipster execution is complete!
app2> jhipster entity product
Using JHipster version installed locally in current project's node_modules
Executing jhipster:entity product
Options:
The entity product is being created.
Generating field #1
? Do you want to add a field to your entity? Yes
? What is the name of your field? productName
? What is the type of your field? String
? Do you want to add validation rules to your field? No
================= Product =================
Fields
productName (String)
Generating field #2
? Do you want to add a field to your entity? Yes
? What is the name of your field? price
? What is the type of your field? Integer
? Do you want to add validation rules to your field? No
================= Product =================
Fields
productName (String)
price (Integer)
Generating field #3
? Do you want to add a field to your entity? No
================= Product =================
Fields
productName (String)
price (Integer)
Generating relationships to other entities
? Do you want to add a relationship to another entity? No
================= Product =================
Fields
productName (String)
price (Integer)
? Do you want to use a Data Transfer Object (DTO)? No, use the entity directly
? Do you want to use separate service class for your business logic? No, the REST controller should use the repository directly
? Do you want pagination on your entity? No
Everything is configured, generating the entity...
create .jhipster/Product.json
create src/main/resources/config/liquibase/changelog/20171023072820_added_entity_Product.xml
create src/main/java/net/slipp/jhipster/domain/Product.java
create src/main/java/net/slipp/jhipster/repository/ProductRepository.java
create src/main/java/net/slipp/jhipster/web/rest/ProductResource.java
create src/test/java/net/slipp/jhipster/web/rest/ProductResourceIntTest.java
create src/test/gatling/user-files/simulations/ProductGatlingTest.scala
conflict src/main/resources/config/liquibase/master.xml
? Overwrite src/main/resources/config/liquibase/master.xml? overwrite this and all others
force src/main/resources/config/liquibase/master.xml
Entity generation completed
Congratulations, JHipster execution is complete!
동일한 방법으로 gateway에도 product, owner, contents entity 추가
jhipster entity owner
jhipster entity contents
jhipster entity product
4. app1(owner) - uaa(user) entity 연동
UserClient12345 @AuthorizedFeignClient
(name =
"uaa"
)
public
interface
UserClient {
@GetMapping
(
"/api/users"
)
List<Owner> getOwners();
}
OwnerResource12 @Inject
private
UserClient userClient;
5. jhipster ci-cd 사용하여 jenkins 설치 (http://www.jhipster.tech/setting-up-ci/)
1. jhipster ci-cd 실행
➜ uaa jhipster ci-cd
Using JHipster version installed locally in current project’s node_modules
Executing jhipster:ci-cd
Options:
[Beta] Welcome to the JHipster CI/CD Sub-Generator
? What CI/CD pipeline
do
you want to generate? Jenkins pipeline
? Jenkins pipeline: what tasks/integrations
do
you want to include? Analyze code with Sonar
? What is the name of the Sonar server? Sonar
? Deploy to heroku?
create Jenkinsfile
create src/main/docker/jenkins.yml
create src/main/resources/idea.gdsl
Execution complete
2. 생성된 jenkins.yml 내용 수정 (image 최신버전으로 변경(jenkins -> jenkins/jenkins), 기본 포트 49001 -> 18080으로 변경)
version:
'2'
services:
jenkins:
image: jenkins/jenkins
ports:
-
18080
:
8080
-
50000
:
50000
# uncomment
for
docker in docker
#privileged:
true
#volumes:
# enable persistent volume (warning: make sure that the local jenkins_home folder is created)
#- ~/volumes/jenkins_home:/var/jenkins_home
# mount docker sock and binary
for
docker in docker (only works on linux)
#- /var/run/docker.sock:/var/run/docker.sock
#- /usr/bin/docker:/usr/bin/docker
3. jenkins 실행
➜ uaa docker-compose -f src/main/docker/jenkins.yml up -d
4. jenkins 접속
1) 브라우저에서 localhost:18080 로 접속
2) Adminastrator password 입력 : 아래의 명령어로 jenkins 도커 컨테이너 내부에 접근하여 해당 경로의 파일에서 비밀번호를 출력한다.docker exec docker_jenkins_1 bash -c
'cat /var/jenkins_home/secrets/initialAdminPassword'
5. jenkins 설치 : Install suggested plugins 를 선택하여 간단하게 설치를 시작한다.
6. pipeline 작업 생성
: 설치 완료 후 새작업을 클릭하여 작업을 생성한다. (참고 : http://www.jhipster.tech/setting-up-ci-jenkins2/ )
7. sonarqube 연동
: 빌드단계에서 자동으로 코드 품질을 테스트 할 수 있도록 sonarqube 연동
- sonar 서버 시작 : docker-compose -f src/main/docker/sonar.yml up -d
sonarqube 세팅
- sonarqube token 발급 및 프로젝트 세팅 : localhost:9000 접속 > login (admin/admin) > tutorial 입력
jenkins 세팅
- plugin 설치
: Jenkins 관리 > 플러그인 관리 > 설치 가능 > SonarQube Scanner for Jenkins 설치
- sonar 연동
: Jenkins 관리 > 시스템 설정 > SonarQube servers - Add SonarQube click - Enable injection of SonarQube … check - name : Sonar - Server Url : http://{server ip}:9000 - Server authentication token : SonarQube에서 발급 받은 토큰 (SonarQube > My Account > Security : Generate Tokens)8. 최초 작업 실행
Jenkins project > Build Project 메뉴를 눌러 최초 pipeline 연결을 확인 한다.
9. ngrok 실행
: 로컬에서 구동중인 jenkins를 외부에서 접근 가능하도록 ngrok을 통해 도메인을 생성한다.
: 다운로드는 여기서 -> https://ngrok.com/downloadngrok http
18080
10. github 연동
: git commit 발생시 자동으로 빌드하도록 연동
github 세팅
repository > settings > Integrations & services > Add service > Jenkins (GitHub plugin)
Jenkins hook url : http://b4863c42.ngrok.io/github-webhook/
jenkins 세팅
작업 설정 > GitHub hook trigger 선택
6. docker-compose 활용하여 prod 배포 (http://www.jhipster.tech/docker-compose/)
1. 각 서비스별로 도커 이미지로 빌드
➜ uaa git:(master) ✗ ./gradlew bootRepackage -Pprod buildDocker
➜ gateway git:(master) ✗ ./gradlew bootRepackage -Pprod buildDocker
➜ app1 git:(master) ✗ ./gradlew bootRepackage -Pprod buildDocker
➜ app2 git:(master) ✗ ./gradlew bootRepackage -Pprod buildDocker
2. msa root 폴더에 docker compose용 디렉토리 생성
➜ msa_sample git:(guide) mkdir docker && cd docker
3. jhipster docker-compose 실행
➜ docker git:(master) ✗ jhipster docker-compose
Using JHipster version installed globally
Executing jhipster:docker-compose
Options:
Welcome to the JHipster Docker Compose Sub-Generator
Files will be generated in folder: /Users/hkp/study/slipp/13_jhipster/msa_sample/docker
Found .yo-rc.json config file...
? Which *type* of application would you like to deploy? Microservice application
? Which *type* of gateway would you like to use? JHipster gateway based on Netflix Zuul
? Enter the root directory where your gateway(s) and microservices are located ../
4
applications found at /Users/hkp/study/slipp/13_jhipster/msa_sample/
? Which applications
do
you want to include in your configuration? app1, app2, gateway, uaa
? Do you want to setup monitoring
for
your applications ? Yes,
for
logs and metrics with the JHipster Console (based on ELK and Zipkin)
? You have selected the JHipster Console which is based on the ELK stack and additional technologies, which one
do
you want to use ?
JHipster registry detected as the service discovery and configuration provider used by your apps
? Enter the admin password used to secure the JHipster Registry admin
Checking Docker images in applications' directories...
identical docker-compose.yml
identical README-DOCKER-COMPOSE.md
identical jhipster-registry.yml
identical central-server-config/application.yml
identical jhipster-console.yml
identical log-conf/logstash.conf
identical log-data/.gitignore
Docker Compose configuration successfully generated!
You can launch all your infrastructure by running : docker-compose up -d
Congratulations, JHipster execution is complete!
7. jhipster-console 모니터링 확인(http://www.jhipster.tech/monitoring/)
1. jhipster-console.yml 수정
jhipster-elasticsearch:
image: jhipster/jhipster-elasticsearch:v2.
2.1
ports:
-
9200
:
9200
environment:
-
"ES_JAVA_OPTS=-Xms512m -Xmx512m"
ulimits:
memlock:
soft: -
1
hard: -
1
mem_limit: 1g
ELASTICSEARCH_URL=http:
//{local ip}:9200 으로 변경
2. application-prod.yml > log 활성화
jhipster.metrics.logs.enabled :
true
jhipster.logging.logstash.enabled :
true
jhipster.logging.logstash.host : {local ip}
'Dev. 자바 > JHipster' 카테고리의 다른 글
[JHipster] error Command "webpack:build:dev" not found (0) | 2019.02.11 |
---|---|
[JHipster] localhost:8080 - blank page 빈 페이지 오류 해결 (0) | 2019.02.11 |
[jhipster, yarn] unable to verify the first certificate (0) | 2017.11.28 |
[jhipster] kafka 사용시 java.lang.ClassNotFoundException: org.springframework.kafka.listener.adapter.RecordMessagingMessageListenerAdapter 에러 수정 (0) | 2017.10.13 |
jhipster 시작하기 (0) | 2017.07.01 |