'2020/03'에 해당되는 글 24건

  1. 2020.03.20 [Reactor Netty] WebClient connection pool?
  2. 2020.03.19 [Elasticsearch] 작은 팁!!
  3. 2020.03.19 [Docker] 컨테이너/이미지 삭제, 로그 보기
  4. 2020.03.19 [Docker] gitlab, redmine, jenkins 설치 하기
  5. 2020.03.18 [Docker] 초보자를 위한 Container 실행/접속/재시작/User변경
  6. 2020.03.17 [Shell] Ubuntu 에서 Reboot 시 자동 스크립트 실행.
  7. 2020.03.16 [AWS] EC2 인스턴스 백업 하기
  8. 2020.03.16 [Gitlab] HTTP Basic: Access denied 해결 하기
  9. 2020.03.16 [Redmine] Ubuntu 에 Redmine 설치 하기
  10. 2020.03.13 [AWS] aws cli 사용 시 --query 알아보기

[Reactor Netty] WebClient connection pool?

ITWeb/개발일반 2020. 3. 20. 19:12

RestTemplate 을 사용 할 까 하다, WebClient 로 변경 했습니다.

더불어 늘 Connection Pool 에 대한 고민을 하는데요.

 

https://projectreactor.io/docs/netty/snapshot/reference/index.html#_connection_pool

By default, the TCP client uses a “fixed” connection pool with 500 
as the maximum number of the channels, 
45s as the pending acquire timeout and 1000 as the maximum number of 
the registered requests for acquire to keep in the pending queue. 
This means that the implementation creates a new channel 
if someone tries to acquire a channel but none is in the pool. 
When the maximum number of the channels in the pool is reached, 
new tries to acquire a channel are delayed 
until a channel is returned to the pool again. 
The implementation uses FIFO order for channels in the pool. 
By default, there is no idle time specified for the channels in the pool.

Channel 500개

Queue 1000개

 

그냥 신경쓰지 말고 쓰라고 합니다.

:

[Elasticsearch] 작은 팁!!

Elastic/Elasticsearch 2020. 3. 19. 20:15

Elasticsearch 를 사용 하다 보면 Maximum 값에 대한 궁금증이 생길 때가 있습니다.

지나가다 또 기억 못할 까봐 적어 봅니다.

 

1. Shard 하나가 가질 수 있는 최대 Document/Term 의 수는 대략 21억개 입니다.

Elasticsearch 에서 Shard 는 Lucene 기준에 Segments 에 해당 합니다.

공식 문서에는 아래와 같이 나와 있습니다.

https://lucene.apache.org/core/8_4_1/index.html

https://lucene.apache.org/core/8_4_1/core/org/apache/lucene/codecs/lucene84/package-summary.html#Limitations

Lucene uses a Java int to refer to document numbers, 
and the index file format uses an Int32 on-disk to store document numbers. 
This is a limitation of both the index file format and 
the current implementation. 
Eventually these should be replaced with either UInt64 values, 
or better yet, VInt values which have no limit.

 

그래서 == 2,147,483,647

 

2. Shard  1개의 크기는 너무 작아도 너무 커도 안됩니다.

실시간 서비스를 위한 용도로는 ~ 10GB

백오피스 운영을 위한 용도로는 ~ 50GB (그러나 Aggregation 질의가 많고 검색 범위가 넓을 경우 20GB 정도로 사용하세요.)

정답은 없으며, 다양한 환경에 따라 적절히 구성해서 사용을 하셔야 합니다.

 

3. Document 1개의 크기는 최대 2GB 까지 입니다.

그러나 이렇게 까지 사용 하시라고 절대 저는 추천 하지 않습니다.

 

:

[Docker] 컨테이너/이미지 삭제, 로그 보기

Cloud&Container/IaC 2020. 3. 19. 11:56

# 컨테이너 삭제 (docker ps)

$ docker stop ${CONTAINER ID} or ${CONTAINER NAME}
$ docker rm ${CONTAINER ID} or ${CONTAINER NAME}
또는
$ docker rm -f ${CONTAINER ID} or ${CONTAINER NAME}



# 컨테이너 이미지 삭제 (docker images)

$ docker rmi ${IMAGE ID}



# 컨테이너 로그 보기

$ docker logs -f ${CONTAINER ID} or ${CONTAINER NAME}

 

:

[Docker] gitlab, redmine, jenkins 설치 하기

Cloud&Container/IaC 2020. 3. 19. 11:48

 

환경)

- AWS

- Ubuntu 18.04 LTS

- Python 3.8.2

