솔라리스 어드민

1부. 솔라리스 소개

1. 유닉스 정의

유닉스는 1969년에 벨 연구소에서 인터랙티브 시분할 시스템으로서 만든 것이 그 시초가 된 운영체계이다. 켄 톰슨과 데니스 리치가 유닉스의 창시자로 알려져 있다. 유닉스라는 이름은 그 이전의 시스템인 멀틱스에 기반을 두고 지은 일종의 말장난이었다. 1974년에 유닉스는 C 언어로 쓰여진 최초의 운영체계가 되었다. 유닉스는 여러 회사들이나 대학 및 개인들에 의해 많은 확장판과 새로운 아이디어들이 다양한 버전의 유닉스에 추가됨으로써, 대형 프리웨어 제품의 한 종류로 진화하였다. 유닉스는 앞서가는 특정 컴퓨터 회사들에 의해 소유된 독점적인 운영체계가 아니었다는 것과, 또 그것이 표준 프로그래밍 언어로 작성되고, 대중적인 많은 아이디어를 받아들였다는 이유 때문에, 누구에 의해서도 개선되고 강화될 수 있는 최초의 개방형 표준 운영체계가 되었다. 다양한 버전의 유닉스로부터 나온 C 언어와 쉘 인터페이스의 복합체는 IEEE의 찬조 하에서 POSIX로 표준화되었다. POSIX 인터페이스들은 번갈아 가며, X/Open 프로그래밍 가이드 4.2 (“단일 유닉스 규격”과 “유닉스95″로 알려져 있다)에 명기되었다. 단일 유닉스 규격의 버전2는 유닉스98로도 알려져 있다. 유닉스의 공식적인 등록상표는 현재 산업표준기구인 오픈 그룹이 소유하고 있으며, 유닉스 관련 제품들의 인증과 상표부여 등을 관장하고 있다.

유닉스 운영체계는 널리 판매된 썬마이크로시스템즈(Solaris), 실리콘그래픽스(IRIX), IBM(AIX), 그리고 그 외 많은 회사들의 워크스테이션 제품들에서 사용된다. 유닉스 환경과 클라이언트/서버 프로그램 모델은 인터넷 개발과 네트워크 중심의 컴퓨팅 국면을 새로이 하기 위한 중요한 요소였다. 유닉스에서 파생하여, 현재 무료 소프트웨어와 상용버전이 모두 존재하는 리눅스는 독점 운영체계의 대안으로서 명성을 더해가고 있다.

2. 유닉스의 특징

– 멀티태스킹과 멀티유저 지원

– 용이한 이식성

– 계층적 파일 시스템 구조 (Hierarchical File System)

– Security 및 Protection 기능

– 입출력의 방향 전환 및 파이프 기능

– 확장성과 조직성이 풍부한 Shell

– 각종 Special Devices의 독립성

– 유연성 있는 커뮤니케이션을 할 수 있는 운영체제

– 언어 및 유틸리티가 다양하여 프로그램 개발이 용이

3. UNIX의 구성요소

1) Kernel : Unix의 핵이며 File system, Device, Memory, Process 관리.

2) Shell : Command Interpreter로 사용자와 커널간의 인터페이스 역할과 명령을 해석.

3) File System (Directory Tree)

파일 시스템은 커널이 데이터를 관리하기 위한 파일 또는 디렉터리의 관리 구조이다.

4. UNIX의 종류

– Sun OS : 썬 마이크로시스템즈에서 제공하는 BSD 계열의 UNIX

– Solaris : 썬 마이크로시스템즈에서 제공하는 System V 계열의 UNIX

– HP/UX : HP의 UNIX 시스템은 OSF/1(Open Software Foundation)의 여러 특징을 도입한 System V의 변형된 형태

– AIX : IBM에서 System V release 4의 4.4 BSD 버전과 OSF/1을 기반으로 만들어낸 UNIX

– Digital UNIX:  OSF그룹에서 System VR3과 4.3 BSD버전을 결합시키고 OSF/1을 기반으로 발전된 DEC(현재 Compaq)의 UNIX

– IRIX : 실리콘 그래픽스에서 BSD와 System V계열의 UNIX를 기반으로 만들어진 UNIX

5. Solaris OS

4.2 버전까지 BSD를 만들던 버클리의 빌 조이가 썬 마이크로시스템즈로 옮겨가서 만든 것이 SUN OS이며 썬 마이크로시스템즈가 AT&T의 System V release 4.0의 라이선스를 받아 만든 것이 Solaris이다.

1) 버전간의 관계

Solaris 2.x = Sun OS 5.x + Open Windows + ONC+(Open Network Computing: NFS, NIS, NIS+등)

Solaris 7  = Sun OS 5.7 + Open Windows, CDE(Common Desktop Env) + ONC+(Open Network Computing: NFS, NIS, NIS+등)

Solaris 8  = Sun OS 5.8  +  OpenWindows, CDE(Common Desktop Env)  + ONC+(Open Network Computing: NFS, NIS, NIS+등)

Solaris 9  = Sun OS 5.9  +  OpenWindows, CDE(Common Desktop Env)  + ONC+(Open Network Computing: NFS, NIS, NIS+등)

