2014년 10월 10일 금요일

bash 쉘 공격대비 업데이트

#!/bin/bash

echo "before Patch"
echo `rpm -qa | grep bash`
echo ""
echo ""
yum -y update bash
echo ""
echo ""
echo "After Patch"
echo ` rpm -qa | grep bash`

echo ""
echo ""
echo `curl https://shellshocker.net/shellshock_test.sh | bash`




1. /home  -> bash.txt 생성

2. 위 쉘 입력

3. sh bash.txt 실행


2014년 10월 7일 화요일

SSH 세션 끊김 현상

SSH Client를 켜두고 아무것도 하지 않으면 자동으로 종료되는 걸 볼 수 있다.

이 것은 리눅스의 screen 을 사용 할 때도 마찬가지로 자동으로 screen이 닫힌다.

* SSH 설정 변경

1) /etc/ssh/sshd_config 를 연다. - Server

2) 아래 항목을 수정하거나 추가한다.
TCPKeepAlive yes
ClientAliveInterval 60
ClientAliveCountMax 99999

3) /etc/init.d/sshd restart 로 ssh를 재시작한다.


* 리눅스 세션 시간 변경
1) bashrc 항목 중 TMOUT 이라는 항목이 있다.
 
2) 초 단위로 사용하지 않는 세션을 종료해버리는데 이게 설정 돼있다면 지워준다.
확인 방법은 export TMOUT 
혹은 /etc/bashrc 나 /etc/profile 을 확인하도록 한다.

3) 변경 후 source bashrc 

2014년 9월 17일 수요일

DRBD(Distributed Replicated Block Device) 설치 및 설정 방법





DRBD(Distributed Replicated Block Device)는 HA(High Availability) Cluster를 구축하기위해 만들어 졌으며, 
네트워크를 통해 디스크 복제(동기화)가 가능 하도록 해주어 Raid-1(Mirroring)과 같은 환경을 구축할수 있게 도와준다.








테스트 환경
  • CentOS 6.5
  • vmware




서버 구성

  • Host Name Type IP Storage


  • nell-node1 Primary 192.168.80.110 20G (SCSI) + 20G (SCSI)


  • nell-node2 Secondary 192.168.80.111 20G (SCSI) + 20G (SCSI)


기존 /sda에 disk를 추가하여 /sdb 추가 (drbd 가상 드라이브로 사용하기 위함)






                                                                                                                         




Host name 별칭 설정 (공통) => node1, node2



/etc/hosts 파일에 서버의 별칭을 설정 한다.

[root@nell-node1 /]# vi /etc/hosts

#DRBD

192.168.80.110 nell-node1

192.168.80.111 nell-node2





                                                                                                                         

NTP 동기화 (공통) => node1, node2



서버의 날짜 및 시간이 맞지 않으면 동기화가 되지 않을수 있기 때문에 crontab을 이용하여 주기 적으로 동기화 될수 있도록 설정 한다.

[root@nell-node1 /]# vi /etc/crontab

# NTP 동기화

# 매 1분마다 동기화를 진행하므로 NTP서버를 직접 구축해서 사용하는 것을 권장 한다.

1 * * * * root ntpdate 1.kr.pool.ntp.org






                                                                                                                         




만약 disk를 추가하였다면 lvm을 사용하여 /sd"X" 추가 해야한다.



[root@nell-node1 /]# fdisk /dev/sdb

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

switch off the mode (command 'c') and change display units to

sectors (command 'u').

Command (m for help): p

Disk /dev/sdb: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x1bc263a6

Device Boot Start End Blocks Id System

/dev/sdb1 1 2610 20964793+ 82 Linux swap / Solaris

Command (m for help):

Command (m for help):

Command (m for help): m

Command action

a toggle a bootable flag

b edit bsd disklabel

c toggle the dos compatibility flag

d delete a partition

l list known partition types

m print this menu

n add a new partition

o create a new empty DOS partition table

p print the partition table

q quit without saving changes

s create a new empty Sun disklabel

t change a partition's system id

u change display/entry units

v verify the partition table

w write table to disk and exit

x extra functionality (experts only)

Command (m for help):






추가 방법

                                                                                                                         

fdisk /dev/"sdb" <- 추가한 disk 또는 디바이스

"n" -> "e" -> "p" -> "1" -> "1" -> "엔터"

1은 default 를 가르킨다 혹은 내가 지정할 용량을 적어도 된다.








디바이스 확인                                                                                                                         


[root@nell-node1 /]# fdisk -l



Disk /dev/sda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x000b89b6

Device Boot Start End Blocks Id System

/dev/sda1 * 1 26 204800 83 Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2 26 287 2097152 82 Linux swap / Solaris

Partition 2 does not end on cylinder boundary.

/dev/sda3 287 2611 18668544 83 Linux

Disk /dev/sdb: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x1bc263a6

Device Boot Start End Blocks Id System

/dev/sdb1 1 2610 20964793+ 82 Linux swap / Solaris -> 추가된 디바이스








DRBD 설치 (공통) => node1, node2

                                                                                                                         




elrepo의 저장소를 추가 하고 설치 한다.

[root@nell-node1 /]# rpm -ivh
http://elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm

[root@nell-node1 /]# yum install -y kmod-drbd84 drbd84-utils




수동으로 DRBD Module을 커널에 적재 시킨다.

[root@nell-node1 /]# modprobe drbd










DRBD 설정 (공통) => node1, node2

                                                                                                                         




"drbd_disk1.res 라는 이름으로 설정 파일을 하나 생성하고 아래와 같이 사용자의 환경에 맞게 변경 하자.

[root@nell-node1 /]# vi /etc/drbd.d/drbd_disk1.res



resource drbd_disk1 {

startup {

wfc-timeout 30;

outdated-wfc-timeout 20;

degr-wfc-timeout 30;

}

net {

cram-hmac-alg sha1;

shared-secret sync_disk;

}

syncer {

rate 100M;

verify-alg sha1;

}

on nell-node1 {                                               # node의 host name 별칭

device /dev/drbd0;                                          # drbd의 논리 블록 디바이스명

disk /dev/sdb1;                                              # 실제 디스크 디바이스명

address 192.168.80.110:7789;               # port는 /etc/sysconfig/iptables에 추가

meta-disk internal;

}

on nell-node2 {

device /dev/drbd0;

disk /dev/sdb1;

address 192.168.80.111:7789;

meta-disk internal;

}

}














DRBD Meta data 생성 (공통) => node1, node2

                                                                                                                         


[root@nell-node1 /]# drbdadm create-md drdb_disk1


riting meta data...

initializing activity log

NOT initializing bitmap

New drbd meta data block successfully created.

success








간혹 아래와 같은 이유로 meta data가 생성이 안될 경우가 있다.


Device size would be truncated, which would corrupt data and result in 'access beyond end of device' errors.

You need to either

* use external meta data (recommended)

* shrink that filesystem first

* zero out the device (destroy the filesystem)

Operation refused.

Command 'drbdmeta 0 v08 /dev/sdb internal create-md' terminated with exit code 40









해결책은 디스크를 초기화 시켜 버리고 생성하면 된다.

[root@nell-node1 /]# dd if=/dev/zero of=/dev/sdb1 bs=1M











DRBD 실행 (공통) => node1, node2

                                                                                                                         



Starting DRBD resources: [

create res: drbd_disk1

prepare disk: drbd_disk1

adjust disk: drbd_disk1

adjust net: drbd_disk1

]

..........





node1 과 node2를 같이 실행해야 접속이 된다.

                                                                                                                         



간혹 아래 메세지가 나오는 경우가 있을수 있다. 아래 메세지는 동기화 하려는 서버와 연결을 맺고자 대기 타고있는데 시간을 초과하여 실행을 할수 없다는 뜻이다.

따라서, 동기화할 서버를 30초이내에 시작하면 해결된다. (대기 시간 변경은 drbd_disk.res 리소스 설정 파일에 "wfc-timeout"를 적절히 변경 하면 된다.)






DRBD's startup script waits for the peer node(s) to appear.

- In case this node was already a degraded cluster before the

reboot the timeout is 30 seconds. [degr-wfc-timeout]

- If the peer was available before the reboot the timeout will

expire after 30 seconds. [wfc-timeout]

(These values are for resource 'drbd_disk1'; 0 sec -> wait forever)

To abort waiting enter 'yes' [ 15]:









************동기화 모드 설정*************


                                                                                                                         



nell-node1 서버를 primary로 지정 하겠다.

[root@nell-node1 /]# drbdadm primary --force drbd_disk1








이후 Primary와 Secondary의 동기화가 완료 될때까지 기다리자.

[root@nell-node1 /]# drbd-overview 


0:drbd_disk1/0 SyncSource Primary/Secondary UpToDate/Inconsistent C r-----

[=================>..] sync'ed: 92.2% (800/10236)M



---------------------------------------------------------




동기화가 완료 되면 이런식으로 나와야 한다.


[root@nell-node1 /]# drbd-overview

0:drbd_disk1/0 Connected Primary/Secondary UpToDate/UpToDate C r-----













DRBD Device 파일 포멧 (공통) => node1, node2


                                                                                                                         

drbd_disk1.res 에서 지정한 "/dev/drbd0"를 ext4 파일 시스템으로 포멧 한다.

[root@nell-node1 /]# mkfs.ext4 /dev/drbd0











동기화 테스트


                                                                                                                         



마운트 할 디렉토리를 생성 하고 마운트 하자.

[root@nell-node1 /]# mkdir /drbd_disk1

[root@nell-node1 /]# mount /dev/drbd0 /drbd_disk1

[root@nell-node1 /]# mount | grep drbd



/dev/drbd0 on /drbd_disk1 type ext4 (rw)




간단한 파일을 생성하여 테스트

[root@nell-node1 /]# echo "mallo" > /drbd_disk1/drbd-test.txt

[root@nell-node1 /]# ls -al /drbd_disk





total 28

drwxr-xr-x. 3 root root 4096 Sep 17 19:19 .

