레이블이 Linux인 게시물을 표시합니다. 모든 게시물 표시
레이블이 Linux인 게시물을 표시합니다. 모든 게시물 표시

2015년 4월 7일 화요일

Linux OS에서 외장 USB HDD를 Mount하기


mkdir /mnt/usb
ls /dev/sd*   
  (어떤 device가 외장 HDD인지 모르므로, 목록에 있는 device를 모두 mount 시도해 봄)
  (단, 이미 mount된 device는 df 명령으로 이미 알고 있으므로 제외하고 작업한다)
mount -t ntfs-3g -o rw /dev/sdf1 /mnt/usb

2014년 12월 20일 토요일

CentOS 6.5에 Open vSwitch 설치

잘 정리된 설명서가 있으면,10분이면 할 일을 하루 종일 자료 찾느라 시간을 허비하고 있다.
다음에 빠르게 Open vSwitch를 설치하기 위해서 메모를 해두어야겠다.

* Open vSwitch Source Code 다운로드 하기
 wget 명령으로 openvswitch source를 다운로드한다.
  # wget http://openvswitch.org/releases/openvswitch-2.3.1.tar.gz

* 압출을 풀고, openvswitch-2.3.1 디렉토리에서 아래의 명령을 수행한다.
  # boot.sh
  # configure--with-linux=/usr/modules/`uname -r`/build    (중요: 이 경로가 잘못되면, 나중에 kernel module이 설치되지 않는다)

  # make
  # make install 
  # ln -s /usr/src/kernels/`uname -r`/include/linux generated   (중요: 이 부분이 매뉴얼에는 없다. 원래 필요없는 작업인데, make 파일이 잘못만들어져서 임의로 수작업을 해야 한다. generated 디렉토리를 만들지 않으면, 아래의 make modules_install 명령이 실패한다.)
  # make modules_install
  # rmmod  openvswitch    (참고: 꼭 필요한 절차는 아니다. Old Version을 remove하기 위해서)
  # modprobe  openvswitch

* kernel module이 잘 insert되었는지 확인한다.
  # dmesg
    ... ( 중간 생략 ) ...
    openvswitch: Open vSwitch switching datapath 2.3.1, built Dec 20 2014 16:33:44

* 새로 빌드한 kernel module의 정보를 확인한다.
 # modinfo openvswitch
    filename:       /lib/modules/2.6.32-431.1.2.0.1.el6.x86_64/extra/openvswitch.ko
    version:        2.3.1
    license:        GPL
    description:    Open vSwitch switching datapath
    srcversion:     B6EF1BA3A4922A40ED09655
    depends:        libcrc32c
    vermagic:       2.6.32-431.1.2.0.1.el6.x86_64 SMP mod_unload modversions
    parm:           vlan_tso:Enable TSO for VLAN packets (int)


* Open vSwitch가 사용할 DB를 초기화한다.
  # mkdir -p /usr/local/etc/openvswitch
  # ovsdb-tool create /usr/local/etc/openvswitch/conf.db vswitchd/vswitch.ovsschema   (위에서 make 명령을 수행했던 source package directory에서 수행해야 한다. 안 그러면, 실패한다.)


* Open vSwitch의 설정 DB를 기동한다.
  # ovsdb-server --remote=punix:/usr/local/var/run/openvswitch/db.sock \
                 --remote=db:Open_vSwitch,Open_vSwitch,manager_options \
                 --private-key=db:Open_vSwitch,SSL,private_key \
                 --certificate=db:Open_vSwitch,SSL,certificate \
                 --bootstrap-ca-cert=db:Open_vSwitch,SSL,ca_cert \
                 --pidfile --detach

  (참고로, 위와 같이 옵션을 추가하면 SSL을 사용하겠다는 것이다)

* DB를 처음 생성했으므로, 초기화한다.
  # ovs-vsctl  --no-wait  init

