Logstash 설치

시스템 2023. 4. 27. 14:49

https://biggongjam.notion.site/Logstash-AWS-EC2-Logstash-7-17-2-b79a2613f6cb4148b8ba0c820b685731

 

Logstash - AWS EC2에서 Logstash 7.17.2 설치 및 실행

작성장 : 김재민

biggongjam.notion.site

 

Siem 로그 시스템 한번 구현해볼 생각이다.

결국은 상용 시스템 도입할 예정이지만 어떻게 돌아가는지 확인해볼 필요는 있다.

 

sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y dist-upgrade

sudo apt-get install -y vim wget unzip ssh openssh-* net-tools
sudo hostnamectl set-hostname logstash01

sudo apt-get install -y openjdk-8-jdk
java -version


sudo find / -name java-8-openjdk-amd64 2>/dev/null
sudo mkdir -p /install_dir && cd /install_dir


pwd
wget https://artifacts.elastic.co/downloads/logstash/logstash-8.2.2-linux-x86_64.tar.gz
ls



sudo tar -zxvf logstash-8.2.2-linux-x86_64.tar.gz -C /usr/local
sudo mv /usr/local/logstash-8.2.2/ /usr/local/logstash
sudo chown -R $USER:$USER /usr/local/logstash && cd /usr/local/logstash


logstash.conf YML CONF 확장자 확인 필수 




ls
clear
ls -al
vi /usr/local/logstash/config/logstash.conf
/usr/local/logstash/bin/logstash -f /usr/local/logstash/config/logstash.conf


ls
vim /usr/local/logstash/config/logstash.conf
/usr/local/logstash/bin/logstash -f /usr/local/logstash/config/logstash.conf
ls
vi config



ls
cd config/
ls
vi logstash.conf
/usr/local/logstash/bin/logstash -f /usr/local/logstash/config/logstash.conf


ls
clear
ls