2) 장비 별 지원 OS 버전

  SunOS 5.x = Solaris 2.x

  Sun dropped the “2.” when Solaris (2.)7 came out.  

          I.e. Solaris 7 = “Solaris 2.7” = SunOS 5.7,

          Solaris 8 = “Solaris 2.8” = SunOS 5.8 and so on.

  Sun2: SunOS 4.0.3 or earlier.

  Sun386i: SunOS 4.0, 4.0.1, 4.0.2 only.

  Sun3: SunOS 4.1.1 or earlier.

  4/100, 4/200 series: SunOS 3.2, SunOS 4.0 through 5.4

  4/300 series: SunOS 4.0.3 through 5.4

  4/400 series: SunOS 4.1PSR_A through 5.4

  600 models 120, 140: SunOS 4.1.2 through 5.5.1

  600 model 41, 51: SunOS 4.1.3 through 5.5.1

  SPARCstation 1, 1+, SLC, IPC: SunOS 4.0.3 through 5.7

  SPARCstation 2, ELC, IPX: SunOS 4.1.1 through 5.7

  SPARCstation 4: SunOS 4.1.4 or later.

  SPARCstation 5: SunOS 4.1.3_U1B or later.

  SPARCstation 10 models 20, 30, 40, 41, 51, 61, 71: SunOS 4.1.3 or later.

  SPARCstation 20 models 50, 51, 61, 71: SunOS 4.1.3_U1B or later.

  SPARCstation 20 model HS11, HS21, 151: SunOS 4.1.4 or later.

  SPARCclassic, SPARCstation LX: SunOS 4.1.3C or later.

  SPARCstation Voyager: Solaris 2.3 edition II or later.

  Ultra 1 model 140, 170: Solaris 2.5 or later.

  Ultra 1 model 140E, 170E, 200E:  Solaris 2.5.1 or later.

  Ultra 2: Solaris 2.5.1 or later.

  Ultra 5, 10, 30, 60, 250, 450: Solaris 2.5.1HW1297 or Solaris 2.6HW0398 or later.

  Ultra Enterprise: Solaris 2.5.1 or later.

  SunBlade 100, SunBlade 1000, SunFire 280R: Solaris 8HW1000 or later.

  SunFire 3800, 4800, 4810, 6800: Solaris 8HW0401 or later.

– OS 버전의 확인

# uname -a

SunOS sonamu 5.8 Generic_108528-15 sun4u sparc SUNW,Ultra-1

– 솔라리스 정보

솔라리스 9

http://kr.sun.com/products/software/os_platforms/solaris/index.html

솔라리스 8

http://kr.sun.com/products/software/os_platforms/solaris/8/index.html

전체 버전 간의 차이 비교

http://wwws.sun.com/software/solaris/fcc/fcc.html

솔라리스 x86(Intel) 하드웨어 호환 리스트(HCL)

http://www.sun.com/bigadmin/hcl/

6. SUN & Solaris 관련 사이트

1) 썬 관련 레퍼런스 (추천)

http://www.stokely.com/unix.sysadm.resources/faqs.sun.html

2) 썬 공식 도큐먼트

http://docs.sun.com

http://www.sun.com/bigadmin/ (BigAdmin System Administration Portal)

3) SUN관련 FAQ

http://www.science.uva.nl/pub/solaris/solaris2.html (Solaris2 FAQ)

http://www.mreriksson.net/faqs/solaris8/ (Ola Eriksson’s FAQ for Sun Solaris )

http://wks.uts.ohio-state.edu/sun/faqs/s86faq.html ( Intel FAQ)

http://item-hunter.com/~chang/src/lecture/faq/sol2faq.html (한글)

http://hawk.com.kyungnam.ac.kr/~opti21/unix/faq/index.html (han.comp.sys.sun FAQ 한글)

4) Sun Managers Summaries  & Archives Search

http://www.sunmanagers.org ( 공식 홈페이지)

http://www.sunmanagers.org/archives.html ( 아카이브 리스트)

http://www.latech.edu/sunman-search.html ( 아카이브 검색)

http://news.google.co.kr ( 모든 뉴스 그룹 검색)

5) 장비 관련

http://sunsolve.sun.com/handbook_pub/Systems/ ( SUN 시스템 핸드북)

http://sunsolve.sun.com/handbook_pub/Devices/ ( SUN 부붐별 핸드북)

2부. 솔라리스의 접근과 사용자 관리

1. 시스템의 접근

1) Consol로 직접 로그인과 telnet, rsh, ssh (Shell 사용), Xmanager(Windows 사용) 등의 원격 로그인

– telnet : 이 기종간의 시스템 접근 가능 ( Port 23)

– rsh : Unix 기종간의 시스템 접근 가능

– ssh: Unix 기종간의 시스템 접근 가능 (보안쉘, Port 22)

http://www.openssl.org

http://www.openssh.org

2) 시스템 사용자: root와 일반 사용자

root: 슈퍼유저, 시스템 어드민, 초기 설치 시 패스워드 결정, 모든 권한, 기본쉘은 /sbin/sh

일반유저: 일반사용자.

3) 관련 파일

/etc/passwd 파일

user1:x:102:10:User Account 1: /export/home/user1:/bin/ksh

/etc/shadow 파일

user01:haN3NqcDfof.2:::::::

/etc/group 파일

other::1:user01,user02

4) 사용자 관리

/usr/bin/passwd 명령 : 자신의 패스워드 변경 (일반 유저), 다른 사용자의 패스워드 변경(root)

* 패스워드 생성 규칙(일반유저)

– 6~8 문자

– 두 개의 알파벳과 하나의 특수문자 또는 숫자 포함

– 로긴 이름과 다르게

– 변경 전 패스워드와 다르게

– 공백을 포함할 수 있다.

/usr/sbin/groupadd 명령 : 그룹을 생성 ( GID는 100 ~ 60000 번까지)

ex) # groupadd -g 100  class1

/usr/sbin/useradd 명령 : 유저를 생성 ( UID는 100 ~ 60000 번까지)

ex) # useradd -u 501 -g 100  -d  /export/home/user01 -m -c “User Account 1”  -s /bin/ksh user01

/usr/sbin/groupdel 명령 : 그룹을 제거

ex) # groupdel  class1

/usr/sbin/userdel 명령: 유저를 제거

ex) # userdel  [-r]  user01

/usr/sbin/usermod, /usr/sbin/groupmod 는 수정 시 사용

* 어드민 GUI 툴 : 사용자, 그룹, 호스트, 프린터, 직렬포트, 소프트웨어, 14(sysadmin) 그룹은 사용가능.

/usr/bin/admintool

3부. 사용자 기본 명령

사용자 기본명령은 다음을 참고한다.

http://www.gohtml.pe.kr/lec/unix1.html

http://unix.co.kr/data/solaris/?p=16

http://whoami21.com/~kimlee/telnet1.htm

http://www.hwaseong.ms.kr/unix1.htm

1. 정보 출력

1) 시스템 이름 및 OS버전 확인

$ uname -a

$ cat /etc/release (=> OS의 릴리즈 확인)

2) 현재 로그인한 사용자 정보

$ who (/var/adm/utmpx)

3) 최근 로긴했던 사용자 정보 + 재 부팅 정보

$ last (/var/adm/wtmpx)

$ last user01

$ last reboot

4) 프로세스 정보

$ ps -ef | grep netscape

$ pgrep netscape (solaris 8부터)