* Open vSwitch 데몬을 기동한다.
  # ovs-vswitchd --pidfile --detach
  2014-12-20T08:26:52Z|00001|reconnect|INFO|unix:/usr/local/var/run/openvswitch/db.sock: connecting...
  2014-12-20T08:26:52Z|00002|reconnect|INFO|unix:/usr/local/var/run/openvswitch/db.sock: connected


여기까지하면, Open vSwitch가 동작한다. 단, 구체적인 switch 설정을 하지 않았기 때문에 일을 하지는 않는다.
아래와 같이 간단하게 bridge network을 구성해보자.

* Bridge br0 라는 것을 생성한다. 그리고 Bridge br0에 물리적 NIC를 binding한다.
  # ovs-vsctl add-br br0
  # ovs-vsctl add-port br0 em1
  # ovs-vsctl add-port br0 vmnet8
  # ovs-vsctl show
    Bridge "br0"
        Port "vmnet8"
            Interface "vmnet8"
        Port "br0"
            Interface "br0"
                type: internal
        Port "em1"
            Interface "em1"


 이것으로 간단한 Bridge Network까지 구성했다.

2014년 12월 18일 목요일

NTFS 파티션을 CentOS 리눅스로 MOUNT 하기


< NTFS 파티션을 CentOS 리눅스로 마운트 하기 >
1. 밑에 3 설치를 위해 yum-priorities 먼저 설치
[root@localhost ~]# yum install yum-priorities -y
2. priorities.conf 수정
[root@localhost ~]# vi /etc/yum/pluginconf.d/priorities.conf
[main]
enabled = 1
check_obsoletes = 1
priority=2

3. rpmforge 설치
[root@localhost ~]# rpm -ivh 
[설치경로]
설치경로 찾기
- rpmforge 시작하는것중 가장 최근것의 파일명 복사해서 앞의 주소와 붙인다.
- 최종경로를 복사해서 위의 [설치경로] 붙여넣고 실행

4. 설치된 rpm 으로 패키지 업데이트
[root@localhost ~]# yum check-update
5. “fuse”, “fuse-ntfs-3g”, “dkms”, “dkms-fuse” 설치
[root@localhost ~]# yum install fuse fuse-ntfs-3g dkms dkms-fuse -y
6. 마운트용 디렉토리 생성
[root@localhost ~]# mkdir /mnt/window
7. fdisk -l 마운트할 파티션정보 찾기
[root@localhost ~]# fdisk -l
=> HPFS/NTFS 으로 표시되는 /dev/sda[넘버] 찾는다.
8. ntfs-3g 타입으로 마운트 실행
[root@localhost ~]# mount -t ntfs-3g /dev/sdb1 /mnt/window
9. 마운트한 파티션 사용
[root@localhost ~]# cd /mnt/window
[root@localhost window]# ls -al

TCPDUMP로 HTTP Packet (웹 페이지) Decode, Tshark(Text Wireshark) 사용법

Windows PC에서는 Wireshark이 Network Packet을 예쁘게 출력해주지만,
Linux 서버에 telnet, ssh 접속해서 tcpdump를 하면 정말 보기 어렵다.
원격 서버에 telnet, ssh 접속해서 Network Packet을 예쁘게 출력하려면 2가지 방법이 있다.

(방법1) tshark 명령 사용
tshark을 사용하면, Network Packet이 정말 예쁘게 출력된다.
만약, CentOS를 사용하는 User라면 아래와 같이 wireshark패키지를 설치한다.

  yum install wireshark

그런 후에 아래와 같이 tshark 명령을 수행한다. (-V 옵션이 decode를 하라는 뜻이다)


# tshark -i eth0 -nV port 53