- Pip 3

 

Step 1) docker 를 설치 합니다.

$ sudo apt update
$ sudo apt upgrade
$ sudo apt-get install curl apt-transport-https ca-certificates software-properties-common
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
$ sudo apt update
$ sudo apt install docker-ce
$ sudo systemctl status docker
$ sudo docker run hello-world

$ docker ps
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post http://%2Fvar%2Frun%2Fdocker.sock/v1.40/images/create?fromImage=gitlab%2Fgitlab-ee&tag=latest: dial unix /var/run/docker.sock: connect: permission denied

$ sudo usermod -a -G docker ubuntu
또는
$ sudo chmod 666 /var/run/docker.sock
$ sudo service docker restart

 

Step 2) docker compose 를 설치 합니다.

https://docs.docker.com/compose/compose-file/compose-versioning/#version-3

$ sudo curl -L "https://github.com/docker/compose/releases/download/1.25.4/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
$ sudo chmod +x /usr/local/bin/docker-compose
$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
$ docker-compose --version

# uninstall
$ sudo rm /usr/local/bin/docker-compose

 

# 도커 허브를 통해서 개별 컨테이너에 대한 정보를 확인해서 docker-compose.yml 파일을 만들면 됩니다.

https://hub.docker.com/

 

Step 3) gitlab 을 설치 합니다.

$ mkdir -p docker/gitlab
$ cd docker/gitlab
$ vi docker-compose.yml
version: '3.1'

services:
  web:
    image: 'gitlab/gitlab-ee:12.8.1-ee.0'
    restart: always
    hostname: 'xxxxx.compute.amazonaws.com'
    environment:
      TZ: "Asia/Seoul"
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'https://xxxxx.compute.amazonaws.com'
        letsencrypt['enable'] = false
        nginx['redirect_http_to_https'] = false
        nginx['listen_https'] = false
        nginx['listen_port'] = 8929
        gitlab_rails['gitlab_shell_ssh_port'] = 2224
    ports:
      - '8929:8929'
      - '2224:22'
    volumes:
      - '/home/ubuntu/docker/gitlab/config:/etc/gitlab'
      - '/home/ubuntu/docker/gitlab/logs:/var/log/gitlab'
      - '/home/ubuntu/docker/gitlab/data:/var/opt/gitlab'

$ docker-compse up -d

- port 정보는 환경에 맞게 수정 하면 됩니다.

- docker compose 의 version 에 따라 yml syntax 가 다를 수 있으니 아래 문서에서 확인 하시면 됩니다.

https://docs.docker.com/compose/compose-file/ 

 

Step 4) redmine 을 설치 합니다.

$ mkdir -p docker/redmine
$ cd docker/redmine
$ vi docker-compose.yml
version: '3.3'

services:
  redmine:
    depends_on:
      - mysql
    image: redmine:4.1.0
    restart: always
    container_name: redmine
    ports:
      - 9292:3000
    environment:
      TZ: "Asia/Seoul"
      REDMINE_DB_MYSQL: mysql
      REDMINE_DB_USERNAME: root
      REDMINE_DB_PASSWORD: ROOT-PASSWORD
      REDMINE_DB_DATABASE: redmine_default
      REDMINE_DB_ENCODING: utf8
      #REDMINE_NO_DB_MIGRATE: true
    volumes:
      - ./data:/usr/src/redmine/files
      - ./plugins:/usr/src/redmine/plugins
      - ./themes:/usr/src/redmine/public/themes
  mysql:
    image: mysql:5.7.29
    container_name: mysql
    ports:
      - 3306:3306
    command:
      - --default-authentication-plugin=mysql_native_password
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
    restart: always
    environment:
      TZ: "Asia/Seoul"
      MYSQL_ROOT_PASSWORD: 'ROOT-PASSWORD'
      MYSQL_DATABASE: 'redmine_default'
    volumes:
      - ./data:/var/lib/mysql

# redmine 에서 사용할 DB 계정 정보는 mysql 을 먼저 구성 한 후 등록 하고 redmine 을 실행 시켜 줘야 정상적으로 동작 합니다.
# 이와 같이 하지 않을 경우 connection 이 안되거나 redmine 용 database 가 없다고 오류를 발생 시킵니다.

- redmine 설치 이전에 mysql 이 먼저 구성이 되어야 합니다.

- redmine 의 mysql 사용자를 별도로 만들어 주는 것이 좋기 때문에 필요 하다면 아래와 같이 수정 하면 됩니다.

services:
    mysql:
        image: mysql
