'Cloud Computing/unix, sh, network'에 해당하는 글 3건

python 및 머신러닝 교육, 슬로우캠퍼스



nginx 설정 설명


server {
    listen  80;
    server_name demo.abc.com;
    charset utf-8;

    access_log /home/ubuntu/app/log/nginx/demo_abc_com_access.log;
    error_log /home/ubuntu/app/log/nginx/demo_abc_com_error.log;

    location / {
            proxy_pass                          http://127.0.0.1:8000;
            proxy_set_header X-Forwarded-Host   $host;
            proxy_set_header X-Forwarded-Server $host;
            proxy_set_header X-Forwarded-For    $proxy_add_x_forwarded_for;
    }
}



location block의 모습

location optional_modifier location_match {

    . . .

}

 

location을 match할때는 다음 순서로 이루어진다.

  1. URL의 prefix가 일치하는지 먼저 검사하여, 일치하는 것이 발견되면 기억해 놓고, 다음 location match를 수행한다. 즉 멈추지 않는다.
  2. regular expression과 일치하는 것이 있는 검사한다.
  3. 최종적으로 일치하는 regular expression이 있으면 그것을 선택하고, 없으면 1번에서 발견한 prefix 일치하였던 것을 리턴한다.
  4. prefix match 중에 '=', '^~' 로 수식된 것에서 prefix 일치가 발견되면 regular expression 비교 수행하지 않고 바로 리턴한다. (1번의 예외상황)

 


location block에서 optional_modifier 의미

  • = 는 exact match를 의미.  RE 진행하지 않음
  • / 및 /abc 는 prefix를 의미 
  • ~는 regular expression(대소문자 구분함)을 의미.  ~*는 대소문자 구분없는 RE(regular expression)
  • ^~는 match된 경우에 RE 진행하지 않음 이라는 의미.


location = / {    
    [ configuration A ]
}

location / {
    [ configuration B ]
}

location /documents/ {
    [ configuration C ]
}

location ^~ /images/ {
    [ configuration D ]
}

location ~* \.(gif|jpg|jpeg)$ {
    [ configuration E ]
}

nginx 설정

 

/etc/nginx/sites-available 아래에 파일을 생성하고,  

/etc/nginx/sites-enabled 에서 링크를 연결한다 (ln -s /etc/nginx/sites-available/xyz . ) 


참고 - https://www.digitalocean.com/community/tutorials/understanding-nginx-server-and-location-block-selection-algorithms



WRITTEN BY
manager@
Data Analysis, Text/Knowledge Mining, Python, Cloud Computing, Platform

,

python 및 머신러닝 교육, 슬로우캠퍼스


CPU, core 정보를 구할 때는 아래 명령어를 이용하자.


/usr/bin/kstat -m cpu_info


/usr/sbin/psrinfo --> CPU 정보 (solaris)



/usr/sbin/prtdiag --> HW 정보 (solaris)



그외 시스템 정보 및 상태 확인할 때는  psrinfo, prtconf, dmesg, format, netstat, uname 등을 이용 가능하다. 




아래는 CPU 개수를 편하게 확인할 수 있는 script이다.








http://technopark02.blogspot.kr/2011/04/solaris-show-me-cpu-vcpu-core-counts.html


#!/bin/bash

# original

/usr/bin/kstat -m cpu_info | egrep "chip_id|core_id|module: cpu_info" > /var/tmp/cpu_info.log

# solaris 10에서는 pkg_core_id, core_id 둘다 존재하는데, pkg_core_id만 grep 하면 된다

/usr/bin/kstat -m cpu_info | egrep "chip_id|pkg_core_id|module: cpu_info" > /var/tmp/cpu_info.log


nproc=`(grep chip_id /var/tmp/cpu_info.log | awk '{ print $2 }' | sort -u | wc -l | tr -d ' ')`
ncore=`(grep core_id /var/tmp/cpu_info.log | awk '{ print $2 }' | sort -u | wc -l | tr -d ' ')`
vproc=`(grep 'module: cpu_info' /var/tmp/cpu_info.log | awk '{ print $4 }' | sort -u | wc -l | tr -d ' ')`

