캠핑과 개발

□ / (root)
- 마운트 되는 리눅스 파일 시스템이 있는 최상위 디렉토리
- 시스템의 근간을 이루는 가장 중요한 디렉토리
- 파티션 설정 시 반드시 존재하여야 함
- 절대경로의 기준이 되는 디렉토리
   ※ 절대경로 - / 디렉토리 기준   예) /usr/local
      상대경로 - 현재 작업 디렉토리 기준 예) ./local

□ /bin
- 리눅스의 기본 명령어(binary)들이 들어있는 디렉토리
- 시스템을 운영하는데 기본적인 명령어들이 들어 있음.

□ /sbin
- 시스템 관리에 관련된 실행 명령어들이 들어있는 디렉토리
- 시스템 점검 및 복구 명령, 시스템 초기 및 종료 명령 등 시스템 관리에
  관련된 실행파일들 존재.

□ /lib
- 프로그램들이 의존하고 있는 라이브러리 파일들 존재.
- /lib/modules : 커널 모듈 파일들 존재.
- 대부분의 라이브러리들은 링크로 연결되어 있음.

□ /proc
- 시스템에 대한 정보를 제공하는 가상 파일 시스템.
- 커널의 어떤 기능을 제어할 수 있는 역할을 가지고 있음.
- 대부분 읽기 전용이나, 일부 파일중에는 쓰기가 가능한 파일이 존재
  하는데 이러한 파일들에 특정 값을 지정하면 커널 기능이 변하게 됨.
- 이 디렉토리 내에 있는 파일을 cat 명령을 이용하여 보면 시스템 정보를
  확인 할 수 있음.
  예) 인터럽트 정보 확인 ---> cat /proc/interrupts

□ /etc
- 시스템 환경 설정 파일이 있는 디렉토리
- 네트워크 관련 설정파일, 사용자 정보 및 암호정보, 파일 시스템 정보,
  보안파일, 시스템 초기화 파일등 중요 설정 파일들의 위치한 디렉토리
- /etc/CORBA : Common Object Request Broker Architecture (COBRA)에
               관한 파일이 들어있음.
- /etc/X11 : 엑스 윈도우 설정에 관련된 파일들이 있음.
- /etc/cron.d : crontab 명령의 설정파일이 있음.
- /etc/cron.daily : 매일 작동하게 하는 crontab 스크립트 파일이 존재.
- /etc/gnome : GTK+ 정의파일들이 있음.
- /etc/httpd : 아파치 웹 서버의 설정 및 로그파일이 있음.
- /etc/logrotate.d : logrotate 설정 파일들이 있음.
- /etc/mail : 센드메일과 관련된 파일이 있음.
- /etc/ppp : ppp 설정에 관련된 파일들이 있음.
- /etc/profile.d : 쉘 로그인 하여 프로파일의 실행되는 스크립트에
                   대한 정의가 있음.
- /etc/rc.d : 시스템 초기화와 관련된 스크립트가 존재.
- /etc/samba : 삼바에 관련된 파일들이 있음.
- /etc/security : 터미널 보안에 관련된 설정이 있음.
- /etc/skel : 새로운 사용자를 추가할 때 자동적으로 생성되는 디렉토리와
              파일이 있음.
- /etc/squid : squid 프록시 서버에 관련된 파일이 있음.
- /etc/ssh : secure shell 설정 파일이 있음
- /etc/sysconfig : 시스템과 네트워크 설정을 담고 있음.
- /etc/xinetd.d : 슈퍼데몬 xinetd.d의 서비스 영역을 설정하는 디렉토리.

□ /var
- 가변 자료 저장 디렉토리
- 시스템 운영중에 시스템 자료 데이터가 변경될 때 변경된 자료들이
  저장되는 곳.
- 주로 시스템 작동기록(log)들을 저장.
- /var/log : 시스템에 발생된 일들에 대한 기록 파일이 있음
- /var/named : 네임서버 설정 파일들 존재
- /var/spool/mail : 수신 메일을 사용자 명으로 기록하는 디렉토리

□ /usr
- 일반 사용자들을 위한 대부분의 프로그램 라이브러리 파일들이 위치.
- /usr/bin : 응용 프로그램의 실행 파일이 위치
- /usr/sbin : 주로 네트워크 관련 실행 명령어와 실행 데몬들을 많이
  포함하고 있음.
- /usr/X11R6 : X-window 시스템에 관련된 파일 존재.
- /usr/include : 기본 C 라이브러리 헤더 파일과 각종 라이브러리
  헤더파일들이 있음.
- /usr/lib : /usr/bin과 /usr/sbin에 있는 실행 바이너리를 실행하기 위한
  라이브러리 존재.