...중략...
		volumes:
            - ./sql/init-redmine.sql:/docker-entrypoint-initdb.d/init-redmine.sql
...중략...


# init-redmine.sql
INSERT INTO `user` (`Host`, `User`, `Select_priv`, `Insert_priv`, `Update_priv`, 
`Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, 
`Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, 
`Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, 
`Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, 
`Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, 
`Create_user_priv`, `Event_priv`, `Trigger_priv`, `Create_tablespace_priv`, 
`ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, 
`max_updates`, `max_connections`, `max_user_connections`, `plugin`, 
`authentication_string`, `password_expired`, `password_last_changed`, 
`password_lifetime`, `account_locked`) 
VALUES ('%','redmine','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y',
'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',
0,0,0,0,'mysql_native_password',password('redmine'),'N',NOW(),NULL,'N')

FLUSH PRIVILEGES;

또는

CREATE USER 'redmine'@'%' IDENTIFIED BY 'redmine';
GRANT ALL PRIVILIEGS ON redmine_default.* TO 'redmine'@'%'

FLUSH PRIVILEGES;

- MySQL 문법 가볍게 한번 보고 넘어 가겠습니다.

CREATE USER '유저아이디'@'접속호스트' IDENTIFIED BY '유저암호';

# 로컬 호스트에서 접속을 허용
CREATE USER '유저아이디'@'localhost' IDENTIFIED BY '유저암호';

# 모든 호스트에서 접속을 허용
CREATE USER '유저아이디'@'%' IDENTIFIED BY '유저암호';

GRANT ALL ON 데이터베이스명.테이블명 TO '유저아이디'@'접속호스트';

# 모든 데이터베이스의 모든 테이블에 대해 로컬호스트로 접속한 유저에게 허용
GRANT ALL ON *.* TO '유저아이디'@'localhost';

# 모든 데이터베이스의 모든 테이블에 대해 모든 호스트로 접속한 유저에게 허용
GRANT ALL ON *.* TO '유저아이디'@'%';

 

Step 5) jenkins 를 설치 합니다.

# python 3.8 최신 버전을 설치 합니다.
# source 로 설치 하는 내용입니다.
$ sudo apt-get install build-essential checkinstall
$ sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev \
    libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev
 
$ cd /opt
$ sudo wget https://www.python.org/ftp/python/3.8.2/Python-3.8.2.tgz
$ sudo tar xzf Python-3.8.2.tgz

$ cd Python-3.8.2
$ sudo ./configure --enable-optimizations
$ sudo make altinstall
$ sudo apt-get install python3-pip 

# 패키지로 설치 하는 내용입니다.
$ sudo add-apt-repository ppa:deadsnakes/ppa
$ sudo apt-get update
$ sudo apt-get install python3.8

# 기본에 3.6.9 와 같이 다른 python3.x 가 설치 되어 있는 경우 설치 하지 않습니다.
$ sudo apt-get install python3.8-dev
$ sudo apt-get install python3.8-distutils

$ sudo apt-get install python3-pip

# virtualenv 가 필요 하다면,
$ pip3 install virtualenv virtualenvwrapper

# Jenkins 설치
$ mkdir -p docker/jenkins
$ cd docker/jenkins
$ vi docker-compose.yml
version: '2'

services:
  jenkins:
    image: 'jenkins/jenkins:lts'
    container_name: 'jenkins'
    restart: always
    ports:
      - '8080:8080'
    volumes:
      - './jenkins_home:/var/jenkins_home'
      - '/home/ubuntu/.ssh:/var/jenkins_home/.ssh'
      - '/home/ubuntu/.aws:/var/jenkins_home/.aws'
    environment:
      TZ: "Asia/Seoul"

$ docker-compose up -d

# 에러 발생
touch: cannot touch '/var/jenkins_home/copy_reference_file.log': Permission denied

$ sudo chown -R 1000:1000 jenkins_home

# Jenkins 에서 awscli 와 boto3 를 사용하기 위한 설치
$ sudo apt install awscli
$ pip3 install boto3

# Jenkins 에서 aws sdk 사용 하기 위한 설정
# host 에 aws configure 설정을 하고 mount 시킵니다.
$ aws configure
$ sudo chmod 666 .aws/config
$ sudo chmod 666 .aws/credentials
$ docker restart jenkins

이제 기본적인 설치는 끝났습니다.

응용은 이제 각자 알아서 해보시기 바랍니다.

:

[Docker] 초보자를 위한 Container 실행/접속/재시작/User변경

Cloud&Container/IaC 2020. 3. 18. 16:55

