# network session check
ss -ant | awk '{print $1}' | grep -v '[a-z]' | sort | uniq -c

# resource limit check
ulimit -a
/etc/security/limits.conf
sudo prlimit --nofile --output RESOURCE,SOFT,HARD --pid $PID

'System Engineering > Linux' 카테고리의 다른 글

KVM virtual machine setting  (0) 2020.06.26
Nginx: How to purge the proxy cache  (0) 2020.05.25
Ubuntu apt-get upgrade  (0) 2019.12.13
Logstash - filebeat SSL settings  (0) 2019.11.26
Buffers and cache in memory (Linux)  (0) 2019.11.11

Host machine setting

$ sudo apt-get install -y qemu qemu-kvm libvirt-daemon bridge-utils virt-manager virtinst libguestfs-tools nmap

$ virsh net-list --all

 

# start default network

$ virsh net-start default

$ virsh net-list

 

You can check the bridge network on hostmachine like 'virbr0'.

Install guest VM with OS: ubuntu 18.04

Install OS on guest VM with ubuntu 18.04, 2 vCPUs, 4GB RAM, 30GB disk in CLI environment using ISO os image.

$ virt-install --name vm-1 --ram 4096 --vcpus 2 --disk ~/vm-1.img,size=30 --os-type linux --os-variant ubuntu18.04 --network bridge=virbr0 --graphics none --console pty,target_type=serial --location ~/ubuntu-18.04.3-server-amd64.iso --extra-args 'console=ttyS0,115200n8 serial'

 

Open-ssh server must be installed during the process.

Connect VM via console

You can check the VM's IP through this command.

$ sudo nmap -sP [virbr0 CIDR] (192.168.0.0/24)

 

$ ssh user@VMIP

$ sudo systemctl enable serial-getty@ttyS0.service && sudo systemctl start serial-getty@ttyS0.service

 

$ virsh list --all

$ virsh connect vm-1

 

 

 

 

'System Engineering > Linux' 카테고리의 다른 글

bash] system check  (0) 2022.03.28
Nginx: How to purge the proxy cache  (0) 2020.05.25
Ubuntu apt-get upgrade  (0) 2019.12.13
Logstash - filebeat SSL settings  (0) 2019.11.26
Buffers and cache in memory (Linux)  (0) 2019.11.11

Clearing nginx proxy cache manually

운영중인 nginx에 캐시 설정이 되어있을 때, 해당 캐시 데이터를 퍼지(삭제) 시키고 싶을 경우

 

1. Find proxy_cache_path settings on nginx configuration.
nginx 설정 파일 (nginx.conf 등의 설정 파일)내의 proxy_cache_path 설정 부분을 찾아 변경해 준다.

# Example
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=edge-cache:10m inactive=600m max_size=1g;

2. Remove the files or directory under the configured cache path.
해당 디렉토리 내의 내용물들을 삭제해 준다. (예제의 경우 /var/cache/nginx 하위의 모든 데이터)

3. Reload nginx

nginx -s reload

PS. If you using nginx+, just curl with PURGE.
만약, NGINX+를 사용하고 있다면 curl 또는 wget 등을 이용해 PURGE 메소드를 날려준다.

curl -H -X PURGE [URL]

 

'System Engineering > Linux' 카테고리의 다른 글

bash] system check  (0) 2022.03.28
KVM virtual machine setting  (0) 2020.06.26
Ubuntu apt-get upgrade  (0) 2019.12.13
Logstash - filebeat SSL settings  (0) 2019.11.26
Buffers and cache in memory (Linux)  (0) 2019.11.11

리눅스 커널 이미지 업데이트 시 systemd에서 Network Service 재시작이 발생할 수 있음

리눅스 Heartbeat 서비스를 사용한 Active / Stand-by 구성에서 해당 작업 시 순차적으로 진행해야 하며, Ansible 등의 병렬 작업을 할 경우, 동시에 네트워크 서비스가 재시작 되며 fail over가 정상적으로 동작하지 않을 수 있음.

 

When updating linux kernel image with 'apt-get upgrade' on ubuntu system, you should aware of that the network service on the host could be restarted. This could be disaster to some network topology. For example, doing some task something like Ansible which execute jobs paratactically on Active-Standby system with Heartbeat service. That may cause restarting network service at subjects at the same time.

'System Engineering > Linux' 카테고리의 다른 글

KVM virtual machine setting  (0) 2020.06.26
Nginx: How to purge the proxy cache  (0) 2020.05.25
Logstash - filebeat SSL settings  (0) 2019.11.26
Buffers and cache in memory (Linux)  (0) 2019.11.11
Check the disk type in linux (ubuntu)  (0) 2019.11.07

Filebeat에서 Logstash로 데이터 전송 시 ssl 설정

Create instance file for elasticsearch-certutil

logstash 노드에서 elasticsearch-certutil 명령어와 instance 파일을 사용하여 p12 파일 생성

# vi instance.yml

instances:
  - name: "logstash"
    ip:
      - "192.168.1.2"

Create p12 cert file from elasticsearch-certutil and instance.yml

# /usr/share/elasticsearch/bin/elasticsearch-certutil cert --in instance.yml --silent --out certs.zip
# cd /DIR_TO_LOGSTASH/cert && unzip ~/certs.zip -d ./
# ls
logstash.p12

Create key and crt file from p12

openssl 명령어로 crt, key 파일 생성

# openssl pkcs12 -in logstash.p12 -out logstash.crt -clcerts -nokeys
# openssl pkcs12 -in logstash.p12 -out logstash.key -nocerts -nodes

Edit each configuration

Logstash
vi logstash.yml
input {
  beats {
...
    ssl => true
    ssl_certificate => "/[LOGSTASH]/cert/logstash.crt"
    ssl_key => "/[LOGSTASH]/cert/logstash.key"
...

Filebeat
vi filebeat.yml
output.logstash:
...
  ssl.certificate: "/[FILEBEAT]cert/logstash.crt"
  ssl.key: "/[FILEBEAT]/cert/logstash.key"
  ssl.certificate_authorities: ["/[FILEBEAT]/cert/logstash.crt"]
...

 

Restart logstash and filebeat service on each server

In logstash server
# sudo kill -SIGHUP [PID_OF_$(ps aux |grep logstash)]

In filebeat server
# sudo service filebeat restart

Check each logstash and filebeat log for connection establishment

'System Engineering > Linux' 카테고리의 다른 글

Nginx: How to purge the proxy cache  (0) 2020.05.25
Ubuntu apt-get upgrade  (0) 2019.12.13
Buffers and cache in memory (Linux)  (0) 2019.11.11
Check the disk type in linux (ubuntu)  (0) 2019.11.07
Bash: sed  (0) 2019.05.07

버퍼는 특정 블록 디바이스와 연관되어 있다. 저장된 파일의 메타데이터 (파일 권한 등)와 어떤 블록 디바이스에서 읽혔는지 또는 쓰기 되었는지 트래킹한다.

캐시는 저장된 파일 자체의 컨텐츠, 즉 파일 내용과 그 자체에 대한 내용을 가지고 있다.

 

Buffers are associated with a specific block device, and cover caching of filesystem metadata as well as tracking in-flight pages. The cache only contains parked file data. That is, the buffers remember what's in directories, what file permissions are, and keep track of what memory is being written from or read to for a particular block device. The cache only contains the contents of the files themselves.

ref: https://stackoverflow.com/questions/6345020/what-is-the-difference-between-buffer-vs-cache-memory-in-linux

 

What is the difference between buffer vs cache memory in Linux?

To me it's not clear what's the difference between the two Linux memory concept :buffer and cache. I've read through this post and it seems to me that the difference between them is the expiration

stackoverflow.com

'System Engineering > Linux' 카테고리의 다른 글

Ubuntu apt-get upgrade  (0) 2019.12.13
Logstash - filebeat SSL settings  (0) 2019.11.26
Check the disk type in linux (ubuntu)  (0) 2019.11.07
Bash: sed  (0) 2019.05.07
Tools: ab  (0) 2018.08.30

cat /sys/block/sda/queue/rotational

result get 1 or 0 (true or false)

which means ''harddisk for 1"

 

You can also use 'lsblk -d -o name,rota' to get this value for all of your physical devices.

 

장착되어 있는 디스크 타입이 SSD인지 하드디스크 인지 OS shell에서 확인하는 방법으로

직접 디바이스 정보에서 rotational 값을 확인하거나 lsblk 명령을 사용할 수 있다.

'System Engineering > Linux' 카테고리의 다른 글

Logstash - filebeat SSL settings  (0) 2019.11.26
Buffers and cache in memory (Linux)  (0) 2019.11.11
Bash: sed  (0) 2019.05.07
Tools: ab  (0) 2018.08.30
Find files and directory which is using disks very highly  (0) 2018.08.17

-linux FILE 내의 ORIGINAL 문자열 찾아 CHANGE로 변경
sed -i 's/{ORIGINAL}/{CHANGE}/g' {FILE_NAME}
- 파일의 \n 찾아 공백으로 변경
sed ':a;N;$!ba;s/\n/%0A/g' pdisk_list.txt
- 파일 빈 줄 지우기
sed '/^$/d' main.txt > out.txt
-windows 프로세스 실행 시작 시간 확인
wmic process get caption,creationdate | findstr 프로세스명

-linux FILE 내의 ORIGINAL 문자열 찾아 CHANGE로 변경
sed -i 's/{ORIGINAL}/{CHANGE}/g' {FILE_NAME}

- 파일의 \n 찾아 공백으로 변경 
sed ':a;N;$!ba;s/\n/%0A/g' pdisk_list.txt 

- 파일 빈 줄 지우기 
sed '/^$/d' main.txt > out.txt 
-windows 프로세스 실행 시작 시간 확인 
wmic process get caption,creationdate | findstr 프로세스명

'System Engineering > Linux' 카테고리의 다른 글

Buffers and cache in memory (Linux)  (0) 2019.11.11
Check the disk type in linux (ubuntu)  (0) 2019.11.07
Tools: ab  (0) 2018.08.30
Find files and directory which is using disks very highly  (0) 2018.08.17
Check and recover disk badblocks  (0) 2018.08.16

ab: Linux web test tool

ref: http://faq.hostway.co.kr/?mid=Linux_WEB&sort_index=readed_count&document_srl=1235&order_type=desc


Apache web server 등이 초당 얼마나 많은 요청을 처리할 수 있는지 측정하는 툴이다


Options


 -k

HTTP Keep-Alive 기능 사용 

-i 

GET 대신 HEAD 사용 

-n [REQUEST_COUNT] 

측정할 요청 수 지정 기본값 1

-t [TIME_LIMIT_SEC] 

측정할 시간 지정. 미지정시 세션에 대하여 50000개의 요청 자동 정의 

-c [SIMULTANEOUSLY_REQUEST_COUNT] 

동시 요청 수 지정. 기본값 1 

-p  [FILE]

POST 요청 및 파일 지정 

-A USER:PASS

사용자 인증

-p USER:PASS 

프록시 서버로의 인증 

-C COOKIE=VALUE 

요청에 쿠키 추가 

-H [HEADER] 

요청에 임의 헤더 추가 

 -T [CONTENT-TYPE]

POST 데이터의 content-type 헤더 지정 

-v 

출력 레벨 지정. 4: 결가괎 상단에 헤더 출력, 3: 결과 상단에 응답코드 출력, 2: 경고,정보 출력 

 -w

HTML table로 결과 출력 

-x <table [ATTRIBUTES]>

HTML <table>에 대한 속성 지정 

-y <tr [ATT]> 

<tr> 속성 지정 

-z <td [ATT]>

<td> 속성 지정 

-V 

버전 정보 출력 후 종료 

-h 

help 


Examples


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
[root@LOCALHOST ~]# ab -n 100 -c 10 http://localhost/
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
 
Benchmarking localhost (be patient).....done
 
 
Server Software:        Apache/2.2.15
Server Hostname:        localhost
Server Port:            80
 
Document Path:          /
Document Length:        4961 bytes
 
Concurrency Level:      10
Time taken for tests:   0.014 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Non-2xx responses:      103
Total transferred:      531377 bytes
HTML transferred:       510983 bytes
Requests per second:    7204.09 [#/sec] (mean)
Time per request:       1.388 [ms] (mean)
Time per request:       0.139 [ms] (mean, across all concurrent requests)
Transfer rate:          37383.68 [Kbytes/sec] received
 
Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.2      0       1
Processing:     0    1   0.4      1       2
Waiting:        0    1   0.4      1       2
Total:          1    1   0.3      1       2
 
Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      2
  95%      2
  98%      2
  99%      2
 100%      2 (longest request)
 
cs


'System Engineering > Linux' 카테고리의 다른 글

Check the disk type in linux (ubuntu)  (0) 2019.11.07
Bash: sed  (0) 2019.05.07
Find files and directory which is using disks very highly  (0) 2018.08.17
Check and recover disk badblocks  (0) 2018.08.16
Apache: Security settings  (0) 2018.08.03

Find files and directory in Linux

리눅스 상에서 파일, 디렉토리 찾기

du (Disk Usage)

Check linux directory usage

디스크 사용량 체크 명령어

1
# du [OPTIONS] [FILE]
cs


1
2
3
4
5
6
7
to check directory’s usage
# du -hs DIR
to check files and directory’s usage in current directory
# du -hs *
to limit recursive directory depth
# du --max-depth=1
 
cs


 -h

--human-readable 

-s 

--summarize: display only a total for each argument 

-x 

--one-file-system: skip directories on different file system 



grep

Print matching line

패턴과 매치되는 파일 또는 디렉터리 출력

1
2
3
# grep [OPTIONS] PATTERN [FILE]
 
egrep == grep -E
cs


-E 

--extended-regexp 

-v 

--invert-match 

-c 

count lines 

-i 

case insensitive 

-n 

set line number 

-l 

print matching file name 

-w 

print line with perfect match 



sort

Sorting list of files

출력하는 내용을 옵션에 따라 정렬해주는 명령

-r 

--reverse 

-h 

--human-numeric-sort: compare according to general numerical value 


head

Print top to N lines

출력 시 위에서 N 번째 줄 까지 출력

1
# head -n 20
cs


xarg

Make a command line on standard input and execute them.

표준 입력으로부터 명령을 받아 실행하는 명령으로, ls 명령과 조합하여 각 ls 명령 결과 줄에 따른 명령을 다시 실행할 수 있다.

1
# xarg -i [replace-str]
cs


-I or i 

replace with replace-str 



Sample

du -h --max-depth=1 * |sort -hr |head

ls | egrep -v "cache|proc" | xargs -i du -sh {} |sort -h


'System Engineering > Linux' 카테고리의 다른 글

Bash: sed  (0) 2019.05.07
Tools: ab  (0) 2018.08.30
Check and recover disk badblocks  (0) 2018.08.16
Apache: Security settings  (0) 2018.08.03
Apache: httpd set-up  (0) 2018.08.03

+ Recent posts