- /usr/src : 프로그램소스 및 커널 소스들이 보관되어 있는 곳.
- /usr/man : 매뉴얼 페이지가 담겨있는곳.
- /usr/local : 새로운 프로그램들이 설치되는 곳
   (windows의 Program Files 와 유사)

□ /mnt
- 다른 장치들을 마운트 할때 일반적으로 사용하는 디렉토리
- 다른 디렉토리를 사용하여도 됨.

□ /home
- 일반 사용자의 홈 디렉토리가 만들어 지는 디렉토리
- 사용자 계정을 만들면 게정과 같은 이름으로 새로운 사용자 디렉토리가
  /home 디렉토리의 하위 디렉토리로 생성됨.
예) test 사용자 추가 후 홈 디렉토리 확인하기.
root@test />$adduser test
root@test />$cd /home
root@test home>$ls

    test   <-- 디렉토리 생성

□ /boot
- 부팅에 핵심적인 커널 이미지와 부팅 정보 파일을 담고 있는 디렉토리
- /etc/lilo.conf에서 지정한 커널 부팅 이미지 파일이 들어 있으며 부팅시
  매우 중요한 디렉토리

□ /root
- 슈퍼유저(root) 사용자의 홈 디렉토리.
- / 와 /root 디렉토리는 부르는 이름은 같지만 서로 다름

'DEVELOPMENT > Linux' 카테고리의 다른 글

linux 명령어 - du  (0) 2012.05.17
linux 명령어 - find  (0) 2012.05.17
리눅스 백그라운드 실행  (0) 2012.05.17
rpm 명령어 사용하기  (0) 2012.05.17
linux 명령어 - yum  (0) 2012.05.17

1. 백그라운드로 실행
$ top &  

2. 확인
$ jobs
[1]+   Running    top &

3. 다시 포그라운드로
$ fg %1

'DEVELOPMENT > Linux' 카테고리의 다른 글

linux 명령어 - find  (0) 2012.05.17
디렉터리 구성  (0) 2012.05.17
rpm 명령어 사용하기  (0) 2012.05.17
linux 명령어 - yum  (0) 2012.05.17
linux 명령어 - crontab  (0) 2012.05.17

1. rpm 설치 확인
rpm -qa | grep rpm명

2. rpm 설치
사용방법
rpm -ivh 설치할 패키지명.rpm

- 의존성 에러가 있을 경우 설치
rpm -ivh --force 설치할 패키지명.rpm

3. rpm 업그레드
사용방법
rpm -Uvh 업그레이드할 패키지명.rpm

4. 제거
rpm -e 제거할 패키지명.rpm

- 의존성 에러가 날 경우 제거
rpm -e --nodeps 제거할 패키지명.rpm