vi logstash.conf
input {
}
output {



clear
/usr/local/logstash/bin/logstash -f /usr/local/logstash/config/logstash.conf


pwd
ls
ls -al
ps -ef | grep logstash


kill 57810
/usr/local/logstash/bin/logstash -f /usr/local/logstash/config/logstash.conf
ps -ef | grep logstash
kill -9 57810

 

AWS 오픈서치나 엘렉스틱 서치 클라우드 서비스를 받는다고 해도 스토리지 요금이 꽤나 많이 나온다고 한다.

그래서 로컬에서 NAS로 구축이 가능하다면 로컬로 구축해서 쓰는것도 나쁘지 않다고 한다.

 

input {
  http_poller {
    urls => {
            naver => {
            method => get
            url => "https://api.coingecko.com/api/v3/exchanges/upbit"
            }
    }
    request_timeout => 10
    schedule => { cron => "* * * * * UTC " }
    codec => "json"
    metadata_target => "http_poller_metadata"
  }
}

output {
  stdout {
  }
}

 

input {
  http_poller {
    urls => {
      test1 => "https://api.coingecko.com/api/v3/exchanges/upbit"
      test2 => {
        # Supports all options supported by ruby's Manticore HTTP client
        method => get
        url => "https://api.coingecko.com/api/v3/exchanges/upbit"
        headers => {
          Accept => "application/json"
        }
     }
    }
    request_timeout => 10
    # Supports "cron", "every", "at" and "in" schedules by rufus scheduler
    schedule => { cron => "* * * * * UTC"}
    codec => "json"
    # A hash of request metadata info (timing, response headers, etc.) will be sent here
    metadata_target => "http_poller_metadata"
  }
}

 output {
   elasticsearch {
     hosts => "localhost:9200"
         index => "covid_test"
         document_type => "search"
         #document_id => "%{[@metadata][_id]}"
   }
   stdout { codec => rubydebug }
 }

 

 

 

 

 

파싱이 되어온다 indexer를 어떤 방식으로 쓴는지 공부해보자

 

 

'시스템' 카테고리의 다른 글

docker-compse Elasticsearch 설치  (0) 2023.05.18
키바나 설치  (0) 2023.04.28
iptime 공유기 & mesh linksys 콜라보레이션 무선 AP 구성  (0) 2023.04.18
MongoDB Replica Set  (0) 2023.01.10
s3 권한이 없는 경우  (0) 2022.05.17
블로그 이미지

iesay

,

오랜만에 블로그 포스팅이다.

사무실에서 삽질을 하도 많이 해서 기록을 남기려구 한다.

요구사항은 아래와 같다.

- linksys mesh 공유기로 기존에 무선 망이 구성됨 

- iptime A2004MU로 기존 무선망에 추가로 멀티브릿지(리피터) 설정

- 192.168.1.1 (mesh linksys)      192.168.0.1(iptime) 대역대를 합치는 작업 

- 복합기가 유선만 제공하여 같은 대역대에서 iptime 공유기를 활용하여 작업

 

-  고급설정 -> 무선랜관리 -> 무선확장 설정 ->     멀티브릿지(리피터)

    linksys mesh 공유기 ID/ PASSWD 입력    

   인증 및 암호화는 아래 그림과 같이 설정하니 통과

- 재로그인 하면 동적IP는 192.168.1.1 (mesh linksys) 대역대

   URL은 192.168.0.1(iptime) 대역이다. 이걸  브릿지로 모든 사무실이다 192.168.1.1 (mesh linksys)대역대를

   사용하게 하면 된다.

- iptime 공유기에 물려진 내PC의  IP주소이다. 해당 IP주소가 브릿지로 192.168.1.1 (mesh linksys) 대역대로

  인터넷이 되면 성공이다. 

 

고급설정 -> 네트워크 관리 -> 내부네트워크 설정       공유기 IP를  192.168.1.101로 설정

앞으로 공유기는 위 IP로 접속 가능 

내부 IP주소를 192.168.1.1 (mesh linksys) 대역대 주소로 바꿈

아래에 클릭 절대 금지 

 

 

이제 PC에서 랜선을 뽑고 복합기에 설치하면 된다.

192.168.1.1 (mesh linksys)에 복합기를  무선망만 되는 환경에서

유무선공유기 iptime공유기를 달아서 설치를 한것이다.

'시스템' 카테고리의 다른 글

키바나 설치  (0) 2023.04.28
Logstash 설치  (0) 2023.04.27
MongoDB Replica Set  (0) 2023.01.10
s3 권한이 없는 경우  (0) 2022.05.17
프로메테우스 모니터링  (0) 2022.03.30
블로그 이미지

iesay

,

MongoDB Replica Set

시스템 2023. 1. 10. 13:55

출처 : https://devs0n.tistory.com/43

  • 파일 생성

/home/ubuntu/mongod/docker-compose.yml

version: "3.6"

services:
  mongo-1:
    image: mongo:4.4
    container_name: mongo-1
    ports:
      - "30000:30000"
    command: mongod --replSet replset --port 30000 **--bind_ip 0.0.0.0**

  mongo-2:
    image: mongo:4.4
    container_name: mongo-2
    ports:
      - "30001:30001"
    command: mongod --replSet replset --port 30001 **--bind_ip 0.0.0.0**

  mongo-3:
    image: mongo:4.4
    container_name: mongo-3
    ports:
      - "30002:30002"
    command: mongod --replSet replset --port 30002 **--bind_ip 0.0.0.0**

C:\Windows\System32\drivers\etc\hosts 추가 (MongoDB IP)

**192.168.0.53** mongo-1
192.168.0.53 mongo-2
192.168.0.53 mongo-3
시작 
docker compose up &

종료
docker compose down
**도커에 접속** 

docker exec -it mongo-1 mongo --port 30000

**mongod  1 :** PRIMARY
**mongod  2 :** SECONDARY
**mongod  3 :** SECONDARY

> config = {
	"_id" : "replset", // docker-compose에 있는 replSet과 동일하게
	"members" : [
		{
			"_id" : 0,
			"host" : "mongo-1:30000"
		},
		{
			"_id" : 1,
			"host" : "mongo-2:30001"
		},
		{
			"_id" : 2,
			"host" : "mongo-3:30002"
		}
	]
}
 
> rs.initiate(config);
{ "ok" : 1 }

**mongod  1]**
**샘플데이터 입력** 
db.wallets.insert(
  { 
    wid: 4,
    uid: "11e035c6-ed09-4c91-aae7-50a72ea3f344",
    ucPubkey:   "0x029c8804e80db19ffe796746ae70c04f25e137c14b08d3e1ea925b92b734812632", 
    created: "2022-08-11T14:00:51.059Z" 
  }
)