5) 날짜 및 시간 출력

$ date

$ cal

6) 맨 페이지

$ man man

$ man -k calendar

cf. # catman -w  (관리자 root가 실행)

$ man -s5  man (5 section manual)

– Section Definition –

관련 파일: /usr/share/man/man.cf, /usr/share/man/entities/*

1: User Commands

1M: System Administration Commands

2: System Calls

3: Basic Library Functions

4: File Formats

5: Standards, Environments and Macros

6: Demos

7: Device and Network Interfaces

9: Device Driver Interfaces

– 맨페이지 위치

/usr/share/man/

/usr/openwin/man/

/usr/dt/man

– 맨페이지 추가

# vi  /etc/profile

MANPATH=/usr/share/man:/usr/openwin/man:/usr/dt/man:<추가할 맨페이지 디렉토리>

export  MANPATH

2. 파일과 디렉토리 접근

주의 – 파일과 디렉토리, 명령 등은 모두 대소문자를 구별한다.

1) 패스이름

– 절대경로(Absolute Path Name) : root(/)를 기준으로 기술, /usr/local/src/file1

– 상대경로(Relative Path Name) :  현재 디렉터리를 기준으로 .또는 ..으로 기술, dir1/subdir1/file2

2) 관련 명령어

– ls(list) : 파일 또는 디렉터리의 리스트를 출력

– pwd(print working directory) : 현재 작업 디렉터리의 위치를 출력

– cd(change directory) : 작업 디렉토리를 변경

3.  파일과 디렉토리를 다루는 명령

– file : 파일 타입을 확인 (text, data, executable or binary)

– cat(catenate) : 주로 짧은 text파일을 볼 때

– more : 주로 긴 text파일을 볼 때

– strings: 바이너리 파일의 문자열만 보고자 할 때

– head: text파일의 머리부분(디폴트 10줄)만 보고자 할 때

– tail: text파일의 끝부분(디폴트 10줄)만 보고자 할 때  (tail -f /var/log/messages)

– wc(word count) : text파일의 라인 수, 단어 수, 문자 수를 알고자 할 때 ( wc file1)

– touch : 빈 파일을 생성할 때

– tee : 화면 출력과 파일 저장을 동시에 하고자 할 때 (ls -lR | tee logfile | more)

– mkdir : 디렉토리를 생성할 때

– rmdir : 빈 디렉토리를 제거할 때

– rm -r : 디렉토리를 제거할 때

– cp : 파일을 복사할 때

– cp -r : 디렉토리를 복사할 때

– mv : 파일 또는 디렉토리를 이름변경 또는 옮길 때

4. 파일과 텍스트 검색

– find : 파일 또는 디렉토리를 찾을 때

$ find / -name core

$ find  ~  -name  core  -exec  rm  {}  \;

$ find  .  -mtime  +90

$ find  ~  -size  +57

$ find  /usr  -name  ‘*tif’

– cmp, diff : 두 파일의 차이를 비교할 때

– sort : 파일의 내용 또는 리스트를 정렬할 때

$  ls -l | sort

$ du -ks /etc/*  | sort -nr

– grep : 파일의 특정 문자열이 있는 라인을 출력

$ grep user01 /etc/passwd

$ ps -ef | grep  ksh

5. 파일의 보안

$ ls -l

-rw-r–r–   1 borisu   staff       8239 2002년  8월 29일 backup.txt

-rw-r–r–   1 borisu   staff       2361 2002년  9월  3일 memo.txt

drwx——   5 borisu   staff        512  5월 20일  11:55 shell/

-rw-r–r–   1 borisu   staff       1660  4월 25일  01:37 ssh-setup.sh

File Type: -, f , d, c, b

Permission: read(r:4), write(w:2), execute(x:1)

User, Group, Others

1) 퍼미션 설정

$ chmod u+x file1 (symbolic mode)

$ chmod a=rx file1 (symbolic mode)

$ chmod 644 file1 (octal mode)

2) 소유권 변경 (root)

# chown user01 file1  (파일 소유자 변경 시)

# chgrp  class1  file1 (파일 그룹 소유자 변경 시)

# chown -R  user01:class1  dir1 (디렉토리 변경 시)

3) umask : 기본 퍼미션 제한

$ umask (확인)

$ touch file1

$ mkdir dir1

$ umask 027 (재설정)

$ touch fie2

$ touch dir2

6. Visual Editor (VI)

유닉스의 기본 편집기는 vi가 있고, 그밖에 emacs 등이 있다. GUI로는 dtpad가 있다.

– vi의 세가지 모드

Command Mode (명령 모드)

Edit Mode (편집 모드)

Last Line Mode (마지막 명령 라인 모드)

– vi 레퍼런스 카드 및 메뉴얼

http://kldp.org/응용_프로그램/에디터/Vi/

7. Archiving User Data

1) Archive 관련 명령

tar – Creates and extracts files from a tape device or file archive

compress, uncompress – Compress and uncompress a file

zcat – Uncompress a compressed file and sends the output to the screen without changing the compressed file.

gzip, gunzip – Compresses and uncompressed

gzcat – Uncompress a gzipped file and sends the output to the screen without changing the gzipped file

zip, unzip – Packages and compresses files and uncompressed files.

jar – Packages and comresses multiple files to a single archive file

cpio – Copies and extracts files fro a file archive or tape device.

[ tar ]

내용만 볼 때: tar tvf name.tar

풀 때       : tar xvf name.tar

만들 때     : tar cvf name.tar  file1 file2 file3

              tar cvf name.tar  dir1

$ cd

$ mkdir testdir

$ cd testdir

$ cp /etc/profile file1

$ man ls | col -b > file2

$ tar cvf first.tar file1 file2

$ rm  file? ; ls

$ tar tvf first.tar

$ tar xvf first.tar

$ cd ..

$ tar cvf second.tar testdir

$ rm -rf testdir

$ tar tvf second.tar

$ tar xvf second.tar

[ compress & uncompress ]

$ compress second.tar

$ ls

$ uncompress second.tar.Z

$ tar xvf second.tar

cf. zcat second.tar.Z | tar xvf –

cf. compress -dc second.tar.Z | tar xvf –

cf. uncompress -c second.tar.Z | tar xvf –

[ gzip ]

$ cd

$ cd ..

$ ls

$ tar cvf /var/tmp/myhome.tar user01

$ cd /var/tmp; ls

$ gzip myhome.tar

$ ls

$ gzip -d myhome.tar.gz

$ tar tvf myhome.tar

$ tar xvf myhome.tar

cf. gzcat myhome.tar.gz | tar xvf –

cf. gzip -dc myhome.tar.gz | tar xvf –

cf. gunzip -c myhome.tar.gz | tar xvf –

cf. gtar xvfz myhome.tar.gz

[ jar ]

$ jar cvf  dir1.jar  dir1

$ jar tvf  dir1.jar

$ jar xvf  dir1.jar

8. 원격지 접속

원격지 접속은 telnet, rlogin, ftp, ssh등이 있다.

1) telnet

원격 호스트의 user name과 password가 필요

$ telnet host1

…(접속해서 사용)

$ exit  (로그 아웃)

2) rlogin

원격 호스트에서 허락된 호스트 또는 유저의 경우 패스워드가 필요 없다.

자세한 사용법은 다음을 참고한다.

http://nscp.upenn.edu/aix4.3html/cmds/aixcmds4/rlogin.htm

– 일반유저:  /etc/hosts.equiv, $HOME/.rhosts

– root : /.rhosts

– 파일 형식 : 호스트 명  유저

$ rlogin host2

…(접속해서 사용)

$ exit (로그 아웃)

cf. rsh  host1 hostname

cf. rcp  file1  host1:/tmp

3) ssh (secure Shell)

명령어: ssh, scp, sftp

관련사이트:

http://www.openssl.org

http://www.openssh.org

관련 문서:

ssh howto

http://kldp.org/~eunjea/ssh/index.html

ssh install for solaris

http://www.sunfreeware.com/openssh.html

4) ftp

[ 접속 및 연결 끊기 ]

1) 일반 유저로 로긴

$ ftp server_name

또는

$ ftp

ftp> open server_name

ftp> user login_id

ftp> close

ftp> open new_server

ftp> quit

2) Anonymous 로긴

$ ftp server_name

Login: ftp ( or anonymous)

password: user01@suned.co.kr

[ 기본 설정 옵션 ]

ftp> hash     (on/off: 전송상태를 표시)

ftp> ver      (on/off: Verbose mode)

ftp> bin      (Binary mode)

ftp> asc      (ASCII mode)

ftp> prompt   (on/off: 다중 파일 전송시 프롬프트 on/off)

[ 기본 명령 ]

ftp> cd      (디렉토리를 옮길 때: REMOTE )

ftp> ls      (디렉토리 내용을 볼 때: REMOTE )

ftp> pwd     (현재 디렉토리 위치 확인: REMOTE)

ftp> lcd      (디렉토리를 옮길 때: LOCAL )

ftp> !ls      (디렉토리 내용을 볼 때: LOCAL )

ftp> !pwd     (현재 디렉토리 위치 확인: LOCAL)

ftp> !        (Shell로 잠시 빠져나감: LOCAL)

[ 파일 전송 ]

ftp> get remote_file [local_file]   (받을 때)

ftp> mget file1 file2 file3 file4   (여러 파일을 받을 때)

ftp> put local_file [remote_file]  (올릴 때)

ftp> mput file1 file2 file3 file4   (여러 파일을 받을 때)

[ 기타 명령어 ]

ftp> del file_name   (파일 지우기: REMOTE)

ftp> mkdir dir_name  (디렉토리 만들기: REMOTE)

ftp> help            (도움말 보기: REMOTE)

5) X 서버로의 접근

윈도우용 Client프로그램으로는 Xmanager가 유명하다. 다음 문서를 참조한다.

– 사용법

http://compedu.inue.ac.kr/~chlee56/wowlinux/xmanager.htm

– 다운로드

http://netsarang.co.kr/download/download.html

9. 시스템 프로세스

process : 프로그램이 메모리에 올라와  동작하고 있는 상태.

PID : 프로세스의 고유 ID (커널이 관리)

Daemon: 백그라운드로 실행, 부팅 시 동작, 서버 프로세스

1) 프로세스 정보

$ ps -ef | more

     UID   PID  PPID  C    STIME TTY      TIME CMD

    root     0     0  0   4월 25 ?        0:00 sched

    root     1     0  0   4월 25 ?        0:05 /etc/init –

    root     2     0  0   4월 25 ?        0:00 pageout

    root     3     0  0   4월 25 ?        86:09 fsflush

    root   279     1  0   4월 25 ?        0:00 /usr/lib/saf/sac -t 300

    root   204     1  0   4월 25 ?        0:00 /usr/lib/utmpd

    root   134     1  0   4월 25 ?        0:02 /usr/sbin/rpcbind

$ ps  -ef | grep lp

$ pgrep -l lp  (solaris 8부터)

2)프로세스 종료

– 시그널 정의

$ man -s 3HEAD signal

     Name             Value   Default    Event

     SIGHUP           1         Exit         Hangup (see termio(7I))

     SIGINT             2        Exit          Interrupt (see termio(7I))

     SIGKILL            9        Exit         Killed

     SIGTERM         15       Exit        Terminated  (==> Control + C)

– 프로세스 종료

$ kill [-signal] PID …

$ kill

$ kill -9  

$ kill  -KILL

$ pgrep  -l  mail

215  sendmail

12047  dtmail

$ kill 12047

$ pkill  -KILL 프로세스 이름

– 자신이 사용하는 워크스테이션이 윈도우 hang시 처리요령

다른 시스템에서 다음과 같이 한다.

$ telnet (또는 rlogin)  host1

$ pkill  -9  <자신의 쉘이름, ex) ksh>

또는

$ pkill  -KILL  <자신의 쉘이름 ex) ksh>

3) 잡 제어 ( Job Control )

여러 개의 작업을 수행하고 이를 제어할 수 있다. 단 본쉘(sh)는 불가

$ find  .  -name  core  > list  & ( Job을 background로 실행)

$ jobs ( Job을 확인)

[1]  =  running  find  .  -name  core  > list  &

$ fg  %1  ( 백그라운드 잡을 포그라운드로)

Control + Z ( 포그라운드 잡을 중지)

$ jobs  ( job을 확인)

$ bg %1 (중지된 잡을 백그라운드로 실행)

$ kill  %1  (잡을 종료)

10. 쉘 (Shell)

명령해석기, 사용자 인터프리터라고도 한다. 쉘 각각의 자세한 문서는 다음을 참고한다.

http://dir.yahoo.com/Computers_and_Internet/Software/Operating_Systems/UNIX/Shells/

Shell 종류        Shell 프로그램 위치        프롬프트        프롬프트 변수        쉘초기화 파일

Bourn Shell        /bin/sh, /sbin/sh        #, $        PS1        /etc/profile, $HOME/.profile

Korn Shell        /bin/ksh        #, $        PS1        /etc/profile, $HOME/.profile, $HOME/.kshrc

C Shell        /bin/csh        hostname#, hostname%        prompt        /etc/.login, $HOME/.cshrc, $HOME/.login

– 현재 사용쉘 확인

$ ps

$ echo $SHELL

– 기타 쉘

bash, tcsh, zsh, ssh

– 관련 디렉토리

/etc/skell  : 샘플 초기화 파일 위치

1) 입출력의 전환

$ mailx user1  < ~/myfile  ( 입력의 방향을 파일로부터 )
$ ps -ef > file_list  (출력의 방향을 파일로 전환)

$ cat  /etc/passwd  >> file_list  (출력의 방향을 파일로 전환, append)

$ ls  /var  /no  1> dat  2>&1  

2) 파이프 (프로세스 간 통신)

$ who  |  wc  -l

$ ls  -F  /etc  | grep  “/”

$ head  -10  file1  | tail  -3  | lp

$ ps  -ef  |  tail  +2  |  wc  -l

3) Meta Character

– Backslashes (\)

– Dollar signs ($)

– Back quotation marks (   )

– quotation marks (‘  ‘)

– double quotation marks (” “)

$ rm  \*

$ echo ‘$SHELL’

$ echo “$SHELL”

$ echo “\$SHELL”

$ echo date

$ echo date

11. Korn Shell Features

1) Aliases

alias  aliasname=”command”

ex)

$ alias  h=history

$ alias  c=clear

$ alias  home=’cd;ls’

$ alias  ls=’ls -F’

$ alias  copy=”cp -r”

2) Command line Editing

– Command line 편집 기능

$ set  -o  vi

$ [esc] + k  (=> vi command mode )

3) History

– 128개를 유지 ( 변수 HISTSIZE -> .kshrc)

– $HOME/.sh_history (변수 HISTFILE -> .kshrc)

ex)

$ history  ( 최근 16개 명령을 list)

$ history  23 (23 ~ 최근명령)

$ history  -10  (최근 명령 10개)

cf)

$ r ( 가장 최근 명령 실행)

$ r  p  ( p로 시작된 가장 최근 명령어 실행)

$ r  23  ( 히스토리가 23번인 명령어 실행)

4) Ignore Control-d (ignoreeof)

– Control-d의 기능: 1) EOF, 2) EXIT

ex)

$ ^d

$ set  -o  ignoreeof   (=>설정 eof:on, exit:off)

$ ^d

$ set  +o  ignoreeof   (=>해제 eof:on, exit:on)

5) .profile과 분리된 초기화 파일 (.kshrc)

– $HOME/.kshrc (C쉘: $HOME/.cshrc)

– 환경변수는 .profile에 기록

– 기타변수 및 콘쉘 제공 기능 등은 .kshrc에 기록

ex)

$ .  ~/.kshrc ( 재 초기화 )

6) Job Control

ex)

$ find  /  -name  core  -exec  rm  {}  \;

^Z (=> suspend)

[1] + stop …  (=> [1]은 잡번호)

$ bg  %1  ( 1번 잡을 백그라운드로 실행)

$ jobs   ( 잡 확인)

$ fg  %1  ( 1번 잡을 포그라운드로 실행)

$ ^+C ( 포그라운드 잡을 종료)

$ jobs

7) 덮어쓰기 방지 (noclobber)

ex)

$ touch  testfile

$ cat  /etc/passwd > testfile

$ cat  testfile

$ cat  /etc/profile > testfile

$ cat  testfile

$ set  -o  noclobber

$ cat  /etc/hosts > testfile  ( => 경고메시지가 떨어짐)

12. Korn Shell Initialization

– Korn Shell 초기화 순서

(1) /etc/profile

(2) $HOME/.profile

(3) $HOME/.kshrc

1) $HOME/.profile 설정하기

$ vi  ~/.profile

   stty  cs8  erase ‘^H’  -istrip   ( -> 터미널 설정 )

   PATH=$PATH:/usr/local/bin:/usr/ccs/bin:/usr/ucb  (-> Path 설정)

   EXINIT=”set ai nu ts=3 showmode”  (-> vi 환경설정)

   ENV=”$HOME/.kshrc”  ( -> .kshrc 확장쉘 변수 설정)

   LPDEST=”lp1″  (-> Default Printer Set )

   EDITOR=”vi”  ( -> Default Editor Set )

   export  PATH EXINIT ENV LPDEST EDITOR  ( 전역변수 선언 )

$ .   ~/.profile  ( .profile 재 초기화)

2) $HOME/.kshrc 설정하기

$ vi   ~/.kshrc

   HOSTNAME=uname -n

   PS1='[$LOGNAME@$HOSTNAME:$PWD]$ ‘  (-> 프롬프트 변경)

   export PS1 HOSTNAME  (-> 전역변수 선언)

   ## My Alias Def  (-> 엘리어스 설정 )

   alias  ls=’ls -F’

   alias  rm=’rm -i’

   alias  mv=’mv -i’

   alias  cp=’cp -i’

   alias  home=’cd;ls’

   alias  c=clear

   alias  h=history

   alias  d=date

   ## Other ksh feature set

   set  -o  noclobber

   set  -o  vi

   set  -o  ignoreeof

$ .   ~/.kshrc   (-> .kshrc 재 초기화)

13. 쉘 프로그래밍

– 쉘 프로그래밍 강좌

http://kldp.org/KoreanDoc/Shell_Programming-KLDP

http://myhome.naver.com/yskim511/21.htm

4부. 시스템 어드민

1. UNIX 파일의 종류와 특성

– 파일은 파일이름, inode, data block으로 구성되어 있다.

– 파일의 종류는 ls -l , ls -F, file 등의 명령어로 확인할 수 있다.

1) 파일의 종류

-: Regular File (Ordinary File) : vi, ed, cp, mv, cat, touch, cc 등에 의해 생성

d: Directory File : mkdir, cp -r 등에 의해 생성

c,b: Special File ( 디바이스 파일) : 장치 파일이며 drvconfig, devfsadm등에 의해 생성

  brw-r—–   1 root     sys       32,  0 2000년  7월  4일  /devices/sbus@1f,0/SUNW,fas@e,8800000/sd@0,0:a

  crw-r—–   1 root     sys       32,  0 2000년  7월  4일  /devices/sbus@1f,0/SUNW,fas@e,8800000/sd@0,0:a

l: Symbolic Link File: 심볼릭 링크 파일

  lrwxrwxrwx   1 root     root          12 2000년  7월  4일 /etc/hosts -> ./inet/hosts

$ ln -s  file1  file2  (심볼릭 링크)

$ ln  file2  file3 (하드 링크)

$ rm  file1 (원본을 제거함)

$ cat  file2  file3  ( file2는 볼 수 없음)

– 링크란 어떤 파일의 또 다른 이름이다.

– 하드링크는 같은 inode를 심볼릭 링크는 다른 inode를 갖는다.

– 하드링크는 디렉토리를 링크할 수 없다.

– 하드링크는 서로 다른 파일시스템 간에 링크할 수 없다.

– 하드링크는 원본파일의 데이터와 같은 데이터를 공유하며, 심볼릭 링크는 원본의 PATH값을 데이터로 갖는다.

– 심볼릭 링크의 예

/etc/hosts -> /etc/inet/hosts

/bin -> /usr/sbin

– 하드링크의 예

/etc/init.d/*  -> /etc/rc#.d/*

2) inode

모든 파일은 하나의 inode를 가지며 이것은 해당 파일에 대한 정보를 가진다. inode table은 inode들로 구성되어 있으며

하나의 inode는 ls-l정보, 데이터블록 포인터, shadow inode 포인터로 이루어져 있다. 포인터들이 가리킬 수 있는 데이터 블록의

사이즈는 최대 1T까지 가능하다.

– 파일과 파일시스템의 최대 사이즈

solaris 2.6 이전 : 2G (파일), 1TB (파일 시스템)

solaris 2.6부터 : 2G이상 1TB (파일), 1TB (파일 시스템)

파일의 경우 실재로는 866G까지 가능하며, 파일 시스템의 1T이상은 Virtual Volume(Meta Device, Veritas Volume Manager)을 구성해야 한다.

2. Boot PROM (Programmable Read Only Memory)

– PROM 관련 문서

Frequently Asked Questions about Sun NVRAM/hostid

http://www.squirrel.com/squirrel/sun-nvram-hostid.faq.html

Sun Flash PROM Guide for Workstations and Workgroup Servers – Standalone Version

http://www.sun.com/products-n-solutions/hardware/docs/pdf/802-3233-23.pdf

Updating the Flash PROM on the Ultra 1, Ultra 2, Ultra 450, and Sun Enterprise 450 Systems

http://docs.sun.com/db/doc/816-2583-10/6m8u2cukc?a=view

Updating the Flash PROM on the Sun Enterprise 3×00, 4×00, 5×00, and 6×00 Systems

http://docs.sun.com/db/doc/816-2583-10/6m8u2cukk?a=view

1) PROM이 하는 역할

– Test the system hardware (POST: Power on Self Test)

– Boot the operating system

[ POST ]

– Initialize the system

– Probes Memory and the CPU

– Probes devices, interprets their devices and build a dev tree

– Install the console

2) PROM으로 가는 방법

– # halt

– # init 0

– # /usr/sbin/shutdown  -y  -g0  -i0

– Stop + A ( 부팅 시 바로 누르거나 시스템 hang시에만 적용)

3) PROM에서의 얻을 수 있는 정보

OK  banner       ( 시스템 모델명, 메모리, hostid, Ethernet Addr, Boot PROM 버전 )

OK probe-scsi  ( 연결된 SCSI 장치들의 정보 확인)

4) PROM 버전

1.x : Original Sparc Boot PROM

2.x : Open Boot PROM (OBP) => sparc 시리즈 (sparc4,5,10,20…등)

3.x : Open Boot PROM with Flash Update (Flash PROM) => ultra sparc 시리즈

5) PROM에서 사용되는 명령어

OK help (도움말)

OK probe-scsi  (스카시 장비 체크)

OK prebe-ide ( IDE장비 체크)

OK devalias  (PROM에 설정되어 있는 장비의 물리적 장치명과 별명)

OK show-devs ( PROM에 설정되어 있는 물리적 장치의 트리구조 보기)

OK printenv  (PROM에 설정되어 있는 부트 파라미터의 기본 값을 확인)

OK setenv

OK reset  ( setenv에 의해 변경된 파라미터 값들을 재 저장하는 명령)

OK set-default   ( 지정한 파라미터 값을 초기화)

OK set-defaults ( 지정한 모든 파라미터 값들을 초기화 => STOP + N)

6) PROM의 부트 명령어

OK boot [ device name ]  -[option]

OK boot  [disk, net, cdrom]  (=> default는 disk)

OK boot -s  (싱글유저로 부팅)

OK boot -a  (Interactive 모드로 부팅)

OK boot  -r  (Reconfiguration Boot => 장치를 추가했을 때)

7) OS의 PROM관련 시스템 명령어

# eeprom (확인)

# eeprom boot-device ( 확인)

# eeprom auto-boot?=false (설정)

# eeprom ‘auto-boot?=false’ (csh의 경우)

3. 부트 프로세스 (Boot Process)

1) 부팅의 단계는 다음과 같다.

(1) 부트 PROM 단계

– PROM이 POST(Power On Self Test)를 실행

– 부트 디바이스를 결정

– 부트 프로그램인 bootblk를 로드

(2) 부트 프로그램 단계

– bootblk는 두 번째 부트 프로그램인 ufsboot를 로드

– ufsboot는 커널을 로드( 32bit, 64bit kernel)

(3) 커널 초기화 단계

– 커널(/kernel/unix, /usr/kernel, /platform/uname -m/kernel)은 자신을 초기화하고 모듈을 로드 한다.

– Configuration 파일인 /etc/system을 읽는다.

(4) init 단계

– 커널이 /sbin/init을 실행한다.

– init은  /etc/initab을 읽는다.

– 필요한 데몬을 실행한다.

2) 32 또는 64 bit 커널의 확인 및 변경

64bit의 경우 OS는 Solaris7부터, 시스템 아키텍처는 sun4u(ultra sparc) 이상에서이다.

– 확인하기

# isainfo  -kv

32-bit sparc kernel modules (=> 32일 경우)

64-bit sparc kernel modules (=> 64일 경우)

– 64bit -> 32bit

OK  boot  kernel/unix

– 32bit -> 64bit

OK boot  kernel/sparcv9/unix

cf. 64bit 커널 지정하기

# vi /platform/sun4u/boot.conf

ALLOW_64BIT_KERNEL_ULTRASPARC_1_CPU=true

3) 커널 파라미터 수정

보다 자세한 사항은 다음을 참조한다.

– Solaris Tunable Parameters Reference Manual

http://docs.sun.com/db/doc/816-0607

i) 최대 사용자수 지정( maxusers)

   set maxusers=100

ii) 최대 프로세스 개수 지정  (max_nprocs)

   set max_nprocs=100

iii) 가상 단말기 개수 지정 ( pt_cnt)

– 리부팅시에는 반드시  reconfiguration boot

   set pt_cnt=128

   set npty=128

iiii) 최대 파일 디스크립트 개수 지정하기 (rlim_fd_cur)

– 하나의 프로세스가 동시에 오픈할 수 있는 최대 파일 개수

– # ulimit descriptors 512

– # ulimit -n 512

   set rlim_fd_max=1500

   set rlim_fd_cur=128

iiiii) 최대 UFS inode수 지정( ufs_ninode)

– 시스템에서 파일을 오픈 하면 하나의 파일에 대하여

하나의 ufs_ninode를 가지게 된다.

   set ufs_ninode=10000

[ How to Setup Kernel Parameter ]

i) backup /etc/system file

# cp /etc/system /etc/system.org

ii) Edit /etc/system file

# vi /etc/system

        … (다음을 추가)

        set pt_max_pty=10

iii) Reconfiguration Boot

# reboot — -r

iiii) 윈도우에서 터미널을 여러 개 띄워 max값을 확인

[ How to recover /etc/system File ]

i) Edit /etc/system file

# vi /etc/system

        … (다음을 추가)

        exclude: drv/dad

ii) reboot

# reboot

iii) Boots the system interactively

OK boot -a

Enter filename of kernel (kernel/unix):  

Enter default directory for modules (kernel, /usr/kernel):  

Enter name of system file (etc/system): /etc/system.org

Enter default root file system type (ufs):  

Enter physical name of root device:  

iiii) Recover /etc/system file

# cp  /etc/system.org  /etc/system

# init 6

4. init 단계

kernel은 init을 실행하고 init은 /etc/inittab파일을 일고 초기화 하며 해당 설정대로 관련 명령을

수행한다. 시스템 운영에 필요한 데몬 들을 실행하고 동작레벨(Run Level)을 관리하는 것이 주 역할이다.

1) /etc/inittab 파일

ap::sysinit:/sbin/autopush -f /etc/iu.ap (*)

ap::sysinit:/sbin/soconfig -f /etc/sock2path (*)

fs::sysinit:/sbin/rcS sysinit           >/dev/msglog 2<>/dev/msglog is:3:initdefault: (*)

p3:s1234:powerfail:/usr/sbin/shutdown -y -i5 -g0 >/dev/msglog 2<>/dev/msglog (*)

sS:s:wait:/sbin/rcS                     >/dev/msglog 2<>/dev/msglog s0:0:wait:/sbin/rc0                     >/dev/msglog 2<>/dev/msglog s1:1:respawn:/sbin/rc1                  >/dev/msglog 2<>/dev/msglog s2:23:wait:/sbin/rc2                    >/dev/msglog 2<>/dev/msglog s3:3:wait:/sbin/rc3                     >/dev/msglog 2<>/dev/msglog s5:5:wait:/sbin/rc5                     >/dev/msglog 2<>/dev/msglog s6:6:wait:/sbin/rc6                     >/dev/msglog 2<>/dev/msglog fw:0:wait:/sbin/uadmin 2 0              >/dev/msglog 2<>/dev/msglog of:5:wait:/sbin/uadmin 2 6              >/dev/msglog 2<>/dev/msglog rb:6:wait:/sbin/uadmin 2 1              >/dev/msglog 2<>/dev/msglog sc:234:respawn:/usr/lib/saf/sac -t 300 (*)

co:234:respawn:/usr/lib/saf/ttymon -g -h -p “uname -n console login: ” -T sun -d /dev/console -l console -m ldterm,ttcompat  (*)

2) Run Level

0      : PROM monitor level. 부트 PROM의 OK 프롬프트 상태로 시스템을 종료하기 위한 Level이다. (==> halt, init 0, shutdown -i0)

s,S   : Single User(관리자) 상태로서 마운트된 모든 파일 시스템을 접근할 수 있다.

1      : Single User(관리자) 상태로서 사용 가능한 모든 파일 시스템을 접근할 수 있다.

2      : 다중 사용자 레벨 (Multi User Level)

3      : 다중 사용자 레벨 (Multi User Level) with NFS(Network File Service)

4      : User Define Level (사용되지 않음)

5      : Shutdown(0) and power off  (==> poweroff , init 5,  shutdown -i5 )

6      : Shutdown(0) and reboot (==> reboot, init 6, shutdown -i6)

3) 각 Run Level별 데몬 프로세스의 실행

init   –>  /sbin/rc# –> /etc/rc#.d/{S##스크립트, K##스크립트} –> 데몬 실행

root(관리자)  –> /etc/init.d/스크립트 –> 데몬 종료, 재실행

/etc/init.d/스크립트 ==> /etc/rc#.d/{S##스크립트, K##스크립트}는 하드링크 됨. 관련 파일 검색은 다음과 같다.

# ls -i /etc/init.d/nfs.server

28562 /etc/init.d/nfs.server*

# find /etc -inum 28562

/etc/init.d/nfs.server

/etc/rc0.d/K28nfs.server

/etc/rc1.d/K28nfs.server

/etc/rc2.d/K28nfs.server

/etc/rc3.d/s15nfs.server

/etc/rcS.d/K28nfs.server

4) RC 스크립트 추가하기

(1) Edit banner script in /etc/init.d

# cd /etc/init.d

# cp lp banner

# vi banner

        #!/bin/sh

        #

        # Boot Process test script

        #

        case “$1” in

        ‘start’)

                [ -f /usr/bin/banner ] && /usr/bin/banner “SYSTEM UP”

                /usr/bin/audioplay /usr/demo/SOUND/sounds/rooster.au

                ;;

        ‘stop’)

                [ -f /usr/bin/banner ] && /usr/bin/banner “SYSTEM DOWN”

                /usr/bin/audioplay /usr/demo/SOUND/sounds/flush.au

                ;;

        ‘*’)

                echo “Usage: $0 { start | stop }”

                exit 1

        esac

        exit 0

(2) Test script

# chmod 744 banner

# chown root:sys /etc/init.d/banner

# ./banner start

# ./banner stop

(3) link to /etc/rc2.d

# cd /etc/rc2.d

# ln /etc/init.d/banner S22banner

(4) link to /etc/rcS.d

# cd /etc/rcS.d

# ln /etc/init.d/banner K99banner

(5)  link to /etc/rc0.d

# cd /etc/rc0.d

# ln /etc/init.d/banner K99banner

(6) Test init state

# init s

# init 6

# halt

5. Device Configuration

1) 장치 명

– Logical Device Name  ( 관리자)

– Physical Device Name ( kernel, system )

– Instance Name (kernel이 부팅 시 빠른 참조를 위해)

2) Logical Device Name

/dev/[r]dsk/c#t#t#d#s#

c# : Controller Number

t# :  Target Number

d# : Disk Number

s# : Slice or partition number (0-7)

예) /dev/dsk/c0t0d0s0(raw device)    /dev/rdsk/c0t3d0s (block device)

3) Physical Device Name

# ls  -lL  /dev/dsk/c0t0d0s0

  brw-r—–   1 root     sys       32,  0 2000년  7월  4일  /devices/sbus@1f,0/SUNW,fas@e,8800000/sd@0,0:a

# ls  -lL  /dev/rdsk/c0t0d0s0

  crw-r—–   1 root     sys       32,  0 2000년  7월  4일  /devices/sbus@1f,0/SUNW,fas@e,8800000/sd@0,0:a

4) Instance Name

시스템 커널에 의해 부여된 Physical Device Name의 축약된 이름이다.

# cat /etc/path_to_inst

“/sbus@1f,0” 0 “sbus”

“/sbus@1f,0/SUNW,fas@e,8800000” 0 “fas”

“/sbus@1f,0/SUNW,fas@e,8800000/sd@f,0” 14 “sd”

“/sbus@1f,0/SUNW,fas@e,8800000/st@6,0” 6 “st”

“/sbus@1f,0/SUNW,fas@e,8800000/sd@d,0” 12 “sd”

“/sbus@1f,0/SUNW,fas@e,8800000/st@4,0” 4 “st”

“/sbus@1f,0/SUNW,fas@e,8800000/sd@e,0” 13 “sd”

“/sbus@1f,0/SUNW,fas@e,8800000/st@5,0” 5 “st”

“/sbus@1f,0/SUNW,fas@e,8800000/sd@b,0” 10 “sd”

“/sbus@1f,0/SUNW,fas@e,8800000/st@2,0” 2 “st”

“/sbus@1f,0/SUNW,fas@e,8800000/sd@c,0” 11 “sd”

“/sbus@1f,0/SUNW,fas@e,8800000/st@3,0” 3 “st”

“/sbus@1f,0/SUNW,fas@e,8800000/st@0,0” 0 “st”

“/sbus@1f,0/SUNW,fas@e,8800000/sd@a,0” 9 “sd”

“/sbus@1f,0/SUNW,fas@e,8800000/st@1,0” 1 “st”

“/sbus@1f,0/SUNW,fas@e,8800000/sd@6,0” 6 “sd”

“/sbus@1f,0/SUNW,fas@e,8800000/sd@4,0” 4 “sd”

“/sbus@1f,0/SUNW,fas@e,8800000/sd@5,0” 5 “sd”

“/sbus@1f,0/SUNW,fas@e,8800000/sd@2,0” 2 “sd”

“/sbus@1f,0/SUNW,fas@e,8800000/sd@3,0” 3 “sd”

“/sbus@1f,0/SUNW,fas@e,8800000/sd@0,0” 0 “sd”

“/sbus@1f,0/SUNW,fas@e,8800000/sd@1,0” 1 “sd”

“/sbus@1f,0/SUNW,fas@e,8800000/sd@8,0” 7 “sd”

“/sbus@1f,0/SUNW,fas@e,8800000/sd@9,0” 8 “sd”

“/sbus@1f,0/sbusmem@2,0” 2 “sbusmem”

“/sbus@1f,0/sbusmem@3,0” 3 “sbusmem”

“/sbus@1f,0/sbusmem@0,0” 0 “sbusmem”

5) 디바이스의 재구성

장치를 새로 장착하고 /devices 및 /dev의 장치파일을 재구성하기 위한 명령어는 다음과 같다.

– (재)부팅이 필요

i) # reboot  —  -r

ii) OK  boot  -r

iii) # touch  /reconfigure

    # reboot ( or init 6)

– (재)부팅이 불필요

i) # drvconfig  -i  sd ( Solaris 2.6부터 )

   # disks  (tapes, ports, devlinks)

ii) # devfsadm -c disk [ -c tape -c audio ]

6) 장치 추가 용례

– reconfigure file 생성

# touch  /reconfigure

– 시스템의 정지

# init  5

– 시스템의 전원을 끈다

– 시스템에 새로운 디바이스를 연결한다.

– 외장형일 경우 외장 디바이스의 전원을 켠다.

– 시스템의 전원을 켠다.

– 부팅 후 추가된 장치의 Reconfiguration을 확인한다.

7) 장치의 연결확인

– PROM 단계에서

OK probe-scsi

– OS에서

# prtconf | grep -v not

# format     (디스크의 경우, 확인만 하고 Control + d )

Searching for disks…done

AVAILABLE DISK SELECTIONS:

       0. c0t0d0