5. SRPM 컴파일
rpm --rebuild 펄 파일 할 패키지명.src.rpm 이때 컴파일 된 패키지는
/usr/src/redhat/BUILD
/usr/src/redhat/RPMS/*

1. 기능
RedHat Package Manager의 약어로 프로그램 등을 설치할 때 사용하는 방법이며, Redhat사에서 제안하였다. rpm은 유닉스계열의 일반적인 설치방법인 소스방법에 비해 쉬운 설치를 지원하지만, 설치되는 디렉토리의 변경이 어렵다. 설치된 디렉토리나 실행명령 등은 설치 후 질의를 통해 확인해야 한다.

2. 문법
rpm options [filename]

3. 옵션
-i :기본적으로 설치할 때 쓴다. 이 옵션을 사용하면 이전 버젼의 같은 패키지에 대한 정보가 존재할 경우 설치하지 않는다.
-U : 이전버젼이 설치되어 있으면 업그레이드를 하며, 설치되어 있지 않으면 새롭게 설치한다.
이전버젼이 설치되어 있을 경우에 환경설정파일을 제외하고 모두 새롭게 설치한다. 설치시에 이옵션을 사용하도록 한다.
-F : 현재 설치하는 패키지의 이전 버젼이 설치되어 있는 경우에만 설치하고, 그렇지 않은 경우에는 설치하지 않는다.
-v : 설치중 메시지를 보여준다.
-h : 진행과정을 '#'으로 표시하라는 뜻이다.(--hash)
-e : 패키지를 제거할 때 쓰인다.
-q : 패키지가 설치되어 있는 질의한다. 이 옵션 단독으로 사용하면 패키지 이름과 버젼만 표시된다.
-qa : 현재 설치된 모든 패키지 목록을 찾는데 사용한다. 보통 grep명령과 같이 사용된다.
-qi : 현재 설치된 패키지의 간략한 정보를 출력
-ql : 현재 설치된 패키지의 내용을 보여준다. 어떤 파일이 어디에 설치되어 있는지 확인할 때 쓴다.
-Vf : 현재 설치된 파일의 검증할때 쓴다. 문제가 없으면 '.'으로 표시된다.
-Va : 한 패키지만 검증한다.
--force : 보통 패키지뒤에 붙는 옵션으로 패키지와의 충돌등을 무시하고 무조건 설치하는 옵션이다.(앞에 옵션을 써도 무방함.)
--nodeps : 의존성 문제를 일으켜 설치가 안될경우에 쓰는 옵션이다.

'DEVELOPMENT > Linux' 카테고리의 다른 글

디렉터리 구성  (0) 2012.05.17
리눅스 백그라운드 실행  (0) 2012.05.17
linux 명령어 - yum  (0) 2012.05.17
linux 명령어 - crontab  (0) 2012.05.17
linux shell 스크립트  (0) 2012.01.13

yum은 centos에서 사용하는 원격업데이트 툴이다.

1. 업데이트 목록보기
  #yum list updates

2. 업데이트 목록을 다운로드하고 업데이트를 설치하려면
#yum update -y

3. 설치된 rpm 패키지를 보려면
#rpm -qa
#yum list installed

4. gcc 패키지가 설치된어 있는지 확인
#rpm -qa | grep gcc
#yum list installed gcc

5. gcc 패키지를 설치하려면
#yum install gcc gcc-c++

6. gcc 패키지를 업데이트하려면
#yum update gcc gcc-c++

7. 패키지 이름으로 검색
#yum list 패키지
#yum list gcc
#yum list gcc*

8. 패키지를 삭제하려면
#yum remove gcc gcc-c++

'DEVELOPMENT > Linux' 카테고리의 다른 글

리눅스 백그라운드 실행  (0) 2012.05.17
rpm 명령어 사용하기  (0) 2012.05.17
linux 명령어 - crontab  (0) 2012.05.17
linux shell 스크립트  (0) 2012.01.13
Fedora 16 | systemctl - 서비스 관리 명령어  (0) 2011.12.01

1. 개요

cron(크론)은 원하는 시간에 명령(프로그램)을 시키기 위한 데몬이다.
서버는 늘 깨어있다는 것을 이용한 최대한의 활용법이 될 수 있다.

- 내가 새벽 3시에 서버에 특정 작업을 해줘야하는데 그 때 깨어있을 수 있는가?
- 또는 30분간격으로 HDD의 사용량을 운영자에게 알리도록 해야한다면?
- 매월 초에 자료를 백업 받고 싶다면?

바로 이럴 때 cron은 최고의 해결책을 제시한다.
cron은 항상 지정한 시간이 되었는지 확인을 하여 해당 명령어을 실행하는 것이다.



2. cron 설정

1) crontab 파일 위치 및 조회

작업 설정 파일을 crontab 파일이라고 부르며, 이 파일의 위치는 OS별로 차이가 있다.
리눅스는 /var/spool/cron/ID, 솔라리스는 /var/spool/corn/crontabs/ID 에 위치한다.
그럼 이 파일을 직접 수정해야 하는가? 그렇지 않다. crontab 명령을 통해 설정과 조회를 한다.


설정 내용을 조회해 보자. (-l 옵션)

crontab -l



2) crontab 파일 형식

------    --------  ---------------------------------------------------
필  드    의  미    범  위
------    --------  ---------------------------------------------------
첫번째    분        0-59
두번째    시        0-23
세번째    일        0-31
네번째    월        1-12
다섯번째  요일      0-7 (0 또는 7=일요일, 1=월, 2=화,...)
여섯번째  명령어    실행할 명령을 한줄로 쓴다.
------    --------  ---------------------------------------------------


- 한 줄당 하나의 명령 (두줄로 나눠서 표시할 수 없음)
- # 으로 시작하는 줄은 실행하지 않는다.

설정을 해보자. (-e 옵션)
crontab -e 을 하면 vi 에디터가 나온다.(환경변수 EDITOR에 따라 다른 에디터를 사용할 수 있다.)

crontab -e

# /home 디렉토리를 /BACKUP/home 으로 백업해둠
#
# 30분, 새벽 4시와 낮 12시, 모든 일, 모든 월, 모든 요일 
30 4,12 * * *  /usr/bin/rsync -avxH --delete /home /BACKUP/home > /dev/null 2>&1
#
# 파일/디렉토리 퍼미션 설정
# 40분, 새벽 1시, 매주 일요일
40 1    * * 0  /root/bin/perm_set.sh   > /dev/null 2>&1


위는 매일 4:30분과 12:30분에 rsync 명령을, 매주 일요일 1:40분에 perm_set.sh를 실행함을 의미한다.

vi 에디터를 통해 설정을 하므로 중요한 몇 가지 에디터 사용법은 익혀야 한다.

----  -----------------------------------------------------------------------------
키    의미
----  -----------------------------------------------------------------------------
i     현재 칸에 글을 넣는다.
o     다음줄에 글을 넣는다.
dd    한줄을 삭제한다.
:wq   저장하고 빠져나온다.
ESC   설정중에 명령어 모드(위의 i, o, dd 등을 사용할 수 있는 상태)로 빠져 나온다.
----  -----------------------------------------------------------------------------



3) 설정 예

시간 설정에서 몇가지 의미있는 것들을 알아보자.

- '*'표시는 해당 필드의 모든 시간을 의미한다.
- 3,5,7 와 같이 콤마(,)로 구분하여 여러 시간대를 지정할 수 있다.
- 2-10와 같이 하이픈(-)으로 시간 범위도 지정할 수 있다.
- 2-10/3와 같이 하이픈(-)으로 시간 범위를 슬래쉬(/)로 시간 간격을 지정할 수 있다.
(2~10까지 3간격으로. 즉, 3,6,9를 의미함)


              

원하는 시간형  식
  매주 토요일 새벽 2:20  20  2     *  *  6  명령어
  매일 오후 4,5,6시  0  4-6   *  *  *  명령어
  매일 2시간간격으로 5분대에  5  */2 *  *  * 명령어
  매월 1일 새벽 1:15  15  1   1  *  *  명령어
  1,7월 1일 새벽 0:30  30  0   1  1,7  *  명령어



