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

AWX에서 Job 실행 후, Inventory sync 과정에서 계속 fail status를 뱉었다. 에러 메시지는 다음과 같다.

Inventory sync keep failing when the job is launched on AWX. The error message is

ERROR! Attempting to decrypt but no vault secrets found

해당 에러는 AWX 프로젝트 내에서 사용하는 ansible SCM 내에 vault 파일을 포함하고 있을 경우 발생한다. Job template 생성 시 AWX상에서 Vault 타입의 Credential을 생성하고 추가 해 주면 해결이 되어야 하는데, 정상적으로 적용하지 못하는 것으로 보인다.

SCM 내에 vault 파일을 모두 삭제해 버리는 것도 방법이다. SCM이 잘 보호 되고 있다는 가정 하에, vault password 파일과 ansible.cfg 파일을 설정하면 해결 가능하다.

 

That error messages comes with if the SCM in AWX project that have some vault files with no vault passwords are given. In the Job template settings, we can set the credential of vault type. But now, it is not working correctly when the job is launched. The temporary way to fix it is set up the vault password file and ansible configuration file in your SCM.

# ansible.cfg
# If set, configures the path to the Vault password file as an alternative to
# specifying --vault-password-file on the command line.
vault_password_file = ./.vault.txt

 

리눅스 커널 이미지 업데이트 시 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

SSL / TLS Intermediate CA

Ref: https://www.thesslstore.com/blog/root-certificates-intermediate/

 

각 CA는 하나 이상의 루트 CA를 가질 수 있으며, 실제 대부분의 CA는 여러개의 루트를 가지고 있다.

 

사용자 시스템에서 리프 인증서가 인증이 되면, 그 인증서의 루트에서 발급 된 모든 인증서는 사용자의 시스템에서 자동으로 신뢰하도록 설계되어 있다.

 

Certificate chain

인증서 발급을 위해서는 CSR (Certificate Signing Request)와 Private key를 생성하며, 인증 기관 루트에서 개인 키로 인증서를 서명함으로 인증 체인이 완성된다.

 

 

루트 CA에서 직접 모든 인증서를 발급하고 관리하는 것은 보안상 많은 리스크를 수반하므로, 중간 CA를 두어 보안 및 관리에 용이하도록 한다.

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

VDI  (0) 2018.06.18
IPS & IDS (feat. FW)  (0) 2018.06.18

When you install pipsi from get-pipsi.py, You should not execute python with sudo.

Just export PATH for pipsi

'Python' 카테고리의 다른 글

Python pip local package install  (0) 2023.06.21
SSH with python3  (0) 2019.01.25
flask: download file from directory  (0) 2019.01.02
Flask on apache via mod_wsgi  (0) 2018.12.06
Python 2.6 to 2.7 (or 3.x)  (0) 2018.11.23

-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

paramiko 모듈을 이용하여 원격 리눅스 서버에 SSH 접속


pip를 이용하여 paramiko 모듈 설치


1
python -m pip install paramiko
cs


paramiko ssh 기본 접속 설정


1
2
3
4
5
6
7
8
9
10
11
import paramiko
import time
 
def main():
    HOST = 'ip_address'
 
    try:
        ssh = paramiko.SSHClient()
        # SSH Host key 설정
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(HOST, username='USERNAME', password='PW')
cs


기본적으로 한번 connect 된 상태에서 명령어를 실행할 때 마다 하나의 채널이 생성되고 종료되는 것이 반복된다.

su 커맨드를 사용하기 위해서는 채널을 유지시켜 줘야 하는데, 이 때 invoke_shell()를 사용하면 된다.


1
2
3
4
channel = ssh.invoke_shell()
 
channel.send('su -\n')
channel.send('password\n')
cs



전체 코드


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
import paramiko
import time
 
def main():
    HOST = 'ip_address'
 
    try:
        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
        ssh.connect(HOST, username='USERNAME', password='PW')
        channel = ssh.invoke_shell()
 
        channel.send('su -\n')
        outdata, errdata = waitStreams(channel)
        print (outdata)
        channel.send('PW2\n')
        outdata, errdata = waitStreams(channel)
        print (outdata)
 
        channel.send('touch python_test_is_complete\n')
        outdata, errdata = waitStreams(channel)
        print (outdata)
 
    finally:
        if ssh is not None:
            ssh.close()
 
# python 모듈을 실행하는 커맨드 라인에서 출력 결과를 보여는 
def waitStreams(chan):
    time.sleep(1)
    outdata=errdata = ""
 
    while chan.recv_ready():
        outdata += str(chan.recv(1000))
    while chan.recv_stderr_ready():
        errdata += str(chan.recv_stderr(1000))
 
    return outdata, errdata
 
if __name__ == "__main__":
    main()
cs



Python 3.7.2 Traceback


1
TypeError: can only concatenate str (not "bytes") to str
cs


전체코드 33 ~ 36: byte로 읽은 데이터를 str 타입으로 변환 시켜 저장해야 정상적으로 print를 사용할 수 있다.

'Python' 카테고리의 다른 글

Python pip local package install  (0) 2023.06.21
pipsi - pip script installer  (1) 2019.06.04
flask: download file from directory  (0) 2019.01.02
Flask on apache via mod_wsgi  (0) 2018.12.06
Python 2.6 to 2.7 (or 3.x)  (0) 2018.11.23

+ Recent posts