Frame 10: 387 bytes on wire (3096 bits), 387 bytes captured (3096 bits) on interface 0
(중간 생략)
Ethernet II, Src: 00:08:5a:00:40:78 (00:08:5a:00:40:78), Dst: f0:1f:af:dc:ae:3b (f0:1f:af:dc:ae:3b)
    Destination: f0:1f:af:dc:ae:3b (f0:1f:af:dc:ae:3b)
        Address: f0:1f:af:dc:ae:3b (f0:1f:af:dc:ae:3b)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Source: 00:08:5a:00:40:78 (00:08:5a:00:40:78)
        Address: 00:08:5a:00:40:78 (00:08:5a:00:40:78)
        .... ..0. .... .... .... .... = LG bit: Globally unique address (factory default)
        .... ...0 .... .... .... .... = IG bit: Individual address (unicast)
    Type: IP (0x0800)
Internet Protocol Version 4, Src: 168.126.63.1 (168.126.63.1), Dst: 1.235.191.65 (1.235.191.65)
    Version: 4
    Header length: 20 bytes
    Differentiated Services Field: 0x00 (DSCP 0x00: Default; ECN: 0x00: Not-ECT (Not ECN-Capable Transport))
        0000 00.. = Differentiated Services Codepoint: Default (0x00)
        .... ..00 = Explicit Congestion Notification: Not-ECT (Not ECN-Capable Transport) (0x00)
    Total Length: 373
    Identification: 0x942b (37931)
    Flags: 0x00
        0... .... = Reserved bit: Not set
        .0.. .... = Don't fragment: Not set
        ..0. .... = More fragments: Not set
    Fragment offset: 0
    Time to live: 56
    Protocol: UDP (17)
    Header checksum: 0x44a1 [correct]
        [Good: True]
        [Bad: False]
    Source: 168.126.63.1 (168.126.63.1)
    Destination: 1.235.191.65 (1.235.191.65)
User Datagram Protocol, Src Port: 53 (53), Dst Port: 61224 (61224)
    Source port: 53 (53)
    Destination port: 61224 (61224)
    Length: 353
    Checksum: 0x8acc [validation disabled]
        [Good Checksum: False]
        [Bad Checksum: False]
Domain Name System (response)
    [Request In: 9]
    [Time: 0.003702000 seconds]
    Transaction ID: 0x0898
    Flags: 0x8180 Standard query response, No error
        1... .... .... .... = Response: Message is a response
        .000 0... .... .... = Opcode: Standard query (0)
        .... .0.. .... .... = Authoritative: Server is not an authority for domain
        .... ..0. .... .... = Truncated: Message is not truncated
        .... ...1 .... .... = Recursion desired: Do query recursively
        .... .... 1... .... = Recursion available: Server can do recursive queries
        .... .... .0.. .... = Z: reserved (0)
        .... .... ..0. .... = Answer authenticated: Answer/authority portion was not authenticated by the server
        .... .... ...0 .... = Non-authenticated data: Unacceptable
        .... .... .... 0000 = Reply code: No error (0)
    Questions: 1
    Answer RRs: 11
    Authority RRs: 4
    Additional RRs: 4
    Queries
        plus.google.com: type A, class IN
            Name: plus.google.com
            Type: A (Host address)
            Class: IN (0x0001)
    Answers
        plus.google.com: type A, class IN, addr 173.194.127.226
            Name: plus.google.com
            Type: A (Host address)
            Class: IN (0x0001)
            Time to live: 58 seconds
            Data length: 4
            Addr: 173.194.127.226 (173.194.127.226)
        plus.google.com: type A, class IN, addr 173.194.127.227
            Name: plus.google.com
            Type: A (Host address)
            Class: IN (0x0001)
            Time to live: 58 seconds
            Data length: 4
            Addr: 173.194.127.227 (173.194.127.227)
        plus.google.com: type A, class IN, addr 173.194.127.228
            Name: plus.google.com
            Type: A (Host address)
            Class: IN (0x0001)
            Time to live: 58 seconds
            Data length: 4
            Addr: 173.194.127.228 (173.194.127.228)
        plus.google.com: type A, class IN, addr 173.194.127.229
            Name: plus.google.com
            Type: A (Host address)
            Class: IN (0x0001)
            Time to live: 58 seconds
            Data length: 4
            Addr: 173.194.127.229 (173.194.127.229)
        plus.google.com: type A, class IN, addr 173.194.127.230
            Name: plus.google.com
            Type: A (Host address)
            Class: IN (0x0001)
            Time to live: 58 seconds
            Data length: 4
            Addr: 173.194.127.230 (173.194.127.230)



(방법2) tcpdump 명령의 -A 옵션 사용

tshark을 사용할 수 없는 경우라면, 아래 명령처럼 -A 옵션을 주면, TCP 또는 UDP의 Payload가 ASCII 로 출력된다.
(즉, Readable Character만 터미널에 출력함)

-A 옵션만 주면, TCP 세션을 수립하기 위한 SYN과 ACK 및 FIN도 모두 보여지기 때문에
Filter에  tcp[32:4] = 0x47455420 조건을 추가한다. ("GET "에 대한 Pointcode 값이다)


[ HTTP GET 요청 메시지만 출력 ]
tcpdump -i p2p2 -s 1500 -An 'src net 192.168.0.0/24' and dst port 80 and 'tcp[32:4] = 0x47455420'


[ HTTP GET 요청과 응답 메시지 모두 출력 ]
tcpdump -i em2 -s 1500 -An 'src net 192.168.0.0/24' and 'tcp[32:4] = 0x48545450' or 'tcp[32:4] = 0x47455420'

또는 

tcpdump -i em2 -An -s 0 'tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)'

(참고: 위의 3개 명령 중에서 3번째 줄의 명령이 제일 출력 포맷이 예쁘다)

출력은 아래와 같은 형태로 된다.

13:17:04.233515 IP 192.168.0.207.57084 > 112.175.42.43.http: Flags [P.], seq 5014:5577, ack 12833, win 324, options [nop,nop,TS val 1951264 ecr 632892989], length 563
E..g.n@.@. .....p.*+...P7..FL......D*......
... %..=GET /include/style/default/SiteHeader/new_window_icon_blue.png HTTP/1.1
Referer: http://wwwimages.adobe.com/www.adobe.com/include/style/compressed.css
Cache-Control: no-cache, must-revalidate
Pragma: no-cache
User-Agent: Wget/1.14 (linux-gnu)
Accept: */*
Host: wwwimages.adobe.com
Connection: Keep-Alive
Cookie: READER_HTTPREFERER=http%3A%2F%2Fwww%2Eadobe%2Ecom%2F; READER_NEW_USER=false; REFERER_URL=http%3A%2F%2Fwww%2Eadobe%
13:17:04.257579 IP 192.168.0.207.47618 > 112.175.13.198.http: Flags [P.], seq 7922:8258, ack 1194783, win 65535, options [nop,nop,TS val 1951270 ecr 3946957185], length 336
....P!.B3...............
...&.A..GET /_common/showThumb.asp?dire=infoMovie&fn=IMG%5F1272thumb%2Ejpg HTTP/1.1
Referer: http://kumon.co.kr/product/edu2_math.asp
Cache-Control: no-cache, must-revalidate
Pragma: no-cache
User-Agent: Wget/1.14 (linux-gnu)
Accept: */*
Host: kumon.co.kr
Connection: Keep-Alive
Cookie: ASPSESSIONIDSQQAQABD=MCBEOLEDLACODBPMGANNNFHG