3. FAQ

1) cron 설정한 후에는 crond 데몬을 재실행해야 하나요?

  아닙니다. crontab -e 으로 설정 후 빠져나오면 바로 적용됩니다.

2) truefeel 사용자는 cron을 못 쓰게 하고 싶습니다.

  /etc/cron.allow : 허용할 사용자 ID 목록
  /etc/cron.deny  : 거부할 사용자 ID 목록

  cron.allow 파일이 있으면 이 파일에 들어있는 ID만 사용 가능
  cron.deny  파일이 있으면 이 파일에 들어있는 ID는 사용 불가

  따라서 cron.deny에 truefeel ID를 추가해주면 됩니다.

3) > /dev/null  2>&1 이 무슨 뜻입니까?

  지정한 명령어 처리 결과와 발생할지 모르는 에러메시지를 출력하지 않고 모두 버린다는(/dev/null)는
  뜻입니다. 만약 결과와 에러를 파일로 저장하려면 /dev/null 대신 파일명을 적어주면 됩니다.





'DEVELOPMENT > Linux' 카테고리의 다른 글

rpm 명령어 사용하기  (0) 2012.05.17
linux 명령어 - yum  (0) 2012.05.17
linux shell 스크립트  (0) 2012.01.13
Fedora 16 | systemctl - 서비스 관리 명령어  (0) 2011.12.01
linux mysql 바이너리 버전 설치  (0) 2011.11.29


파일구조
#!/bin/bash

#내용

exit 0
문서의 시작은 #!bin/bash로 시작하며 문서의 끝은 exit 0으로 끝낸다.


변수선언
a=0 (O)
a = 0 (X)
b="aaaa bbbb"

변수사용
$a
$b
echo $a
$(($a + 10))


인자값(argument)

$# : 넘어온 인자의 갯수
$* : 각 인자를 나누지 않고 통틀어 참조
$@ : $*와 같지만 quoting(escape)된 문자열로 취급
$0 : 실행된 쉘스크립트 이름
$1, $2, ... 쉘, 함수 호출시 넘어온 매개변수


if문
if [표현식]; then
...
fi


if [표현식]; then
...
elif [표현식]; then
...
else
...
fi

 
test, [] :
    - test는 조건을 판별하여 0(true)/1(false)를 반환한다.
    - test는 쉘 내장명령이며, []은 이것의 또다른 표기법이다.
    - test는 보통 독립적으로 쓰이지않고, if, case, while 등의 뒤에 붙어 조건을 판별한다.

주의!!!) [ ] 은 그 사이사이를 반드시 공백으로 띄어야한다.
[ ]을 제어문자가 아닌 하나의 명령어로 이해할 것!!!

- test는 크게 다음과 같은 3가지를 판별한다.
1)스트링
2)산술식(Interger)
3)파일

- test는 다음과 같은 이진연산자를 인자로 갖는다.
A A는 true
!A A가 아니면 true
A -a B(&&) A이고 B이면 true
A -o B(||) A이거나 B이면 true

-- string 비교시 쓰이는 연산자
A == B A와 B가 같으면 true
A != B A와 B가 다르면 true
-n A A가 not null이면 true
-z A A가 null이면 true