dr-xr-xr-x. 26 root root 4096 Sep 16 19:30 ..

-rw-r--r--. 1 root root 6 Sep 17 19:19 drbd-test.txt

drwx------. 2 root root 16384 Sep 17 18:10 lost+found








[root@nell-node1 /]# cat /drbd_disk1/drbd-test.txt


mallo



이제 Primary로 지정한 ruo91-node1에서 /dev/drbd0를 마운트 해제 하고,

Secondary로 지정된 ruo91-node2서버에서 생성한 파일이 존재 하는지 확인을 해보겠다.









nell-node1에서 마운트를 해제 하자.


                                                                                                                         



[root@nell-node1 /]# umount /dev/drbd0

초보라면 흔히 할 수 있는 실수 마운트 해제 할 디렉토리 안에서 


마운트 해제를 하면 안된다







Primary에서 Secondary로 변경 하자.


                                                                                                                         


[root@nell-node1 /]# drbdadm secondary drbd_disk1











Secondary로 변경이 되었는지 확인 하자.


                                                                                                                         


[root@nell-node1 /]# drbd-overview




0:drbd_disk1/0 Connected Secondary/Secondary UpToDate/UpToDate C r-----











nell-node2


                                                                                                                         



nell-node2에서 Secondary를 Primary 상태로 변경 한다.


[root@nell-node1 /]# drbdadm primary drbd_disk1












마운트 할 디렉토리를 생성 하고 마운트 한다.


                                                                                                                         



[root@nell-node1 /]# mkdir /drbd_disk1

[root@nell-node1 /]# mount /dev/drbd0 /drbd_disk1

[root@nell-node1 /]# mount | grep drbd



/dev/drbd0 on /drbd_disk1 type ext4 (rw)







이제 nell-node1에서 생성한 파일이 존재 하는지 확인 하자.


[root@nell-node1 /]# ls -al /drbd_disk1/






total 28

drwxr-xr-x. 3 root root 4096 Sep 17 19:19 .

dr-xr-xr-x. 26 root root 4096 Sep 16 19:30 ..

-rw-r--r--. 1 root root 6 Sep 17 19:19 drbd-test.txt

drwx------. 2 root root 16384 Sep 17 18:10 lost+found















2014년 9월 4일 목요일

PuTTY 접속 속도 향상시키는 방법





  1. PuTTY는 SSH, 텔넷, rlogin, raw TCP를 위한 클라이언트로 동작하는 자유 및 오픈 소스 단말 에뮬레이터 응용 프로그램이다. PuTTY라는 이름에는 특별한 뜻이 없으나 tty는 유닉스 전통의 터미널의 이름을 가리키며 teletype를 짧게 줄인 것이다. PuTTY는 본래 마이크로소프트 윈도용으로 작성되었으나 다른 다양한 운영 체제에도 포팅되었다. 위키백과



1. # vi /etc/ssh/sshd_config




2. # /etc/init.d/sshd restart







소소한 팁
                                                  :)



VMware Clone 후 eth0인식 안될 때?





VMware에서 Linux Clone을 하게 되면 eht0을 인식하지 않고 eth1을 인식하게 된다.





1. 원인은 MAC address가 바뀌어서 그렇다.


# vi /etc/udev/rules.d/70-persistent-net.rules




PCI device가 eth1로 한줄 더 생성되어 있다.






2. PCI device 두개 중 하나를 삭제 해버리고 NAME="eth1" 자리에 "eth0" 과  "새 MAC 주소"로 변경해야 한다.







3. “eth0” mac주소도 위와 마찬가지로 변경한다.



# vi /etc/sysconfig/network-script/ifcfg-eth0

VMware -> Generate로 생성한 새 MAC주소 저장




MSSQL Memory 제한






MSSQL은 기본으로 메모리용량을 할당 받아놓고 작업을 하기 때문에 사용하지 않더라도 메모리를 차지하고 있다. 그러므로 사이즈를 줄여 준다면 서버 자원을 낭비하지 않을 수 있다. 



1. SQL 속성 클릭








2. Memory 부분에 "Maximum server memory" 현재 서버의 스펙에 맞춰 
   용량을 낮춰 준다.



MsSQL DB Backup schedule 등록하는 방법






1.     SQL connect Management -> Maintenance Plans -> Maintenance Plans wizard




2.     Plans Name 입력 “ Backup Plan “







3. Tasks 선택 – Full, Diff, Trans, Maintenance Cleanup







4. Databases -> All user databases 
-> Create a subdirectory for each database 
Schedule :  Full / week  ,  Diff / day  ,  Trans / Hour
Full -> weekly -> Monday -> 06:00 AM






5. Schedule -> Full per weekly , Diff per Daily , Trans per Hourly 







6.     Diff -> daily -> 06:30 AM






7. Trnas -> Daily -> Occurs every 1 hours






8. Cleanup Plan -> .bak -> Delete files 4 weeks after





9.  Execute finish





10.     SQL Agent -> Jobs -> start Job at step… ( Full, Diff, Tran, Clean )






                                                    :)