아주 기본적인 것도 자주 사용하지 않으면 기억이 나지 않습니다.

 

Docker Reference)

https://docs.docker.com/reference/

 

# Container 실행 (-d 데몬으로 실행)

$ docker-compose up -d


# Process 확인

$ docker ps


# Container 에 접속,  Default 가 생성한 도커파일에 user 가 jenkins 로정의 되어 있음

$ docker exec -it ${CONTAINER ID} 또는 ${CONTAINER NAME}
$ docker exec -it 9fbf1f1df70c /bin/bash
$ docker exec -it -u root 9fbf1f1df70c /bin/bash
jenkins@9fbf1f1df70c:/$


# Container 재시작

$ docker start ${CONTAINER ID} 또는 ${CONTAINER NAME}
$ dcoker stop ${CONTAINER ID} 또는 ${CONTAINER NAME}
$ docker restart ${CONTAINER ID} 또는 ${CONTAINER NAME}


# Container 접속 시 user 변경

$ docker exec -it -u root 9fbf1f1df70c /bin/bash

 

:

[Shell] Ubuntu 에서 Reboot 시 자동 스크립트 실행.

ITWeb/개발일반 2020. 3. 17. 11:30

급하게 필요한 것들을 구성 하다 보니 좀 엉성하게 구성이 되어서 챙겨야 할 게 많네요.

Jenkins 를 설치 해 두었는데 instance 가 재부팅 되면 매번 수동으로 실행을 해줘야 해서 자동으로 실행 되도록 서비스 등록을 했습니다.

 

환경)

- Ubuntu

- Jenkins war 설치

 

자동 스크립트 구성)

$ cd /etc/init.d

$ sudo vi jenkins

#! /bin/sh

JENKINS_HOME=/home/mzc/app/jenkins
JENKINS_BIN=$JENKINS_HOME/bin

sudo -u jenkins $JENKINS_BIN/stop.sh
sudo -u jenkins $JENKINS_BIN/start.sh

exit 0

 

$ sudo update-rc.d jenkins defaults

$ sudo reboot

$ service --status-all

 

이제 자동으로 잘 올라 오는지 확인해 보시면 되겠습니다.

:

[AWS] EC2 인스턴스 백업 하기

Cloud&Container/AWS 2020. 3. 16. 17:03

내부에서 사용하는 EC2 인스턴스의 경우 HA 구성까지는 너무 오버라고 생각될 때 최소한의 Backup 정책 정도는 만들어 놓는게 좋습니다.

 

Case 1) 임의 수동 Snapshot 생성

Backup 하고자 하는 Instance 에서 우클릭 후 Snapshot 생성 을 선택 하시면 됩니다.

Selected Instance -> Right Click -> Image -> Create Image

이와 같이 하면 IMAGES 매뉴에서 AMIs  에 생성된 이미지를 보실 수 있습니다.

 

Case 2) 주기적인 자동 Snapshot 생성 (EBS)

EC2 화면에서 수명 주기 관리자(Lifecycle Manager)

Create Snapshot Lifecycle Policy 를 선택해서 필요한 Scheduler 를 만듭니다.

자세한 내용이 궁금한 분들은 공홈 문서를 보시면 좋을 것 같습니다.

https://docs.aws.amazon.com/ko_kr/AWSEC2/latest/UserGuide/ec2-instance-lifecycle.html

https://docs.aws.amazon.com/ko_kr/AWSEC2/latest/UserGuide/ebs-creating-snapshot.html

:

[Gitlab] HTTP Basic: Access denied 해결 하기

ITWeb/개발일반 2020. 3. 16. 16:14

이 에러가 저장된 credential 정보가 틀려서 나는 것일 수도 있고 저 처럼 2FA 설정을 한 경우에 발생을 하는 경우도 있습니다.

 

Case 1) 저장된 Credentail 정보가 틀렸을 경우 아래와 같이 Reset 한번 합니다.

 

$ git config --system --unset credential

 

Case 2) 2FA 설정을 했을 경우 아래와 같이 access token을 생성 해서 Password 대신 사용을 합니다.

remote: HTTP Basic: Access denied
remote: You must use a personal access token with 'read_repository' or 'write_repository' scope for Git over HTTP.
remote: You can generate one at https://gitxxxxx.net/profile/personal_access_tokens

# 매번 입력하기 힘드니까 ID/PWD(Access Tokens) 를 저장해 둡니다.
$ git config --global credential.helper store

 

:

[Redmine] Ubuntu 에 Redmine 설치 하기

ITWeb/개발일반 2020. 3. 16. 13:24