-- integer only 연산자
A -eq B A==B
A -ne B A!=B
A -ge B A>=B
A -gt B A>B
A -le B A<=B
A -lt B A<B
*** =,>,<,!등을 써도되나 주로 스트링비교연산자로 쓰이므로
   산술비교 시는 되도록 전자의 표기법을 따라라.

-- file only 연산자
A -ef B 동일파일
A -nt B A가 최신파일(newer modification data)
A -ot B A가 오래된파일(older ..)
-e A 파일이 있다
-s A 파일크기가 0이 아님(내용있음)
-d A directory임
-f A file임
-h(or L) A Symbolic Link
-r A 현재 사용자가 r권한 갖고 있음.
-w A .. .. ..   w .. .. ..
-x A .. .. ..   x .. .. ..
-O A 내가 소유자임
-G A Group이 같음
-N A (내가) 마지막으로 읽은 후에 변경
--------여기까지만...밑에는 잘 모르겠다-------------
-S A Scoket
-p A PIPE
-b A block device(플로피,씨디롬 등 마운트객체)
-c A character special(키보드,모뎀,사운드카드등 장치)
-g A set-group-id(sgid) flag가 설정된 파일
-u A set-user-id(suid) flag가 설정된 파일
-k A has its stick bit set
-t A file descriptor가 terminal device와 관계됨.

사용법
a=하하하
b=히히히
if [ $a!=$b ]; then # [ ] 사이 공백이 있어야함에 주의!
# then을 이어서 쓸 때 앞명령과 ;로 구분함에 주의!
echo "a is not b"
else
echo "a is b"
fi

c= # 이렇게 하면 변수c는 null값을 가진다.
if [ -z $c ]; then echo "c is null"; fi

a=3
b=10
if [ $a -gt $b ]; then
echo "a is greater then b"
else
echo "a is less then b";
fi

touch 빈파일
if [ -e "빈파일" ];then echo "file is exist!"; fi
if [ -s "빈파일" ];then echo "file size is zero"; fi

case문
case $변수 in
값1 ) 처리1;;
값2 ) 처리2;;
값3 ) 처리3;;
...
* ) default처리;;
esac

ex)
case $( arch ) in
i386 ) echo 80386;; #;; 두번들어감에 유의!!!
i486 ) echo 80486;;
i586 ) echo pentium;;
i686 ) echo pentium3;;
* ) echo "몰라! 이상한 머신이야..."
esac

while문
while [ ... ];do
...
done

ex)
i=0
while [ $i -lt 10 ];do
echo $i
i=$((i+1))
sleep 0.2
done


for문
for i in 1 2 3 4 5; do
    echo $i
    sleep 0.2
done



커맨드라인(사용자) 입력받기
read
한줄로 입력하려면 aaaa<Enter> 여러줄로 입력받으려면 aaa\<Enter> bbbb\<Enter>


쉘스크립트파일안에서 쉘명령 실행
eval

ex) eval "ls -al"


문자열 제어
${...}

ex)

a=aaa하하핳BBBaaaccc