**샘플 데이터 확인**
> db.wallets.find({})
{ "_id" : ObjectId("63acdad42c351689ae8b3af7"), "wid" : 4, "uid" : "11e035c6-ed09-4c91-aae7-50a72ea3f344", "ucPubkey" : "0x029c8804e80db19ffe796746ae70c04f25e137c14b08d3e1ea925b92b734812632", "created" : "2022-08-11T14:00:51.059Z" }
>

  • Robo 3T docker compass 접속 정보 설정
  • docker compass 왼쪽 확인

SECONDARY에 접근하기 위한 명령어

**mongod  2] , mongod  3]**

replset:SECONDARY> rs.slaveOk()
  • mongod 1] , mongod 2] , mongod 3] 데이터 동일 여부 확인
    • 파일 생성
    /home/ubuntu/mongod/docker-compose.ymlC:\Windows\System32\drivers\etc\hosts 추가 (MongoDB IP)
    시작 
    docker compose up &
    
    종료
    docker compose down
    
    **도커에 접속** 
    
    docker exec -it mongo-1 mongo --port 30000
    
    **mongod  1 :** PRIMARY
    **mongod  2 :** SECONDARY
    **mongod  3 :** SECONDARY
    
    > config = {
    	"_id" : "replset", // docker-compose에 있는 replSet과 동일하게
    	"members" : [
    		{
    			"_id" : 0,
    			"host" : "mongo-1:30000"
    		},
    		{
    			"_id" : 1,
    			"host" : "mongo-2:30001"
    		},
    		{
    			"_id" : 2,
    			"host" : "mongo-3:30002"
    		}
    	]
    }
     
    > rs.initiate(config);
    { "ok" : 1 }
    
    **mongod  1]**
    **샘플데이터 입력** 
    db.wallets.insert(
      { 
        wid: 4,
        uid: "11e035c6-ed09-4c91-aae7-50a72ea3f344",
        ucPubkey:   "0x029c8804e80db19ffe796746ae70c04f25e137c14b08d3e1ea925b92b734812632", 
        created: "2022-08-11T14:00:51.059Z" 
      }
    )
    
    **샘플 데이터 확인**
    > db.wallets.find({})
    { "_id" : ObjectId("63acdad42c351689ae8b3af7"), "wid" : 4, "uid" : "11e035c6-ed09-4c91-aae7-50a72ea3f344", "ucPubkey" : "0x029c8804e80db19ffe796746ae70c04f25e137c14b08d3e1ea925b92b734812632", "created" : "2022-08-11T14:00:51.059Z" }
    >
    
    
    • Robo 3T docker compass 접속 정보 설정

    • docker compass 왼쪽 확인

    **mongod  2] , mongod  3]**
    
    replset:SECONDARY> rs.slaveOk()
    
    • mongod 1] , mongod 2] , mongod 3] 데이터 동일 여부 확인

'시스템' 카테고리의 다른 글

Logstash 설치  (0) 2023.04.27
iptime 공유기 & mesh linksys 콜라보레이션 무선 AP 구성  (0) 2023.04.18
s3 권한이 없는 경우  (0) 2022.05.17
프로메테우스 모니터링  (0) 2022.03.30
nginx/1.18.0 (Ubuntu20.04) gzip  (0) 2022.03.07
블로그 이미지

iesay

,

 

 

 

 

 

블로그 이미지

iesay

,

출처

https://ichi.pro/ko/prometheus-mich-grafanaleul-sayonghan-node-js-aepeullikeisyeon-moniteoling-194123578535907

 

const http = require('http')
const url = require('url')
const client = require('prom-client')
// Create a Registry which registers the metrics
const register = new client.Registry()
// Add a default label which is added to all metrics
register.setDefaultLabels({
  app: 'example-nodejs-app'
})
// Enable the collection of default metrics
client.collectDefaultMetrics({ register })
// Create a histogram metric
const httpRequestDurationMicroseconds = new client.Histogram({
  name: 'http_request_duration_seconds',
  help: 'Duration of HTTP requests in microseconds',
  labelNames: ['method', 'route', 'code'],
  buckets: [0.1, 0.3, 0.5, 0.7, 1, 3, 5, 7, 10]
})
// Register the histogram
register.registerMetric(httpRequestDurationMicroseconds)
// Define the HTTP server
const server = http.createServer(async (req, res) => {
    // Start the timer
  const end = httpRequestDurationMicroseconds.startTimer()
// Retrieve route from request object
  const route = url.parse(req.url).pathname
if (route === '/metrics') {
    // Return all metrics the Prometheus exposition format
    res.setHeader('Content-Type', register.contentType)
    res.end(register.metrics())
  }
// End timer and add labels
  end({ route, code: res.statusCode, method: req.method })
})
// Start the HTTP server which exposes the metrics on http://localhost:8080/metrics
server.listen(8080)

nodejs server.js

 

프로메테우스 설치 

#apt install prometheus

#cd /etc/prometheus

#vi prometheus.yml

global:
  scrape_interval: 5s
scrape_configs:
  - job_name: "example-nodejs-app"
    static_configs:
      - targets: ["localhost:8080"]

#service prometheus restart

 

prometheus_http_request_duration_seconds_bucket

프로메테우스 실행 완료  

 

Grafana

#cd /etc/prometheus

#vi datasources.ym


apiVersion: 1
datasources:
  - name: Prometheus
    type: prometheus
    access: proxy
    orgId: 1
    url: http://docker.for.mac.host.internal:9090
    basicAuth: false
    isDefault: true
    editable: true

 


docker run --rm -p 3000:3000 \
  -e GF_AUTH_DISABLE_LOGIN_FORM=true \
  -e GF_AUTH_ANONYMOUS_ENABLED=true \
  -e GF_AUTH_ANONYMOUS_ORG_ROLE=Admin \
  -v `pwd`/datasources.yml://etc/prometheus \
  grafana/grafana-enterprise:8.3.6-ubuntu


 

 

'시스템' 카테고리의 다른 글

MongoDB Replica Set  (0) 2023.01.10
s3 권한이 없는 경우  (0) 2022.05.17
nginx/1.18.0 (Ubuntu20.04) gzip  (0) 2022.03.07
nginx/1.18.0 (Ubuntu20.04) brotli  (0) 2022.01.11
Gitlab CI react app 배포  (0) 2021.12.31
블로그 이미지

iesay

,

wasm 파일에  gzip을 적용하는게 목표 타입 추가

cd /etc/nginx

vi mime.types

application/xspf+xml xspf;
application/zip zip;
application/wasm wasm;

 

nginx.conf  http 부분에서 내용 변환

cd /etc/nginx

vi nginx.conf


        ##
        # Gzip Settings
        ##
        gzip on;
        gzip_disable "msie6";

        gzip_comp_level 6;
        gzip_min_length 500;
        gzip_buffers 16 8k;
        gzip_proxied any;
        gzip_types text/plain text/css text/js text/xml text/javascript application/javascript application/x-javascript application/json application/xml application/rss+xml application/wasm image/svg+xml image/png;


nginx 재부팅

nginx -t

service nginx restart

 

 

gzip on;
gzip_static on;
gzip_disable     "msie6"; # 자동으로 IE6, 5.5를 감지해서 disable한다.
# gzip_disable "MSIE [1-6]\.(?!.*SV1)"; # nginx 0.7 이하에서만
gzip_types application/x-javascript application/javascript application/xml text/javascript application/json text/json text/css text/plain application/xhtml+xml application/rss+xml application/wasm ;

개발자 도구에서 동작 확인

'시스템' 카테고리의 다른 글

s3 권한이 없는 경우  (0) 2022.05.17
프로메테우스 모니터링  (0) 2022.03.30
nginx/1.18.0 (Ubuntu20.04) brotli  (0) 2022.01.11
Gitlab CI react app 배포  (0) 2021.12.31
AWS Amplify 설치  (0) 2021.12.28
블로그 이미지

iesay

,

 

출처 : https://gist.github.com/jivanpal/ce90c0d34ead57bc33d10099278ab423

        https://stackoverflow.com/questions/43862412/why-is-brotli-not-supported-on-http

 

Why is Brotli not supported on HTTP?

I noticed an odd thing where apparently Firefox says it supports Brotli on HTTPS, but not HTTP? As Brotli is like gzip but more efficient, why would it limit it to HTTPS? On a HTTPS tab I see: Acc...

stackoverflow.com

환경 : nginx/1.18.0 (Ubuntu20.04) brotli

        https에서만 동작

 

출처에 있는 셀 스크립트 소스르 vi해서 파일을 만든다.

vi compile-nginx-brotli-modules.sh
chmod 777 compile-nginx-brotli-modules.sh
./compile-nginx-brotli-modules.sh

 

디렉토리 이동후 SO파일을 복사 한다.

cd /root/build/nginx-1.18.0/objs

cp *.so /usr/lib/nginx/modules/

cp *.so /usr/share/nginx/modules

vi /etc/nginx/nginx.conf

