시스템관련 테크닉(&Tip)

2010.05.12 03:32

조인상 조회 수:7986

원문 : http://www.ischo.net -- 조인상 // 시스템 엔지니어

Writer : http://www.ischo.net -- ischo // System Engineer in Replubic Of Korea

+++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

본문 : http://www.ischo.net -- 조인상 //시스템 엔지니어

+++++++++++++++++++++++++++++++++++++++++++++++++++++++



23.1 Large dummy file 생성 방법




dd를 이용한 Create large files

Systax :

dd if=file of=file bs=n count=n

examples : 아래의 예는 100Mbyte의 dummy file을 만든다.

[dct:/tmp]# dd if=/dev/zero of=100megs bs=10000 count=10000

10000+0 records in

10000+0 records out

[dct:/tmp]# ls -al 100megs

-rw-r--r-- 1 root other 100000000 10월 20일 17:34 100megs

[sun:/tmp]#

; bs - 버퍼에 확보될 block size

count - bs에서 설정된 size의 buffer를 dummy file로 copy할 횟수

위의 예는 10000block을 10000번 copy하여 100Mbyte의 bummy file을 생성한다.







23.2 DOS file에서 ^M 문자 제거 방법




아래 예는 간혹 DOS에서 편집된 텍스트 파일을 유닉스 machine에서 열 경우 각 line 끝에 ^M를 볼수 있는데, 이를 제거할수 있는 방법 3가지를 보여준다

1) tr을 이용한 제거 방법

Syntax : tr -d string < infile > outfile

dct# tr -d "\015" < /tmp/hosts.dos > /tmp/hosts.unix

2) sed을 이용한 제거 방법

Syntax : sed 's/[regular expression]/[Replacement]/[flags]/g' infile > outfile

dct# sed 's/^V^M//g' /tmp/hosts.dos > /tmp/hosts.unix

3) vi 편집기를 이용한 방법

dct# vi /tmp/hosts.dos 열리면, vi command line상에서 아래와 같이 한다.

:%s/^V^M//g







23.3 두 개의 모니터에 Openwindows 올릴때




openwin -dev /dev/fbb/?? -dev /dev/fbb/??

또는 ?? openwin -dev /dev/fbb/??

?? openwin -dev /dev/fbb/??







23.4 rdist사용하여 정해진 시간에 화일 transfer




rdist - remote file distribution program

rdist 명령어를 사용하기 위해서는 /etc/hosts.equiv file과 /.rhosts file을 원하는 host와 사용자에 맞게 editing하여 주어야 한다.

remote file transfer를 위해서는 각각의 시스템에 /etc/hosts.equiv file을 만들어 각각의 시스템을 명명하여 주거나, +라고 써주어 모든 시스템에서 수행하는 r명령어 (rcp, rsh, rlogin, rdist...)에 대해 open을 시켜주어야 한다.

또는 각각의 사용자 홈디렉토리에 .rhosts file을 만들어야 한다.




rdist에는 여러가지 option이 있다.

이러한 option들은 "man rdist"를 수행하면 살펴볼수 있는데, 정해진 시간에 파일을 전송하면서

세부적인 사항을 미리 선택하기 위해서는 '-f' option을 사용하는 것이 좋다.




여기에서는 실제로 rdist command를 사용하여 file transfer하는 예를 보기로 하겠다.




source host = TECH

destination host = sun




1. 먼저 TECH의 /etc/hosts.equiv file을 편집.

www

cello

mymy

sun (여기에서는 기존의 entry에 hyundai2를 추가함.

다른 것 없이 그냥 +만 써넣어도 됨 )




2. /.rhosts file등에도 다음과 같이 하여준다.

+

+ sms




3. 그리고 만일 eng라는 디렉토리를 transfer하려고 할 때, 막상 transfer하고 보면

eng라는 parent directory는 보이지 않고 그 안의 sub directory만이 보이게 된다.

즉 나는 /eng라는 이름과 함께 그 밑의 sub directory인 words, toeic, read등을 transfer하려

한다면 targer이 되는 시스템의 원하는 위치에 eng라는 이름의 디렉토리를 만들어 두는 것이

편하다는 것이다.




4. description file을 작성한다.

다음은 sms라는 사용자가 remote system상의 sms에게 file을 transfer하는 것이다.

이 화일의 이름은 사용자 임의로 주어도 된다.

이 예에서 description file의 이름은 distfile이다.




HOSTS = ( sms@sun ) --> hostname만 써넣어도 된다.

FILES = (/user1/sms/eng) --> transfer하기 원하는 화일의 위치

${FILES} -> ${HOSTS}

install -R ~sms/eng; --> transfer된 화일을 install하기 원하는 위치

except (/user1/sms/eng/toeic); --> transfer를 원하지 않는 화일이나 directory

있다면 이를 지정할 수 있다.