1. 문자열 길이
    echo ${#a} --> 15

2. substring
   echo ${a:3} --> aaa
   echo ${a:3:6} --> 하하하BBB : position,length

3. replace
   echo ${a//aaa/} --> 하하핳BBBccc
   echo ${a/aaa/AAA} --> AAA하하핳BBBaaaccc


파일명 비우기
 : > [파일명]


쉘에서 :은 null을 의미한다. 고로 : > [파일]은 null값을 파일에 redirection하므로 해당 파일의 크기가 0이 된다.


Tip


변수에 substring 사용하기

var=${변수명:start index:end index}


DT=`date -d +"%Y%m%d %H:%M:%S`

STR="Hello World"


month=${DT:0:5} 

str2=${STR:0:4}


echo $month

echo $str2


date 함수

현재의 날짜와 시간을 가져옴

 date  +%Y%m%d   -> 20101216

date +%y%m%d   -> 101216

등등 %Y%m%d를 변경해 가면서 사용할 수 있음

 

##하루전 날짜 구하기

date +%Y%m%d -d  '-1days'

or

date +%Y%m%d --date '1 days ago'

-- 연간 주간은 알아서 찾아 보길

 

##shell에서 사용시

$(date +"%Y%m%d")

 

##날자의 파일명 만들기

filename=exe_$(date +" %Y%m%d")

 

##date 함수 Shell에서 사용할 때

filename=exe_$(date +"%Y%m%d") //오늘 날짜

filename=exe_$(date +"%Y%m%d" -d '-1days') //전날짜




예제파일
sh1.shsh2.shsh3.shshex.sh


'DEVELOPMENT > Linux' 카테고리의 다른 글

linux 명령어 - yum  (0) 2012.05.17
linux 명령어 - crontab  (0) 2012.05.17
Fedora 16 | systemctl - 서비스 관리 명령어  (0) 2011.12.01
linux mysql 바이너리 버전 설치  (0) 2011.11.29
ssh 접속 설정.  (0) 2011.11.29

Fedora 16에서는 서비스(Service) 관리를 systemctl이라는 명령어로 한다. (이전 버전 명령어들도 아직은 사용 가능하지만 systemctl 사용을 권장하고 있다.)


서비스 상태 확인 하기

서비스 상태 확인은 다음과 같이 한다.

systemctl status service_name.service

예를 들어 httpd의 상태를 확인하려면 다음과 같이 명령한다.

systemctl status httpd.service


서비스 시작, 중지, 재시작 하기

서비스를 시작하는 기본 명령 방식은 다음과 같다.

systemctl start service_name.service

중지할 때에는 start 대신 stop을, 재시작할 때에는 restart를 쓰면 된다. 예를 들어 httpd를 시작하려면 다음과 같이 명령한다.

systemctl start httpd.service


중지와 재시작은 다음과 같이 명령하면 된다.

systemctl stop httpd.service
systemctl restart httpd.service
systemctl start httpd.service
systemctl start vsftpd@vsftpd.service


부팅 시 자동 실행 하기

시스템 부팅 시 서비스가 자동 실행되게 하는 명령은 다음과 같다.

systemctl enable service_name.service

예를 들어 httpd를 부팅 시 자동 실행되게 하려면 다음과 같이 명령한다.

systemctl enable httpd.service

자동 실행 되지 않게 하려면 enable 대신 disable을 쓰면 된다.


실행 중인 서비스 보기

실행 중인 모든 서비스 목록을 보려면 다음과 같이 명령한다.

systemctl list-units --type=service


'DEVELOPMENT > Linux' 카테고리의 다른 글

linux 명령어 - crontab  (0) 2012.05.17
linux shell 스크립트  (0) 2012.01.13
linux mysql 바이너리 버전 설치  (0) 2011.11.29
ssh 접속 설정.  (0) 2011.11.29
linux 방화벽 열기  (0) 2011.11.29


http://dev.mysql.com 에서 다운로드 후 설치

mysql 5.1 바이너리 설치

[바이너리 버전 설치 순서]
shell> groupadd mysql
shell> useradd -g mysql mysql
shell> cd /usr/local
shell> gunzip < /path/to/mysql-VERSION-OS.tar.gz | tar xvf -
shell> ln -s full-path-to-mysql-VERSION-OS mysql
shell> cd mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> scripts/mysql_install_db --user=mysql
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe --user=mysql &

이제 기본 데이터베이스 설치를 위해 아래의 코드 실행. script 디렉토리 안에서 mysql_install_db를 실행하니 아래와 같이 FATAL ERROR가 발생했다. 
그러므로 아래 빨간 색으로 표시된 것처럼 mysql의 탑 디렉토리에서 실행해야 성공한다.

[root@localhost bin]# cd ../scripts
[root@localhost scripts]# ls
mysql_install_db
[root@localhost scripts]# ./mysql_install_db 

FATAL ERROR: Could not find ./bin/my_print_defaults

If you compiled from source, you need to run 'make install' to
copy the software into the correct location ready for operation.

If you are using a binary release, you must either be at the top
level of the extracted archive, or pass the --basedir option
pointing to that location.

[root@localhost scripts]# pwd
/usr/local/mysql/scripts
[root@localhost scripts]# cd ..
[root@localhost mysql]# ./scripts/mysql_install_db 
Installing MySQL system tables...
090720 14:01:07 [Warning] Forcing shutdown of 2 plugins
OK
Filling help tables...
090720 14:01:07 [Warning] Forcing shutdown of 2 plugins
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

./bin/mysqladmin -u root password 'new-password'
./bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:
./bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd ./mysql-test ; perl mysql-test-run.pl

Please report any problems with the ./bin/mysqlbug script!

The latest information about MySQL is available at http://www.mysql.com/
Support MySQL by buying support/licenses from http://shop.mysql.com/

이제 기본 DB(mysql, test)의 설치가 끝났다. mysql 디렉토리를 보면 data라는 새 디렉토리가 생성되었을 것이다.

mysql 실행
mysql 게정으로 로긴 후
mysql]$ /usr/local/mysql/bin/mysqld_safe &

mysql 종료
mysqladmin -u root -p shutdown

root로 접속하기 (여기서 root는 시스템의 root계정이 아니라, mysql의 관리계정이다)
처음 설치시 root의 패스워드는 없다.

사용형식) mysql -u MySQL계정명 -p 접속할데이터베이스명
mysql]$ mysql -u root -p mysql

database내 테이블 조회
mysql> show tables;