최상단에 추가

load_module modules/ngx_http_brotli_filter_module.so;
load_module modules/ngx_http_brotli_static_module.so;

vi /etc/nginx/nginx.conf     http 안에 추가 

brotli on;
brotli_comp_level 6;
brotli_types text/plain text/css application/javascript application/x-javascript text/xml application/xml application/wasm application/xml+rss text/javascript image/x-icon image/vnd.microsoft.icon image/bmp image/svg+xml;
brotli_static on;

 

nginx 재부팅 

nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
service nginx restart

 

 

개발자 도구 네트워크 탭에서 확인 할수 있다.

 

적용 전 

 

 

적용 후 

 

 

'시스템' 카테고리의 다른 글

프로메테우스 모니터링  (0) 2022.03.30
nginx/1.18.0 (Ubuntu20.04) gzip  (0) 2022.03.07
Gitlab CI react app 배포  (0) 2021.12.31
AWS Amplify 설치  (0) 2021.12.28
ipfs 사용법  (0) 2021.12.06
블로그 이미지

iesay

,

출처 : https://merrily-code.tistory.com/123

환경 :  AWS LigthSail  8코어 32기가 램 

        Docker 제외하고 nginx에 바로 다이렉트로 deploy

 

 

 

 

 

shell로 등록 

gitlab-runner register -n \
--url https://gitlab.com/ \
--registration-token M9토큰값 \
--description gitlab-runner \
--executor shell

'시스템' 카테고리의 다른 글

nginx/1.18.0 (Ubuntu20.04) gzip  (0) 2022.03.07
nginx/1.18.0 (Ubuntu20.04) brotli  (0) 2022.01.11
AWS Amplify 설치  (0) 2021.12.28
ipfs 사용법  (0) 2021.12.06
gitlab ci Docker 연동(React)  (0) 2021.11.24
블로그 이미지

iesay

,

AWS Amplify 설치

시스템 2021. 12. 28. 15:18

'시스템' 카테고리의 다른 글

nginx/1.18.0 (Ubuntu20.04) brotli  (0) 2022.01.11
Gitlab CI react app 배포  (0) 2021.12.31
ipfs 사용법  (0) 2021.12.06
gitlab ci Docker 연동(React)  (0) 2021.11.24
gitlab CI_SERVER_TLS_CA_FILE: Permission denied  (0) 2021.08.30
블로그 이미지

iesay

,

ipfs 사용법

시스템 2021. 12. 6. 15:47

출처 : https://miiingo.tistory.com/204

https://zooyeonii.tistory.com/7

https://bl.ocks.org/kevin-smets/75f717f22a55ac628744c830c9d6b491

https://simpleaswater.com/ipfs-going-online/

 

#ipfs config show 

{
  "API": {
    "HTTPHeaders": {
      "Server": [
        "go-ipfs/0.4.17"
      ]
    }
  },
  "Addresses": {
    "API": "/ip4/127.0.0.1/tcp/5001",
    "Announce": [],
    "Gateway": "/ip4/127.0.0.1/tcp/8080",
    "NoAnnounce": [],
    "Swarm": [
      "/ip4/0.0.0.0/tcp/4001",
      "/ip6/::/tcp/4001"
    ]
  },

 

외부 접근 가능  

#ipfs config Addresses.API /ip4/0.0.0.0/tcp/5001
#ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/8080


#export LIBP2P_FORCE_PNET=1
ipfs daemon 실행 중인 것을 중지하고 다시 시작한다. 


#ipfs shutdown
#ipfs daemon > ipfs.log &

root@server:~# 06:51:37.225 ERROR p2p-config: tried to create a libp2p node with no Private Network Protector but usage of Private Networks is forced by the enviroment config.go:66
06:51:37.226 ERROR   cmd/ipfs: error from node construction: privnet: private network was not configured but is enforced by the environment daemon.go:332
Error: privnet: private network was not configured but is enforced by the environment

[1]+  Exit 1                  ipfs daemon > ipfs.log
root@server:~#

 

'시스템' 카테고리의 다른 글

Gitlab CI react app 배포  (0) 2021.12.31
AWS Amplify 설치  (0) 2021.12.28
gitlab ci Docker 연동(React)  (0) 2021.11.24
gitlab CI_SERVER_TLS_CA_FILE: Permission denied  (0) 2021.08.30
gitlab ci Docker 연동(nodejs)  (2) 2021.08.23
블로그 이미지

iesay

,