13:17:04.465645 IP 192.168.0.207.47152 > a184-50-205-15.deploy.static.akamaitechnologies.com.http: Flags [P.], seq 335:669, ack 563, win 123, options [nop,nop,TS val 1951322 ecr 3284250484], length 334
E....N@.@..n.....2...0.PS.y..i.....{Z......
...Z...tGET /itunes/features/ HTTP/1.1
Referer: https://itunes.apple.com/app/id657500465?mt=8
Cache-Control: no-cache, must-revalidate
Pragma: no-cache
User-Agent: Wget/1.14 (linux-gnu)
Accept: */*
Host: www.apple.com
Connection: Keep-Alive


Cookie: ccl=fZMrl+bDAe8OE6vShNUGZA==; dssid2=3069a63c-9e19-42bf-b4bb-ec4af96b2ccd; geo=KR

환경변수 MALLOC_CHECK_ 설정하기

glibc

  • Red Hat 엔터프라이즈 리눅스 4에 포함된 버전 glibc는 데이터 손상을 최대할 빨리 검색하여 방지할 수 있도록 내부 정상 감시 기능을 추가로 수행합니다. 데이터 손상이 감지되면 다음과 같은 메시지가 표준 오류로 나타날 것입니다 (만일 표준 오류(stderr)이 열려있지 않은 경우에는 syslog으로 기록됩니다):

    *** glibc detected *** double free or corruption: 0x0937d008 ***
    또는
    *** glibc detected *** invalid pointer free: 0x0937d008 ***

    이 오류 메시지를 생성하는 프로그램은 디폴트로 제거(kill)됩니다; MALLOC_CHECK_ 환경 변수를 이용하여 오류 메시지 생성 여부를 선택하실 수 있습니다. 다음과 같은 설정이 가능합니다:
    • 0 — 오류 메시지를 생성하지 않고, 프로그램을 제거하지 않음
    • 1 — 오류 메시지를 생성하지만, 프로그램을 제거하지 않음
    • 2 — 오류 메시지를 생성하지는 않지만, 프로그램은 제거함 <== 기본값
    • 3 — 오류 메시지를 생성하고 프로그램을 제거함

    알림

    만일 MALLOC_CHECK_ 변수를 0이 아닌 다른 값으로 설정할 경우, glibc는 기본 설정 보다 광범위한 검사를 수행하므로결국 시스템 성능에 영향을 미칠 수 있습니다.


** 쉘 설정 파일에 setenv MALLOC_CHECK_  0 으로 세팅한다.


Bourne 쉘의 경우 
MALLOC_CHECK_=0;
export MALLOC_CHECK_

Bash 쉘의 경우 
export MALLOC_CHECK_=0

csh, tcsh 쉘의 경우 
setenv MALLOC_CHECK_ 0

Install EPEL and additional repositories


작업을 하기 전에 현재 설정된 Repository List를 출력한다.
  yum repolist   (참고: 확장자가 *.repo 인 모든 파일 정보를 출력)




[Install EPEL and additional repositories]

참고로, EPEL repository는 Extra Packages for Enterprise Linux repository를 의미한다.


아래의 wget 명령과 rpm 명령을 각각 한번씩만 수행하면 모든 설정 작업은 끝난다.
(/etc/yum.repos.d/ 디렉토리에서 파일을 수작업으로 편집하지 않아도 된다)


Install the EPEL Repository
[CentOS 6.x 또는 RedHat Enterprise 6.x]
wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
rpm -Uvh epel-release-6*.rpm

[CentOS 7.x 또는 RedHat Enterprise 7.x]
wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm
rpm -Uvh epel-release-7*.rpm


Install the IUS repository (optional)
[RedHat 6.x]
wget http://dl.iuscommunity.org/pub/ius/stable/RedHat/6/x86_64/ius-release-1.0-13.ius.el6.noarch.rpm
rpm -Uvh ius-release*.rpm

또는 아래와 같이 직접 rpm 명령으로 repository를 추가할 수 있다.
rpm -Uvh http://download.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm

rpm -Uvh http://mirror.premi.st/epel//6/x86_64/epel-release-6-8.noarch.rpm


[RedHat 7.x]


http://dl.iuscommunity.org/pub/ius/stable/RedHat/7/x86_64/ius-release-1.0-13.ius.el7.noarch.rpm
sudo rpm -Uvh ius-release*.rpm