테이블 스키마 조회
mysql> desc <테이블명>;


자동 시작 등록

#!/bin/sh
vi /etc/rc.d/rc.local

/usr/local/mysql/bin/mysqld_safe &

 

- 데몬이 무사히 실행됐다면 서버 시작시에 자동실행되도록 한다.
  # cp /usr/local/mysql/support-files/mysql.server /etc/rc.d/init.d
  # ln -s ../init.d/mysql.server /etc/rc.d/rc0.d/K01mysql
  # ln -s ../init.d/mysql.server /etc/rc.d/rc3.d/S90mysql

 
/var/run/mysqld/mysqld.pid를 생성하지 못할경우
cd /var/run
mkdir mysqld
chown mysql mysqld
chgrp mysql mysqld 



 

'DEVELOPMENT > Linux' 카테고리의 다른 글

linux shell 스크립트  (0) 2012.01.13
Fedora 16 | systemctl - 서비스 관리 명령어  (0) 2011.12.01
ssh 접속 설정.  (0) 2011.11.29
linux 방화벽 열기  (0) 2011.11.29
sftp root 계정 접속 설정  (0) 2011.07.27


일단 크게

  1. ssh 관련 설정파일을 수정하고
  2. 방화벽설정을 열어준다.

정도로 접속이 가능하게 된다.
fedora12 에서 ssh 설정 관련 패키지 설정파일은 "/etc/ssh" centos는 /etc/ssh/sshd-config에 있습니다.


파일을 열어보면...

[root@localhost /]# cat /etc/ssh/sshd_config
#       $OpenBSD: sshd_config,v 1.80 2008/07/02 02:24:18 djm Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/local/bin:/bin:/usr/bin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options change a
# default value.

Port 8103
AddressFamily inet
ListenAddress 192.168.0.104
#ListenAddress ::

# Disable legacy (protocol version 1) support in the server for new
# installations. In future the default will change to require explicit
# activation of protocol 1
Protocol 2

# HostKey for protocol version 1
#HostKey /etc/ssh/ssh_host_key
# HostKeys for protocol version 2
#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_dsa_key

# Lifetime and size of ephemeral version 1 server key
#KeyRegenerationInterval 1h
#ServerKeyBits 1024

# Logging
# obsoletes QuietMode and FascistLogging
#SyslogFacility AUTH
SyslogFacility AUTHPRIV
LogLevel INFO

# Authentication:

#LoginGraceTime 2m
PermitRootLogin no
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#RSAAuthentication yes
#PubkeyAuthentication yes
#AuthorizedKeysFile     .ssh/authorized_keys

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#RhostsRSAAuthentication no
# similar for protocol version 2
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# RhostsRSAAuthentication and HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
PasswordAuthentication yes

# Change to no to disable s/key passwords
#ChallengeResponseAuthentication yes
ChallengeResponseAuthentication no

# Kerberos options
#KerberosAuthentication no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes
#KerberosGetAFSToken no

# GSSAPI options
#GSSAPIAuthentication no
GSSAPIAuthentication yes
#GSSAPICleanupCredentials yes
GSSAPICleanupCredentials yes

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
#UsePAM no
UsePAM yes

# Accept locale-related environment variables
AcceptEnv LANG LC_CTYPE LC_NUMERIC LC_TIME LC_COLLATE LC_MONETARY LC_MESSAGES
AcceptEnv LC_PAPER LC_NAME LC_ADDRESS LC_TELEPHONE LC_MEASUREMENT
AcceptEnv LC_IDENTIFICATION LC_ALL LANGUAGE
AcceptEnv XMODIFIERS

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#X11Forwarding no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation yes
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#ShowPatchLevel no
#UseDNS yes
#PidFile /var/run/sshd.pid
#MaxStartups 10
#PermitTunnel no
#ChrootDirectory none

# no default banner path
#Banner none

# override default of no subsystems
Subsystem       sftp    /usr/libexec/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       ForceCommand cvs server
[root@localhost /]#


파일에서 vi 에디터로  주황색으로 표시된부분만 수정해준다. (위 내용은 현재 사용하고있는 테스트 서버의 내용)

Port 8103 는 Listen 포트를 변경하는 부분... 기본값은 22

포트를 변경하였을때에는 /etc/services 파일과 방화벽에서 해당포트를 열어주어야한다. (여기서는 8103)

AddressFamily inet 는 ipv4, ipv6 에 대한 옵션이라고함. inet 으로 설정하면 ipv4 에 대해서만 bind 한다고함.

ListenAddress 192.168.0.104는 Listen 할 아이피를 설정해주는 부분.
SyslogFacility AUTHPRIV   로그에대한 옵션임 로그파일이 저장되는 곳을 지정. AUTHPRIV 가 기본값. 기본값일때에는
/var/log/secure 에 로그를 기록하게됨.