팀에서 사용할 workspace 도구로 뭘 쓸까 하다가 Redmine 으로 결정을 했습니다.

설치는 아래 문서 보시고 따라 하시면 됩니다.

 

[설치 문서]

https://www.redmine.org/projects/redmine/wiki/HowTo_Install_Redmine_on_Ubuntu_step_by_step

 

[설치 환경]

Ubuntu Server 18.04 LTS (HVM), SSD Volume Type 

AWS EC2 c5.xlarge

 

[문서 대로 설치하기 + 일부 수정]

$ sudo apt-get install apache2 libapache2-mod-passenger
$ sudo apt-get install mysql-server mysql-client

# MySQL 설치 이후 최초 root 계정 접속 시 아래와 같이 접속 하여 계정 추가/변경 등의 작업을 수행 합니다.

$ sudo mysql -proot

 

[MySQL root 계정 접근 허용]

INSERT INTO `user` (`Host`, `User`, `Select_priv`, `Insert_priv`, `Update_priv`, 
`Delete_priv`, `Create_priv`, `Drop_priv`, `Reload_priv`, `Shutdown_priv`, 
`Process_priv`, `File_priv`, `Grant_priv`, `References_priv`, `Index_priv`, 
`Alter_priv`, `Show_db_priv`, `Super_priv`, `Create_tmp_table_priv`, 
`Lock_tables_priv`, `Execute_priv`, `Repl_slave_priv`, `Repl_client_priv`, 
`Create_view_priv`, `Show_view_priv`, `Create_routine_priv`, `Alter_routine_priv`, 
`Create_user_priv`, `Event_priv`, `Trigger_priv`, `Create_tablespace_priv`, 
`ssl_type`, `ssl_cipher`, `x509_issuer`, `x509_subject`, `max_questions`, 
`max_updates`, `max_connections`, `max_user_connections`, `plugin`, 
`authentication_string`, `password_expired`, `password_last_changed`, 
`password_lifetime`, `account_locked`) 
VALUES ('%','root','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y',
'Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','Y','','','','',
0,0,0,0,'mysql_native_password',password('************'),'N',NOW(),NULL,'N')
$ sudo apt-get install redmine redmine-mysql
$ sudo gem update
$ sudo gem install bundler

 

[passenger.conf 수정]

$ sudo vi  /etc/apache2/mods-available/passenger.conf

<IfModule mod_passenger.c>
  PassengerRoot /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini
  PassengerDefaultRuby /usr/bin/ruby
  PassengerDefaultUser www-data		  
</IfModule>

문서에는 아래와 같이 수정 하게 되어 있으나 동작 하지 않아서 변경했습니다.

<IfModule mod_passenger.c>
    PassengerDefaultUser www-data
    PassengerRoot /usr
    PassengerRuby /usr/bin/ruby
</IfModule>

 

[ports.conf 수정]

$ sudo vi /etc/apache2/ports.conf

Listen xxxx

# 기본 80 포트를 사용 하나 다른 프로그램에서 사용을 하고 있어서 포트를 수정 하였습니다. 

 

[000-default.conf 수정]

$ sudo vi /etc/apache2/sites-available/000-default.conf

<VirtualHost *:xxxx>
....

    <Directory /var/www/html/redmine>
        RailsBaseURI /redmine
        PassengerResolveSymlinksInDocumentRoot on
    </Directory>
</VirtualHost>

 

[최종 마무리 단계]

$ sudo ln -s /usr/share/redmine/public /var/www/html/redmine
$ sudo touch /usr/share/redmine/Gemfile.lock
$ sudo chown www-data:www-data /usr/share/redmine/Gemfile.lock
$ sudo service apache2 restart

 

[접속]

http://localhost:xxxx/redmine

admin/admin

 

:

[AWS] aws cli 사용 시 --query 알아보기

Cloud&Container/AWS 2020. 3. 13. 21:46

알아 보기라고 하기에는 그냥 약간의 예제와 학습 해야 하는 문서 링크 입니다.

 

https://jmespath.org/specification.html#filter-expressions

$ aws iot list-thing-types --query 'thingTypes[].[thingTypeName, thingTypeName==`1584075120782`]'
$ aws iot list-thing-types --query "thingTypes[].[thingTypeName, starts_with(thingTypeName, '15840')]"

 

JMES 가 이거 만든 사람 이름의 약어 인것 같은데, 맞는지 모르겠네요.

© Copyright 2014-2015, James Saryerwinnie.

 

그리고 이 분 AWS 직원인 것 같습니다. :)

: