Total: Today: Yesterday:
노하우/Linux | 2021. 7. 22. 12:10 | Posted by 자수씨

top이라는 명령어만으로는 머신 상태를 확인하기에는 부족함이 있다.

페이스북에서 과거의 오늘이라며 8년 전 글을 보여줬는데 지금 봐도 충격과 공포이다.

 

 

요즘에는 AWS EC2 머신을 주로 사용하므로 해당 머신에 설치하는 방법을 공유하고자 한다.

 

htop

top의 대안으로 나온 프로그램으로 c언어로 된 오픈소스이다. Ncurses를 이용하여 키보드 커서도 이용할 수 있다.

 

 

설치 방법은 간단하다.

 

# 설치
sudo install -y htop

# 실행
htop

 

iotop

프로세스 별 io 통계를 볼 수 있는 프로그램이다.

 

 

이것 또한 설치 방법은 간단하다. 실행 시에는 root 권한이 필요하여 sudo를 이용한다.

 

# 설치
sudo yum install -y iotop

# 실행
sudo iotop

 

iftop

네트워크 연결 목록 및 상태를 보여주는 프로그램이다. 실시간 트래픽 확인에 도움이 된다.

 

 

EC2의 경우 기본적으로 EPEL 리포지토리가 활성화가 되어 있지 않기 때문에 다음과 같은 설정이 필요하다.

 

# 1. EC2 리눅스 버전 확인
cat /etc/-release

# 2-1. Amazon Linux AMI 2018.03 의 경우
sudo yum-config-manager --enable epel

# 2-2. Amazon Linux 2 의 경우
sudo sudo yum-config-manager --enable epel

# 3. epel-release 설치
sudo yum install epel-release

# 4. iftop 설치
sudo yum install iftop

# 실행
sudo iftop

 

iotop 과 마찬가지로 root 권한이 요구되어 실행시 sudo를 이용한다.

노하우/Linux | 2020. 5. 31. 19:36 | Posted by 자수씨

1. yum 을 최신으로 업데이트 한 후에 gcc 와 make 를 설치한다.

$ sudo yum update
$ sudo yum install gcc make

 

2. 레디스 최신 버전 소스를 내려받아 빌드한다.

$ wget http://download.redis.io/releases/redis-6.0.4.tar.gz
$ tar xzf redis-6.0.4.tar.gz
$ cd redis-6.0.4
$ make

 

3. 디렉토리 생성 및 복사

$ sudo mkdir /etc/redis 
$ sudo mkdir /var/lib/redis
$ sudo cp src/redis-server src/redis-cli /usr/local/bin/
$ sudo cp redis.conf /etc/redis/

 

4. /etc/redis/redis.conf 수정

daemonize yes
bind 0.0.0.0
dir /var/lib/redis
logfile "/var/log/redis_6379.log"

 

5. 자동 실행을 위한 설정

$ cd /tmp
$ wget https://raw.github.com/saxenap/install-redis-amazon-linux-centos/master/redis-server
 
$ sudo mv redis-server /etc/init.d
$ sudo chmod 755 /etc/init.d/redis-server

$ sudo chkconfig --add redis-server
$ sudo chkconfig --level 345 redis-server on

 

6. redis 서버 실행

$ sudo service redis-server start
Starting redis-server (via systemctl):                 [  OK  ]

 

참고자료:

1. https://redis.io/download

 

Redis

*Download Redis uses a standard practice for its versioning: major.minor.patchlevel. An even minor marks a stable release, like 1.2, 2.0, 2.2, 2.4, 2.6, 2.8. Odd minors are used for unstable releases, for example 2.9.x releases are the unstable versions of

redis.io

2. https://github.com/saxenap/install-redis-amazon-linux-centos

 

saxenap/install-redis-amazon-linux-centos

his is a installation script to setup Redis 2.6 as a service on Amazon Linux AMI and CentOS distributions. - saxenap/install-redis-amazon-linux-centos

github.com

 

'노하우 > Linux' 카테고리의 다른 글