${FILES} :: /bin/time --> transfered time을 파악하여 notify sms@sun;

메일로 알려줌.




5. 이 상태에서

# rdist -f distfile 을 수행하면 바로 원하는 화일이 description file에

정해진 대로 전송된다.

이 명령어를 수행하면 다음의 예와 같은 내용이 화면에 출력된다.




tech /tmp> rdist -f distfile

updating host sun

/tmp: Warning: remote mode 1777 != local mode 755

installing: /user1/sms/eng/read

installing: /user1/sms/eng/read/1.txt

installing: /user1/sms/eng/read/2.txt

installing: /user1/sms/eng/read/3.txt

installing: /user1/sms/eng/read/4.txt

installing: /user1/sms/eng/read/5.txt

installing: /user1/sms/eng/read/6.txt

installing: /user1/sms/eng/read/7.txt

installing: /user1/sms/eng/read/ab1.txt

installing: /user1/sms/eng/read/ab2.txt

installing: /user1/sms/eng/read/ab3.txt

installing: /user1/sms/eng/read/ab4.txt

installing: /user1/sms/eng/read/ab5.txt

installing: /user1/sms/eng/toeic

installing: /user1/sms/eng/toeic/f1

installing: /user1/sms/eng/toeic/f2

installing: /user1/sms/eng/toeic/f3

installing: /user1/sms/eng/toeic/f4

installing: /user1/sms/eng/toeic/f5

installing: /user1/sms/eng/toeic/f6

installing: /user1/sms/eng/toeic/e1

installing: /user1/sms/eng/toeic/e2

installing: /user1/sms/eng/toeic/e3

installing: /user1/sms/eng/toeic/e4

notify ( sms@sun )




정해진 시간에 전송하려면 결국 crontab을 사용하여야 한다.

/var/spool/cron/crontabs 밑에 사용자별로 있는 화일을 문법에 맞게 setting한다.


다음 예는 화요일 14시 16분에 이 명령어를 수행하라는 예이다.

16 14 * * 2 /bin/rdist -f /user1/sms/distfile




6. 일단 crontabs에 등록, cron daemon kill, /etc/cron.d/FIFO delete, /usr/sbin/cron 수행

하고나면 변경된 crontabs내용이 실행된다.




7. 주의 할것은 source file의 permission과 destination directory의 permission.

만일 source는 root permission인데, destination directory가 일반 사용자 permission

이라면 명령어 수행도중 permission error 생길 수 있다.







23.5 Prompt변경(HostName & CurrentPath Display)




1) korn shell인 경우

(1) dir function만들기

dir()

{

cd $1

PS1="<'uname -n'><'pwd'>

}

(2) alias시키기

alias cd=dir




2) C Shell인 경우

alias cd 'cd \!*;set prompt="`hostname`:`pwd`>"'

or

?? alias setprompt 'set prompt="[`hostname`:$cwd]# "'

? alias cd 'cd \!*; setprompt'

?? setprompt







23.6 임시Host_name변경




# hostname sun;source /.cshrc

임시로 호스트명이 sun으로 바뀌고, /etc/nodename도 sun으로 바뀌고,

prompt에 나타난 host_name도 sun으로 바꾼다.







23.7 /file system 100% 일 경우 유용한 command.




/tmp: If several large files are here, reboot and they will be cleaned out.

/dev: Large files may appear here when trying to write to a device andusing the

incorrect device name (i.e. /dev/rsto instead of /dev/rst0)

/: Look for core files

/var: If var is part of the root partition, check for large administration files in

/var/adm. Also, some spool files may be left in the /var/spool directories.

Check for other large files (over 1mb) with the command:

find / -size +1000000c -xdev -print




tape 작업시 누군가 /dev/rst0 를 주었음. 2.x 에서는 /dev/rst0 가 존재하지않음. 따라서 이것이

약 9 M 정도의 file 이 되어 system full 이됨.







23.8 man page에 관한 몇가지




man은 Solaris의 명령어의 문법과 자세한 설명을 볼수 있는 일종의 manual이다. 이러한 man을 통하여 명령어의 적절한 사용법과 예제, 관련된 다른 명령어까지도 참조 할 수 있다.

이러한 man을 사용하다 겪는 몇가지 문제점과 man을 더욱 잘 사용하기 위해 만들어지는 windex에 대해서 몇가지를 간단히 정리해보려 한다.




1. Solaris install후에 man page만 따로 install하는 경우




volume manager는 SUNWman package에 있다.따라서 O/S CD를 먼저 mount 시킨후에 pkgadd시킨다.

만일 Solaris 2.4에서 cdrom이 /cdrom/cdrom0에 mount되어있다면 다음과 같이 하면 된다.




# cd /cdrom/cdrom0

# cd Solaris_2.4

# pkgadd -d . SUNWman




2. "XXXX에 대한 메뉴얼 항목이 없음.“ error

MANPATH에 manual page가 setting되어있음에도 불구하고 ‘man 명령어’하면 이와 같은 오류

메시지를 띄우면서 실행이 되지 않는 경우가 종종 있다. 이러한 경우에는 windex file에 대한

오류를 생각해 볼수 있다.




/windex file은 man page의 검색 속도를 높여주는데 사용된다.

만일 windex file이 존재하지만 찾고자 하는 entry가 빠져 있거나하면 위와 같은 오류메세지를

내면서 manual을 찾는데 실패한다.

각각의 MANPATH에 windex file이 있을수도 있다.

windex file은 다음의 몇가지 이유로 corrupt되어질 수 있다.




1) windex size = 0

: 이 경우에는 이 windex file을 지워주거나, man page를 더하기 위해




2) windex file에 몇가지 man page가 누락되었다.

: windex file이 만들어진 후에 man page가 추가되는 경우도 많다.

catman -w를 실행하여 파일을 다시 만든다.




3) windex entry들이 alphabetical order를 따르지 않는다.

: 수동으로 (by hand)로 editing한 경우에 발생.

windex file을 sort하거나 catman -w를 실행한다.




4) windex file의 시작 부분에 additional characters가 있을 때 이러한 문제가 생길수 있다.

일반적으로 troff나 nroff characters가 삽입되어 있는 경우가 많다.

: 예제>

잘된 예 ==> ypbind ypbind(1m) -NIS binder process

잘못된 예 ==> /f4ypbind ypbind(1m) -NIS binder process




3. "sh: less not found" error가 나오는 경우

/usr/ucb/man command가 내는 error:

Reformatting page. Wait...done

sh: less: not found

man command는 man page를 화면에 맞추기 위해 reformat을 하게 되는데 이때 nroff를 부른다. 또한 연이어서 nroff에서 나오는 output이 more command와 연계되어진다.

하지만 만일 PAGER라는 환경변수가 “less:로 setting되어 있다면 이와 같은 오류가 생길수 있다.

“less" command는 Sun에서는 지원되지 않는 것으로 more command와 비슷한 command이다. 만일 시스템이 less command찾기를 실패하면 man command또한 오류를 일으킨다.




1) less command가 상주하고 있는 directory를 PATH 변수에 설정해준다.




2) PAGER변수를 “more"로 setting해주거나, ” unsetenv PAGER "로 변수를 제거해준다.




4. “ nroff: 임시 파일을 생성할 수 없음. ” error가 나오는 경우

(reformatting page. wait...nroff: cannot create temp file

sh: /dev/null: cannot create)

이러한 경우 /var/tmp의 permission이 1777인지 확인한다.

정상적인 경우는 다음과 같이 보인다.

drwxrwxrwt 2 sys sys 1536 11월 29일 16:47 tmp

이 permission이 맞지 않으면 일반 사용자 모드에서 man 사용시 이런 오류가 발생한다. SunOS5.x의 nroff는 임시 파일을 쓰기 위해 /var/tmp를 사용한다. 하지만, SunOS 5.1과 SunOS 5.2는 /var/tmp가 아니라 var/tmp가 아니라 /tmp를 사용한다.

SunOS 4.x에서도 /tmp 의 permission을 확인해야 한다.




5. man page를 간단히 프린트 할수 있는 방법

man에 -t option을 사용한다.

-t option은 default printer상에 manual page를 reformat하고 display하는데 사용된다.

다음의 세가지 환경 변수가 output을 customizing하는데 사용된다.




PRINTER : to set a new default printer

TROFF : to change the format utility

Usually changed to nroff on non-newsprint printers.

TCAT : the display program. Defaults to lpr -t







23.9 Login User중 idle time check하여 자동 kill(script)




내용은 host 로 Login한 User중 Idle time이 10분 이상 초과한 User를

자동으로 Kill하는 Procedure 한것이다.




# SunOS 4.1.3

finger | grep -v root | grep -v oracle |grep svc | cut -c32-38 > /tmp/_list

cat /tmp/_list |cut -c1-2 > /tmp/col1;cat /tmp/_list |cut -c3-7 > /tmp/col2

_tab=`paste -d" " /tmp/col2 /tmp/col1 |\

grep -v " " |grep -v " [1-9]"|cut -c7-8`

for i in $_tab

do

/etc/fuser -k /dev/tty$i

done




# Solaris 2.5

finger | grep -v root |grep -v oracle |grep svc | cut -c32-47 > /tmp/_list

cat /tmp/_list | cut -c1-7 > /tmp/col1;cat /tmp/_list | cut -c8-16 > /tmp/col2

_tab=`paste -d" " /tmp/col2 /tmp/col1 |\

grep -v " " |grep -v " [1-9]"| cut -c11-17`

for i in $_tab

do

fuser -k /dev/$i

done




이상의 Script를 crontab에 등록하여 1분 간격으로 돌려준다.







23.10 login 보안 및 audit관련 Tip




/etc/default/login 변수...

- CONSOLE 변수는 root로 login가능한 device지정

예제)

워크스테이션의 콘솔을 지정하는 경우 또는 배제

CONSOLE=/dev/console

#CONSOLE=/dev/console

콘솔에서조차 login불능

CONSOLE=/dev/null

- PASSREQ=YES (PASSWD를 꼭 필요로 함, default NO)

예제)

MAXWEEKS=15 /* 15주 이상이면 유효기간 만료 */

MINWEEKS=3 /* 최소한 3주는 사용하여야 함 */

PASSLENGTH=6 /* Passwd의 최대의 길이 */

INACTIVE=30 /* 30주 이상 안쓰면 account locking */

EXPIRATE_DATE=1997.12.31 /* Passwd 소멸일자 */

- SYSLOG=YES ( root login 및 fail에 대한 audit자료 수집 허용여부 ,

audit는 /etc/syslog.conf에 지정된 file에 저장된다. )

/etc/default/passwd file은 default로 password aging관련 파일이다.

/etc/default/su file은 SULOG=/var/adm/sulog등으로 log파일을 지정할 수 있다.

- /etc/ftpuser file에 등록된 host들은 ftp service 불허

- ftp auditing setting

www% vi /etc/inetd.conf /* 수정 */

...

#ftp stream tcp nowait root /usr/local/etc/ftpd ftpd

ftp stream tcp nowait root /usr/sbin/in.ftpd in.ftpd -l

...




www% vi /etc/syslog.conf

...

daemon.info ifdef(`LOGHOST', /var/adm/ftp.log, @loghost)

...




syslogd daemon restart




- /var/adm/loginlog file을 만들어 놓으면 5번의 login log fail를

기록할 수 있게 된다.




- /etc/nologin file을 생성하면 모든 사용자 login을 불가능하게 한다.

물론 root user를 제외하고는...

그러므로 더이상의 login을 허용하고자 하지 않을 때 사용한다.

nologin file은 rebooting할 때 없어지므로 manual하게 만들든지 또는

crontab에 등록할 수 있다.




- logins -d ( 중복된 user check )

- logins -p ( null passwd user check )







23.11 시스템에 유저 접근 거부 시킬때




시스템 점검등에 유용할 것이다.

일반 계정의 유저는 접근이 거부되고, 슈퍼유저는 접속 가능하다.

# touch /etc/nologin

# vi ... 왜 접근을 거부하는지 에 대한 내용을 포함 시킨다.

# cat /etc/nologin

The system is down right now for routine maintenancee

and should be back inline by 23:00.

Please check back at this time.

Thank you for your understanding,

the SYSTEM Admins
번호 제목 글쓴이 날짜 조회 수
공지 [공지] 게시자료 열람자유. 불펌금지입니다. 조인상 2010.12.07 20160
73 같은아이디로 여러번 로그인(멀티로그인) 금지 방법 조인상 2010.05.12 10671
72 솔라리스 10 접속서비스 설정 (telnet ftp ssh) 조인상 2010.05.12 16469
71 NIC 속도 확인방법 조인상 2010.05.12 19779
70 Solaris Volume Manager Admin Guide file 조인상 2010.05.12 7824
69 솔라리스 10 매뉴얼 file 조인상 2010.05.12 14213
68 about iostat 조인상 2010.05.12 7796
67 number of files (nofiles : File descriptor)값 변경하는 법 조인상 2010.05.12 11751
66 Solaris 10 Virtual Exam file 조인상 2010.05.12 6521
65 Sun Performance And Tuning - Sparc & Solaris file 조인상 2010.05.12 6497
64 솔라리스 이더넷카드 인터페이스 종류 조인상 2010.05.12 8991
63 SUN 용 시리얼케이블 제작법 file 조인상 2010.05.12 16186
62 Sun/Qlogic HBA WWN 알아보는법 조인상 2010.05.12 18272
61 운영체제별 명령어 비교 조인상 2010.05.12 7110
60 SUN T3 Array 뒷면 LED 정보 file 조인상 2010.05.12 7631
59 CPU offline 시키는 방법 조인상 2010.05.12 8068
» 시스템관련 테크닉(&Tip) 조인상 2010.05.12 7986
57 최대 프로세스 확인하는 방법과 변경 방법 조인상 2010.05.12 9875
56 telnet 접속시 No utmpx entry. You must exec "login" from the lowes 조인상 2010.05.12 14874
55 패치 오류 (error code) 조인상 2010.05.12 6363
54 파이프를 이용한 tar와 압축의 동시수행 조인상 2010.05.12 8342
서버에 요청 중입니다. 잠시만 기다려 주십시오...