2020년 6월 19일 금요일

신용카드 번호 체계(BIN)와 검증번호

신용카드와 체크카드 번호는 XXXX-XXXX-XXXX-XXXX 형식으로 4자리씩 총 16자리로 구성된다. 아멕스 신용카드 처럼 일부 카드는 15자리도 있지만 대부분은 16자리이다.
이 중에서 앞자리 6개는 국제식별번호이며 BIN (Bank Identification Number) 이라고 부른다.

국내 신용카드사 전체의 6자리 BIN 넘버를 알고 싶으면, VAN사 자료실에서 찾아보면 된다

전세계 BIN 정보는 아래



참고

2017년 2월 16일 목요일

HAproxy HA 구성


HA 구성을 봐야해서 남겨둔다.

물론인터넷에서 가져옴. 문제될까봐 출처도 남겨놓는다.

https://blog.logentries.com/2014/12/keepalived-and-haproxy-in-aws-an-exploratory-guide/

HAproxy는 고가용성 프록시를 의미합니다. 
이름에서도 알 수 있다시피 High Availability proxy 입니다
C 언어로 작성되었으며 무료 오픈소스 프로그램입니다. 
HAproxy는 TCP / HTTP 로드 밸런서로 프록시 솔루션에 사용됩니다. 
HAproxy의 일반적인 용도는 웹서버, DB 서버 등 부하를 분산시키는 용도로 많이 사용되고 있습니다.
BSD, 리눅스, 솔라리스 등에서 사용할 수 있으며, 물론 윈도우는 안됩니다. (-0-;)
(여담이지만, 윈도우는 뭐 다 돈이네요 ;;;)

**********************************************************************************************************
* 환경
OS : Ubuntu 16.04.1 LTS
HAproxy : 1.6.7
WebServer : Apache/2.4.18 (Ubuntu)
VM : VirtualBox 5.1.2

* 참고
sudo 로 진행하지 않고 root 로 진행합니다.
**********************************************************************************************************
* 준비사항
VM 환경에서 진행되며, 로드밸런서이기 때문에
HAproxy 를 설치할 VM 하나, 웹서버 VM 2개를 먼저 준비합니다.
VM 을 만드는 부분은 여기서 설명하지 않습니다.
VM 의 상세 내역은 아래와 같습니다.

VM
OS
IP
Hostname
HAproxy
Ubuntu 16.04.1 LTS 64bit
172.16.1.5
HAproxy
 Webserver01
Ubuntu 16.04.1 LTS 64bit
172.16.1.15
webserver-01
Webserver02
Ubuntu 16.04.1 LTS 64bit
172.16.1.16
webserver-02

**********************************************************************************************************

1. Apache 설치
# apt-get install apache2 
  - 모든 VM 에 apache 를 모두 설치합니다.

2. HAproxy 저장소 등록 및 업데이트
# apt-add-repository ppa:vbernat/haproxy-1.6
# apt-get update

3. HAproxy 설치
# apt-get install haproxy

4. haproxy.cfg 수정
# vi /etc/haproxy/haproxy.cfg

global
        #log /dev/log   local0
        #log /dev/log   local1 notice
        log 127.0.0.1 local2
        chroot /var/lib/haproxy
        stats socket /run/haproxy/admin.sock mode 660 level admin
        stats timeout 30s
        user haproxy
        group haproxy
        daemon
 . . .

위처럼 log 를 주석처리 해주고 log 127.0.0.1 local2 를 입력해 줍니다.

5. rsyslog.conf 파일 수정
# vi /etc/rsyslog.conf

$ModLoad imudp
$UDPServerRun 514 

파일에 위 부분이 주석처리 되어 있다면 주석을 풀어주시고 없다면 입력해 줍니다.

6. haproxy.conf 파일 생성하고 내용 추가
# vi /etc/rsyslog.d/haproxy.conf

local2.*        /var/log/haproxy.log

7. rsyslog 서비스 재시작
# service rsyslog restart

8. haproxy.cfg 수정
# vi /etc/haproxy/haproxy.cfg

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        option  http-server-close
        option  forwardfor except 127.0.0.0/8
        option  redispatch
        retries 3
        timeout http-request    20
        timeout queue            86400
        timeout connect          86400
        timeout client             86400
        timeout server             86400
        timeout http-keep-alive 30
        timeout check             20
        maxconn                    50000 

frontend LB
        bind 172.16.1.5:80
        reqadd X-Forwarded-Proto:\ http
        default_backend bkLB

backend bkLB
        mode http
        stats enable
        stats hide-version
        stats uri /stats
        stats realm Haproxy\ Statistics
        stats auth haproxy:admin
        balance roundrobin
        option httpchk
        option httpclose
        option forwardfor
        cookie LB insert
        server webserver-01 172.16.1.15:80 cookie webserver-01 check
        server webserver-02 172.16.1.16:80 cookie webserver-02 check


10. HAproxy 재시작
# service haproxy restart

11. 시스템 시작시 자동으로 시작하기 위해 파일 수정
# vi /etc/default/haproxy

ENABLED=1 


12. 정상적으로 동작하는지 확인하기 위해 웹서버 index.html 를 수정
- webserver-01 에서
# mv /var/www/html/index.html /var/www/html/index.html.backup
# vi /var/www/html/index.html
webserver-01 

- webserver-02 에서
# mv /var/www/html/index.html /var/www/html/index.html.backup
# vi /var/www/html/index.html
webserver-02

13. 로드밸런싱이 되는지 확인
# curl 172.16.1.5
webserver-01
# curl 172.16.1.5
webserver-02
# curl 172.16.1.5
webserver-01
# curl 172.16.1.5
webserver-02

위 처럼 roundrobin 형식으로 정상적으로 나오는지 확인

14. HAproxy 통계 페이지 확인
- 웹브라우저에서 172.16.1.5/stats 를 입력
  로그인 화면에서 haproxy / admin 으로 로그인





* 참고
hosts 파일 수정

127.0.0.1       localhost
127.0.1.1       HAproxy

# The following lines are desirable for IPv6 capable hosts
::1     localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouter

172.16.1.15  webserver-01
172.16.1.16  webserver-02 


출처: http://livegs.tistory.com/43 [if (feel)]

실제 현업에선 HAproxy 한대로 구성하는 경우는 거의 없습니다.
만약 HAproxy 가 장애를 일으켜 죽는 경우가 발생하면
그 밑에 있는 웹서버들은 다 죽는 거나 마찬가지기 때문에 리스크가 너무 큽니다.
그래서, 이번엔 HAproxy 를 Active - Standby 형식으로 LB Cluster 를 구성해 보겠습니다.
HAproxy 를 HA 구성으로 만들기 위해 keepalived 를 이용하여 구성합니다.
**********************************************************************************************************
* Keepalived 란?
Keepalived 는 C 언어로 작성되었으며 부하 분산 및 고가용성을 위한 라우팅 소프트웨어입니다.
VRRP (Virtual Router Redundancy Protocol) 프로토콜을 사용합니다.
VRRP 관련하여 알고 싶으시면 여기 를 확인해 보시기 바랍니다.

**********************************************************************************************************
* 환경
OS : Ubuntu 16.04.1 LTS
HAproxy : 1.6.7
Keepalived : 1.2.19

* 참고
sudo 로 진행하지 않고 root 로 진행합니다.
**********************************************************************************************************
* 준비사항

VM
OS
IP
Hostname
HAproxy
Ubuntu 16.04.1 LTS 64bit
172.16.1.5
HAproxy
HAproxy2
Ubuntu 16.04.1 LTS 64bit
172.16.1.6
HAproxyB
 Webserver01
Ubuntu 16.04.1 LTS 64bit
172.16.1.15
webserver-01
Webserver02
Ubuntu 16.04.1 LTS 64bit
172.16.1.16
webserver-02

HAproxy 에서 설치했던 것과 같이 똑같이 HAproxyB 에도 설치합니다.
설치하는 방법은 이전 포스팅 http://livegs.tistory.com/43 을 참고해주세요.

**********************************************************************************************************

1. HAproxy 가 설치된 서버의 커널 값을 수정합니다. (두 대 모두 수행)
# vi /etc/sysctl.conf
 net.ipv4.ip_nonlocal_bind=1

위 부분이 중요한 부분인데, 위 옵션이 뭔지 찾아보면
로컬 IP 가 아닌 주소에 bind() 할 수 있게 해줍니다. 라고 되어 있는데요. 말이 어려운데요.
다시 말해서 현재 가지고 있는 IP 가 아닌 다른 외부 IP 를 NIC 에 바인딩 할 수 있게 해준다는 뜻입니다.
이게 왜 중요하냐면 서비스인 VIP 를 첫번째 서버가 가지고 있다가 장애가 나는 경우
Standby 서버로 그 VIP 를 옮겨야 서비스가 끊기지 않고 돌아갈 수 있기 때문이죠.
저 옵션이 되어 있지 않은 경우 VIP 를 바인딩 할 수 없기 때문에 꼭 수정해줘야 합니다.

2. 커널 값 적용 및 확인 (두 대 모두 수행)
# sysctl -p
# cat /proc/sys/net/ipv4/ip_nonlocal_bind 
1 

위 처럼 1이 나오면 정상적으로 적용됨.
안되는 경우 reboot


3. Keepalived 설치 (두 대 모두 수행)
# apt-get install keepalived

4. keepalived.conf 파일 수정
# vi /etc/keepalived/keepalived.conf

- 첫번째 서버
global_defs {
        router_id HAproxy
}

# Define the script used to check if haproxy is still working
vrrp_script chk_haproxy {
        script "killall -0 haproxy"
        interval 2
        weight 2
}

# Configuration for the virtual interface
vrrp_instance VIS_1 {

        interface              enp0s3
        state                   MASTER
        priority                101
        virtual_router_id     51
        advert_int             1

        # The virtual ip address shared between the two loadbalancers
        virtual_ipaddress {
                172.16.1.5
        }

        # Use the script above to check if we should fail over
        track_script {
                chk_haproxy
        }
}

- 두번째 서버
global_defs {
        router_id HAproxyB
}

# Define the script used to check if haproxy is still working
vrrp_script chk_haproxy {
        script "killall -0 haproxy"
        interval 2
        weight 2
}

# Configuration for the virtual interface
vrrp_instance VIS_1 {

        interface              enp0s3
        state                   MASTER
        priority                100
        virtual_router_id     51
        advert_int             1

        # The virtual ip address shared between the two loadbalancers
        virtual_ipaddress {
                172.16.1.5
        }

        # Use the script above to check if we should fail over
        track_script {
                chk_haproxy
        }
}


위 처럼 인스턴스 (vrrp_instance VIS_1) 이름은 동일하게 하며 priority 값은 다르게 하여
Master 가 내려 갔다 다시 올라오는 경우에 원래대로 Master 에서 VIP 를 가져갈 수 있게 합니다.
위 설정 값은 기본 적은 설정으로 자세한 옵션은 상황에 맞게 진행하면 됩니다.
더 자세한 내용을 알고 싶으면 여기 를 참고해 주세요.

5. keepalived 와 HAproxy 서비스 재시작 (두 대 모두 수행)
# service keepalived restart
# service haproxy restart

6. IP 할당 확인
# ip addr show
위 명령어로 확인해보면 첫번째 서버의 NIC 에 VIP가 추가로 할당되어 있는 것을 확인할 수 있다.

7. FailOver 확인
두 대의 서버가 아닌 서버에서 (같은 네트워크에 있는...) ping 으로 확인해 봅니다.

# ping 172.16.1.5

수행 후 첫번 째 서버를 halt 내지는 poweroff 를 해봅니다.

...

64 bytes from 192.168.25.203: icmp_seq=221 ttl=64 time=0.291 ms
64 bytes from 192.168.25.203: icmp_seq=222 ttl=64 time=0.297 ms
64 bytes from 192.168.25.203: icmp_seq=223 ttl=64 time=0.242 ms
64 bytes from 192.168.25.203: icmp_seq=224 ttl=64 time=0.286 ms
64 bytes from 192.168.25.203: icmp_seq=225 ttl=64 time=0.151 ms
64 bytes from 192.168.25.203: icmp_seq=226 ttl=64 time=0.270 ms 

...


위 처럼 ping 이 가다가 잠시 순단 현상이 발생할 수 있으나 계속 ping 이 나간다면
정상적으로 failover 됨을 알 수 있습니다.
실제 두번째 서버에 가서 
# ip addr show 를 해보면 VIP 인 172.16.1.5 가 NIC 에 바인딩 되어 있음을 확인할 수 있습니다.


출처: http://livegs.tistory.com/44 [if (feel)]

2017년 2월 3일 금요일

[VBS] LNK 파일 만들기

VBS로 숏컷 만들기

LNK 파일을 만들려고 하니 귀찬음. 자동화를 위해서는 스크립트를 만들어야 해서 작성함.

시나리오는 C:\TEST\TEST.TXT 파일을 C:\TEST 디랙토리에 test.LNK 파일을 만든다.

Set oWS = WScript.CreateObject("WScript.Shell")
sLinkFile = "C:\test\test.LNK"
Set oLink = oWS.CreateShortcut(sLinkFile)
    oLink.TargetPath = "C:\test\test.txt"
 '  oLink.Arguments = ""
 '  oLink.Description = "MyProgram"   
 '  oLink.HotKey = "ALT+CTRL+F"
 '  oLink.IconLocation = "C:\test\test.txt, 2"
 '  oLink.WindowStyle = "1"   
 '  oLink.WorkingDirectory = "C:\test\"
oLink.Save

또는 CMD로 만들어서 할수도있다는 바탕화면에 notepad.exe 숏컷을 만드는 예제.
@echo off
echo Set oWS = WScript.CreateObject("WScript.Shell") > CreateShortcut.vbs
echo sLinkFile = "%HOMEDRIVE%%HOMEPATH%\Desktop\Hello.lnk" >> CreateShortcut.vbs
echo Set oLink = oWS.CreateShortcut(sLinkFile) >> CreateShortcut.vbs
echo oLink.TargetPath = "C:\Windows\notepad.exe" >> CreateShortcut.vbs
echo oLink.Save >> CreateShortcut.vbs
cscript CreateShortcut.vbs
del CreateShortcut.vbs