[EC2] htop, iftop, iotop  (0) 2021.07.22
[scouter] AWS EC2 인스턴스에 scouter-paper 설치하기  (0) 2019.04.23
[AWS] EC2 인스턴스에 nodejs 설치  (0) 2019.04.23
Linux 에 OpenJDK 8 설치  (0) 2019.04.13
포트 우회하기  (0) 2019.04.12

노하우/Server | 2020. 5. 31. 18:58 | Posted by 자수씨

웹소켓 서버를 nginx 를 통해 포워딩을 하려고 단순하게 아래와 같이 서버 설정을 할 경우 정상적으로 처리가 되지 않는다.

    server {
        ...

        # forward {context-path}
        location /{context-path}/ {
            proxy_pass http://localhost:{port}/{context-path}/;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "Upgrade";
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
        }

아래와 같이 map 설정을 해주어야 정상동작을 한다.

    map $http_upgrade $connection_upgrade {
        default upgrade;
        ''      close;
    }

    server {
        ...

 

참고자료: http://nginx.org/en/docs/http/websocket.html

'노하우 > Server' 카테고리의 다른 글

[MongoDB] CentOS 7에 설치하기  (0) 2019.08.10
[scouter] AWS EC2 인스턴스에 scouter 설치하기  (1) 2019.04.19

노하우/Server | 2019. 8. 10. 18:34 | Posted by 자수씨

1. yum repository 에 MongoDB 추가

# vi /etc/yum.repos.d/mongodb.repo

/etc/yum.repos.d/mongodb.repo

[MongoDB]
name=MongoDB Repository
baseurl=http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=0
enabled=1

2. MongoDB 서버 설치

# yum install mongodb-org

설치하는 시점(2019.08.10)에는 4.0.12 버전으로 설치가 되었습니다.

Installed:
  mongodb-org.x86_64 0:4.0.12-1.el7                                                                                                                                                                     

Dependency Installed:
  mongodb-org-mongos.x86_64 0:4.0.12-1.el7          mongodb-org-server.x86_64 0:4.0.12-1.el7          mongodb-org-shell.x86_64 0:4.0.12-1.el7          mongodb-org-tools.x86_64 0:4.0.12-1.el7

3. MongoDB 서비스 시작

MongoDB 서비스를 시작하기 위해서는 아래와 같은 명령어를 입력합니다.

# systemctl start mongod.service

시스템 부팅 시에 자동으로 시작되게 하기 위해서 아래의 명령어를 입력합니다.

# systemctl enable mongod.service

서비스가 시작된 후 버전 확인을 위해서는 다음 명령을 통해 확인 가능합니다.

# mongod --version
db version v4.0.12
git version: **
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
    distmod: rhel70
    distarch: x86_64
    target_arch: x86_64

참고자료

'노하우 > Server' 카테고리의 다른 글

[nginx] websocket forwarding  (0) 2020.05.31
[scouter] AWS EC2 인스턴스에 scouter 설치하기  (1) 2019.04.19

노하우/WAS | 2019. 5. 23. 16:36 | Posted by 자수씨

Apache Http Server 나 Nginx 에서 사용하던 인증서를 Tomcat 에서 사용하려고 보니 바로 적용이 안되군요...
(pkcs12 형식으로 변환이 필요)

./chainca.crt
./mydomain.com.crt
./mydomain.com.key

위와 같이 체인인증서와 ROOT 인증서가 합쳐저 있는 chainca.crt 와 도메인의 인증서가 있는 mydomain.com.crt 를 하나의 파일로 합쳐 줍니다.

$ cat mydomain.com.crt chainca.crt > mydomain.com.chainca.crt

openssl 을 이용하여 pkcs12 형식으로 변환합니다.

$ openssl pkcs12 -export -in mydomain.com.chainca.crt -inkey mydomain.com.key -out mydomain.com.p12 -name tomcat
Enter Export Password: (key 파일 암호입력)
Verifying – Enter Export Password: (key 파일 암호입력)

정상적으로 변환을 확인하려면 아래 명령어를 이용합니다.

$ keytool -list -v -keystore mydomain.com.p12 -storetype pkcs12

$CATALINA_HOME/conf/server.xml

아래와 같이 커넥터를 추가합니다.

<Connector port="{SSL포트}" maxHttpHeaderSize="8192"
           maxThreads="150" enableLookups="false" acceptCount="100"
           connectionTimeout="20000" disableUploadTimeout="true"
           protocol="org.apache.coyote.http11.Http11NioProtocol"
           SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS"
           keystoreFile="{인증서 경로}"
           keystoreType="PKCS12" keystorePass="{인증서 패스워드}"/>

해당 포트로 정상적으로 접근하면 설정 완료입니다.

참고자료

노하우/Jenkins | 2019. 5. 1. 17:45 | Posted by 자수씨

설정이 복잡한 jenkins job 을 다른 jenkins 서버에 이관할 경우 jenkins-cli 를 통해 쉽게 진행할 수 있습니다.

Jenkins 관리 > Jenkins CLI 에 들어가면 가능한 명령어들을 볼 수 있습니다.

우측 상단에 jenkins-cli.jar 를 내려받아 다음과 같이 실행합니다.

java -jar jenkins-cli.jar -s <jenkins 서버 IP:Port> <명령어>

만약 로그인이 필요한 서버일 경우 다음과 같이 계정 정보를 입력합니다.

java -jar jenkins-cli.jar -s <jenkins 서버 IP:Port> -auth <아이디>:<패스워드> <명령어>

기존 jenkins 서버에서 job 정보를 xml 로 내려받기 위해 get-job 명령어를 이용합니다.

java -jar jenkins-cli.jar -s http://localhost:8080/ -auth user:password get-job myjob > myjob.xml

get-job 명령어는 xml 로 job 정보를 stdout 으로 내보내기 때문에 > 을 이용하여 파일에 저장합니다.

<?xml version='1.1' encoding='UTF-8'?>
<maven2-moduleset plugin="maven-plugin@3.1.2">
  <actions/>
  <description></description>
  <keepDependencies>false</keepDependencies>
  <properties>
    <com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty plugin="gitlab-plugin@1.5.6">
      <gitLabConnection></gitLabConnection>
    </com.dabsquared.gitlabjenkins.connection.GitLabConnectionProperty>
    <jenkins.model.BuildDiscarderProperty>
      <strategy class="hudson.tasks.LogRotator">
        <daysToKeep>20</daysToKeep>
        <numToKeep>20</numToKeep>
        <artifactDaysToKeep>-1</artifactDaysToKeep>
        <artifactNumToKeep>-1</artifactNumToKeep>
      </strategy>
    </jenkins.model.BuildDiscarderProperty>
  </properties>
  ...
<maven2-moduleset>

이관할 jenkins 서버에 job 을 생성하기 위해 create-job 명령어를 이용합니다.

java -jar jenkins-cli.jar -s http://localhost:9080/ -auth user:password create-job myjob < myjob.xml
ERROR: Unexpected exception occurred while performing create-job command.
javax.xml.transform.TransformerException: org.xml.sax.SAXParseException; lineNumber: 2; columnNumber: 1; Content is not allowed in prolog.

위와 같은 오류가 발생한다면 xml 에서 <?xml version='1.1' encoding='UTF-8'?> 부분을 제거한 후 다시 실행합니다.

성공적으로 job 이 생성되었다면 서버 환경에 따른 차이점 부분만 조정해주면 됩니다.

노하우/Linux | 2019. 4. 23. 00:25 | Posted by 자수씨

지난번 포스팅 에서 내려받았던 scouter 에 paper 기능을 설치하였습니다.

webapps 설정

인증된 사용자만 노출할 것이므로 net_http_api_auth_bearer_token_enabled 설정을 해주고 collector 서버 설정도 합니다.

net_collector_ip_port_id_pws=127.0.0.1:6100:<계정>:<패스워드>
net_http_port=6180
net_http_api_auth_bearer_token_enabled=true

/scouter/webapps 에서 ./startup.sh 로 실행을 하면 아래와 같이 지정된 포트로 LISTEN 상태를 확인할 수 있습니다.

[ec2-user@~ webapp]$ netstat -na | grep LISTEN
...
tcp        0      0 :::6180                     :::*                        LISTEN    

nat 설정으로 외부포트를 내부 6180 연결하여 로그인이 정상적으로 되지 않습니다.

네트워크 탭을 보면 loginGetToken 에서 오류가 납니다. (외부포트와 내부포트가 달라서 발생하는 문제)

scouter-paper 수정

github 에서 소스를 내려받은 후 강제로 외부포트를 설정하였습니다. 그리고 빌드 후 다시 webapps/extweb 에 배포

/src/App.js

componentWillMount() {
    ...

    // URL로부터 스카우터 서버 정보를 세팅
    let params = getParam(this.props, "address,port,protocol,authentification");
    if (params[0] && params[1]) {
        let paramAddress = params[0];
        let paramPort = params[1];
        let paramProtocol = params[2] ? params[2] : "http";
        let paramAuthentification = params[3] ? params[3] : "none";

        let found = false;
        for (let i=0; i<config.servers.length; i++) {
            let server = config.servers[i];
            if (server.protocol === paramProtocol && server.address === paramAddress && String(server.port) === String(paramPort) && server.authentification === paramAuthentification) {
                found = true;
                server.default = true;
            } else {
                server.default = false;
            }
        }

        if (!found) {
            config.servers.push({
                protocol: paramProtocol,
                address: paramAddress,
                port: paramPort,
                authentification :paramAuthentification,
                default : true
            });
        }
    }

    config.servers[0].port = <외부포트>;

    if (config && config.servers) {
        config.servers.forEach((server) => {
            server.name = server.protocol + "://" + server.address + ":" + server.port
        });
    }
    ...
}

정상적으로 접근이 됩니다.

'노하우 > Linux' 카테고리의 다른 글

[EC2] htop, iftop, iotop  (0) 2021.07.22
[Redis] AWS EC2 인스턴스에 redis-server 설치  (0) 2020.05.31
[AWS] EC2 인스턴스에 nodejs 설치  (0) 2019.04.23
Linux 에 OpenJDK 8 설치  (0) 2019.04.13
포트 우회하기  (0) 2019.04.12

노하우/Linux | 2019. 4. 23. 00:16 | Posted by 자수씨

nvm(노드 버전 관리자)을 설치

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.0/install.sh | bash

nvm 활성화

. ~/.nvm/nvm.sh

npm 설치

2019년 4월 23일 기준 10.15.3 버전이 최신이므로 해당 버전을 설치

[ec2-user@~~]$ nvm install 10.15.3
########################################################################################################################################################################################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v10.15.3 (npm v6.4.1)
Creating default alias: default -> 10.15.3 (-> v10.15.3)

버전 확인

[ec2-user@~~]$ node -e "console.log('Running Node.js ' + process.version)"
Running Node.js v10.15.3

참고자료

노하우/Server | 2019. 4. 19. 22:47 | Posted by 자수씨

스카우터 설치

2019.04.19 기준 2.6.1 버전으로 설치

서버 (collector) 설치

서버만 돌릴 거면 agent 는 제거

$ wget https://github.com/scouter-project/scouter/releases/download/v2.6.1/scouter-all-2.6.1.tar.gz
$ tar xzf scouter-all-2.6.1.tar.gz

$ cd scouter
$ rm -rf agent.*

scouter/server/conf/scouter.conf 설정 (6180 은 api 서버에서 쓸 예정이므로 다른 포트로 변경해준다.)

# Agent Control and Service Port(Default : TCP 6100)
net_tcp_listen_port=6100

# UDP Receive Port(Default : 6100)
net_udp_listen_port=6100

# Http Port for scouter-pulse(Default : 6180)
net_http_port=6101

# DB directory(Default : ./database)
db_dir=/<스토리지경로>/scouter/database

# Log directory(Default : ./logs)
log_dir=/<스토리지경로>/scouter/logs

실행법은 startup.sh 로 한다. (java 가 설치안된 경우에는 별도로 설치)

[ec2-user@~~ server]$ ./startup.sh 
nohup: redirecting stderr to stdout
  ____                  _            
 / ___|  ___ ___  _   _| |_ ___ _ __ 
 \___ \ / __/   \| | | | __/ _ \ '__|
  ___) | (_| (+) | |_| | ||  __/ |   
 |____/ \___\___/ \__,_|\__\___|_|                                      
 Open Source S/W Performance Monitoring  
 Scouter version 2.6.1

[ec2-user@~~ server]$ netstat -na | grep LISTEN    
tcp        0      0 :::6100                     :::*                        LISTEN      
tcp        0      0 :::6101                     :::*                        LISTEN      

client 에서 정상적으로 접근되면 서버는 설치 완료

에이전트 (agent.host) 설치

리눅스 서버에 agent.host 를 설치할 예정이므로 min 버전을 다운 받아 설치한다.
(server 는 필요 없으므로 제거)

$ wget https://github.com/scouter-project/scouter/releases/download/v2.6.1/scouter-min-2.6.1.tar.gz
$ tar xzf scouter-min-2.6.1.tar.gz

$ cd scouter
$ rm -rf server

scouter/agent.host/conf/scouter.conf 설정

obj_name=<agent이름>
net_collector_ip=<collector IP>
net_collector_udp_port=6100
net_collector_tcp_port=6100
#cpu_warning_pct=80
#cpu_fatal_pct=85
#cpu_check_period_ms=60000
#cpu_fatal_history=3
#cpu_alert_interval_ms=300000
#disk_warning_pct=88
#disk_fatal_pct=92

scouter/agent.host 에서 ./host.sh 로 실행시킨다.

[ec2-user@ip~~ agent.host]$ ./host.sh 
nohup: redirecting stderr to stdout
  ____                  _            
 / ___|  ___ ___  _   _| |_ ___ _ __ 
 \___ \ / __/   \| | | | __/ _ \ '__|
  ___) | (_| (+) | |_| | ||  __/ |   
 |____/ \___\___/ \__,_|\__\___|_|                                      
 Open Source S/W Performance Monitoring  
 Scouter version 2.6.1

Configure -Dscouter.config=./conf/scouter.conf
Scouter Host Agent Version 2.6.1 2019-03-17 08:45 GMT
System JRE version : 1.8.0_201

클라이언트에 정상적으로 host 정보가 집계되면 성공

에이전트 (agent.java) 설치

데이터를 집계할 WAS 는 Tomcat 이기 때문에 catalina.sh 에 다음과 같이 추가한다.

$CATALINA_HOME/bin/catalina.sh

# scouter settings
JAVA_OPTS="$JAVA_OPTS -javaagent:/home/ec2-user/scouter/agent.java/scouter.agent.jar"

Tomcat 을 재시작 하면 collector 쪽에 데이터를 전송한다.

참고자료

http://gunsdevlog.blogspot.com/2017/07/scouter-apm-1.html

'노하우 > Server' 카테고리의 다른 글

[nginx] websocket forwarding  (0) 2020.05.31
[MongoDB] CentOS 7에 설치하기  (0) 2019.08.10

노하우/Linux | 2019. 4. 13. 12:28 | Posted by 자수씨

EC2 인스턴스나 리눅스 기본 패키지에는 아직까지 JRE 1.7 이 설치되어 있는 경우가 많다.

$ java -version
java version "1.7.0_191"
OpenJDK Runtime Environment (amzn-2.6.15.4.82.amzn1-x86_64 u191-b01)
OpenJDK 64-Bit Server VM (build 24.191-b01, mixed mode)

 

다음과 같이 yum 을 이용하여 OpenJDK 8 을 설치한다.

$ sudo yum install -y java-1.8.0-openjdk-devel.x86_64

 

여러 JRE 가 설치된 경우 OS 에서 관리하는 java 를 설정하도록 아래와 같이 수행한다.

$ sudo alternatives --config java

There are 2 programs which provide 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java
    2           /usr/lib/jvm/jre-1.8.0-openjdk.x86_64/bin/java

Enter to keep the current selection[+], or type selection number: 2

 

불필요한 JRE 7 은 제거한다.

$ sudo yum remove java-1.7.0-openjdk

 

참고자료

 

centos에서 java version관리 (alternatives 사용)

 

blog.seotory.com