nstrandspercore=$(($vproc/$ncore))
ncoresperproc=$(($ncore/$nproc))

speedinmhz=`(/usr/bin/kstat -m cpu_info | grep clock_MHz | awk '{ print $2 }' | sort -u)`
speedinghz=`echo "scale=2; $speedinmhz/1000" | bc`

echo "Total number of physical processors: $nproc"
echo "Number of virtual processors: $vproc"
echo "Total number of cores: $ncore"
echo "Number of cores per physical processor: $ncoresperproc"
echo "Number of hardware threads (strands or vCPUs) per core: $nstrandspercore"
echo "Processor speed: $speedinmhz MHz ($speedinghz GHz)"

# now derive the vcpu-to-core mapping based on above information #

echo -e "\n** Socket-Core-vCPU mapping **"
let linenum=2

for ((i = 1; i <= ${nproc}; ++i ))
do
        chipid=`sed -n ${linenum}p /var/tmp/cpu_info.log | awk '{ print $2 }'`
        echo -e "\nPhysical Processor $i (chip id: $chipid):"

        for ((j = 1; j <= ${ncoresperproc}; ++j ))
        do
                let linenum=($linenum + 1)
                coreid=`sed -n ${linenum}p /var/tmp/cpu_info.log | awk '{ print $2 }'`
                echo -e "\tCore $j (core id: $coreid):"

                let linenum=($linenum - 2)
                vcpustart=`sed -n ${linenum}p /var/tmp/cpu_info.log | awk '{ print $4 }'`

                let linenum=(3 * $nstrandspercore + $linenum - 3)
                vcpuend=`sed -n ${linenum}p /var/tmp/cpu_info.log | awk '{ print $4 }'`

                echo -e "\t\tvCPU ids: $vcpustart - $vcpuend"
                let linenum=($linenum + 4)
        done
done
 

rm /var/tmp/cpu_info.log




실행 결과 예시)

 $ bash showcpucount.sh


Total number of physical processors: 1

Number of virtual processors: 8

Total number of cores: 4

Number of cores per physical processor: 4

Number of hardware threads (strands or vCPUs) per core: 2

Processor speed: 2400 MHz (2.40 GHz)


** Socket-Core-vCPU mapping **


Physical Processor 1 (chip id: 0):

        Core 1 (core id: 0):

                vCPU ids: 0 - 1

        Core 2 (core id: 9):

                vCPU ids: 2 - 3

        Core 3 (core id: 0):

                vCPU ids: 4 - 5

        Core 4 (core id: 9):

                vCPU ids: 6 - 7




WRITTEN BY
manager@
Data Analysis, Text/Knowledge Mining, Python, Cloud Computing, Platform

,

python 및 머신러닝 교육, 슬로우캠퍼스

[curl, wget] 다운로드 속도 조절하기 (limit download speed)


--limit-rate 옵션을 이용하면 다운로드 속도를 제어할 수 있다 (throttle download speed)

이 옵션은 curl, wget 둘 다 동일하게 지원한다.


아래는 100 Kb/sec 으로 제한하는 방법이다.


curl --limit-rate 100K


wget --limit-rate=100k



[curl, wget] 파일 일부분 다운로드 받기  (partial download)


HTTP header에 'Range' 를 넣어서 할 수 있다.

curl에서 --header 옵션으로 header값을 추가할 수 있다.


아래는 http://abc.com/aaa.txt 에서 앞부분 50k byte 정도만 다운로드 받아 aaa.5k.txt 로 저장하는 것이다.


curl --header "Range: bytes=0-50000" -o aaa.5k.txt http://abc.com/aaa.txt 


WRITTEN BY
manager@
Data Analysis, Text/Knowledge Mining, Python, Cloud Computing, Platform

,