LogLevel INFO 로그레벨은 Info 로 지정함으로써 왠만한 기록은 다 기록된다고 함.

PermitRootLogin no 는 ssh 접속시 루트 계정으로 접속을 허용하느냐 마느냐 임...


특정 계정만 ssh 접속을 허용하는 경우

#LoginGraceTime 2m
PermitRootLogin no
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
AllowUsers admin guest test1 test2




이제 ssh 데몬을 재시작한다.

[root@localhost /]# /etc/init.d/sshd restart
sshd 를 정지 중:                                           [  OK  ]
sshd (을)를 시작합니다:                                    [  OK  ]
[root@localhost /]#


방화벽이 꺼져있는 상태이고, 포트가 기본인 22로 설정 되어있을경우에는 여기까지하면 완료가된다.

참고로...

ssh 버전확인은...
[root@localhost /]# rpm -qa | grep ssh
openssh-clients-5.2p1-31.fc12.i686
openssh-server-5.2p1-31.fc12.i686
trilead-ssh2-213-6.fc12.i686
openssh-5.2p1-31.fc12.i686
libssh2-1.2-2.fc12.i686
openssh-askpass-5.2p1-31.fc12.i686
[root@localhost /]#


ssh 상태보기는...
[root@localhost /]# /etc/init.d/sshd status
openssh-daemon (pid  7931)를 실행하고 있습니다..
[root@localhost /]#




자... 이제 /etc/services 파일과 방화벽에서 해당포트를 열어주는 작업을 해주자.

ssh             8103/tcp                          # The Secure Shell (SSH) Protocol

ssh 에 관한 부분에서 포트번호를 바꾸어준다.


그리고 방화벽 파일을 변경하여 포트를 열어주자

[root@localhost /]# cat /etc/sysconfig/iptables
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8103 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
[root@localhost /]#


이렇게 해주면...

ssh 프로그램으로 원격접속이 가능하게 된다.

참고로...

방화벽 상태 알아보기
/sbin/service iptables status

방화벽 올리고 내리기
/sbin/service iptables stop
/sbin/service iptables start


[출처] http://pippen80.cafe24.com/255



'DEVELOPMENT > Linux' 카테고리의 다른 글

Fedora 16 | systemctl - 서비스 관리 명령어  (0) 2011.12.01
linux mysql 바이너리 버전 설치  (0) 2011.11.29
linux 방화벽 열기  (0) 2011.11.29
sftp root 계정 접속 설정  (0) 2011.07.27
linux 명령어 - nohup  (0) 2011.07.21

ex ) 8080 포트 열기
[root@blogserver bin]# vi /etc/sysconfig/iptables

# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT

-A INPUT -m state --state NEW -m tcp -p tcp --dport 8103 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 21 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT

-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT



[root@blogserver bin]#
[root@blogserver bin]# /etc/init.d/iptables restart
iptables: 방화벽 규칙을 지웁니다: [  OK  ]
iptables: chain을 ACCEPT 규칙으로 설정 중:  filter [  OK  ]
iptables: 모듈을 언로드하는 중: [  OK  ]
iptables: 방화벽 규칙 적용 중:  [  OK  ]
[root@blogserver bin]#
[root@blogserver bin]# /etc/init.d/iptables status
테이블: filter
Chain INPUT (policy ACCEPT)
num  target     prot opt source               destination        
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
2    ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0          
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0          
4    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8103
5    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:3306
6    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:21
7    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           state NEW tcp dpt:8080 
8    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)
num  target     prot opt source               destination        
1    REJECT     all  --  0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination        

[root@blogserver bin]#



방화벽 상태 알아보기
/sbin/service iptables status

방화벽 올리고 내리기
/sbin/service iptables stop
/sbin/service iptables start


특정 아이피 막기
iptables -A INPUT -s xx.xx.xx.xx -j DROP

특정 아이피 해제
iptables -D INPUT -s xx.xx.xx.xx -j DROP

특정 IP  웹  접속 차단
iptables -A INPUT -s xx.xx.xx.xx -p tcp --dport 80 -j DROP


해당 C class 웹 접속 차단
iptables -A INPUT -s 210.221.204.0/24 -p tcp --dport 80 -j DROP



[출처] http://pippen80.cafe24.com/271


'DEVELOPMENT > Linux' 카테고리의 다른 글

linux mysql 바이너리 버전 설치  (0) 2011.11.29
ssh 접속 설정.  (0) 2011.11.29
sftp root 계정 접속 설정  (0) 2011.07.27
linux 명령어 - nohup  (0) 2011.07.21
Linux IP 변경  (0) 2011.07.21