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

2009년 2월 1일 일요일

Some Tutorials from HowtoForge


 

[VMWare] How to get the NIC working on a Linux guest(Debian Etch)

Start the VM.
log in as root (su)
To find out the IP Address of the VM.
# ifconfig eth0
eth0: error fetching interface information: Device not found



[Solution]


Source : Official Open-Xchange Forum > - > -> VMWare Image with debian/Etch
By neo          03-16-2007, 11:02 AM

more..



determine the ethernet interface

ifconfig -a | grep eth

edit the network setup /etc/network/interfaces and /etc/init.d/info and replace eth0 with the NIC you find in the command above.

now reboot
:-)

:D

Instead of eth0, eth1 was found by the command above.
(Network Conneciton Type : "Bridged")

I've edited just /etc/network/interfaces and replace eth0 with eth1.

And then reboot.

Done.

[Link] Knowledge Dump

Source : Linhost.info





2008년 9월 12일 금요일

[Tip] Linux/Unix에서 압축파일 다루기


물론 zip이나 rar 또는 7zip과 같은 압축파일형식은 Platform에 구애받지 않고 사용될 수 있고 실재로 많이 사용되고 있기는 하지만, Linux/Unix에서 가장 자주 만나게 되는 압축파일은 filename.tar.gz 와 filename.tar.bz2와 같은 형식이다.
(최근의 Data Compression Software들은 다양한 format을 지원하고 있기 때문에 tar.gz나 tar.bz2 등도 적절한 Windows Utility를 사용하면 MS Windows에서 사용하는 데 큰 어려움은 없다.)
Kernel Source라든지 Application들의 Source Package들도 주로 이 두가지 형식으로 배포된다.
이러한 압축파일들은 tar 명령과 gzip, bzip2와 같은 Utility들을 이용하여 만들어질 수 있다.

===| TAR |=======================
TAR는 UNIX의 standard archive utility로서 원래 Tape ARchiving program에서 유래하였다.
지정된 여러 개의 file들을 archive라고 부르는 하나의 file로 만들거나, 하나의 archive에 모아져 있는 여러 개의 file을 원래의 형태대로 추출해내는 UNIX SHELL command이다.
tar archive에는 ".tar"라는 확장자가 붙는다. tar archive 내에 들어있는 file들은 압축되는 것이 아니라, 단지 하나로 모아지는 것뿐이다. 흔히 tar로 묶어진 archive를 "tarball"이라 부르기도 한다. 이러한 tar archive를 gzip이나 bzip2로 다시 압축한 것이 archive-name.tar.gz와 archive-name.tar.bz2이다.

$ tar cvf backup.tar /home/jvm
이 명령은 /home/jvm 안의 모든 file을 backup.tar의 이름으로 묶는다. 첫 번째 argument인 "cvf" 는 tar의 option으로서, "c"는 새로운 file을 생성(create)하며, "v"는 명령이 수행되는 세부 process를 화면에 출력될 것을 지정한다(verbose). "f"는 생성될 file의 이름을 다음에 나오는 argument인 backup.tar로 지정한다(file). 마지막 argument는 압축이 될 file이나 directory이다.

# tar xvf backup.tar
current directory의 backup.tar를 푼다(extract). tar로 묶인 것을 풀 때 기존의 file들을 덮어쓰게 되므로 주의를 요한다. backup.tar가 directory를 포함한다면, 자동적으로 directory가 생성되고 file이 속하게 된다. 
  
===| compress |=======================
근래에는 잘 사용하지 않는 compress의 경우 가장 먼저 나와서 가장 오랫동안 사용되었으나, algorithm에 대한 Software License 문제와 gzip의 효율이 compress 보다 좋다는 점, 그리고 gzip으로도 compress를 이용해 압축된 file을 다룰 수 있다는 등의 이유로 gzip(GNU Zip)으로 대치되었다.

compress로 압축된 file의 끝에는 확장자 .Z가 붙는다. 예를 들면,
$ compress backup.tar 라는 명령으로 backup.tar를 compress를 사용해 압축하면 backup.tar.Z이 만들어진다.
압축을 해제할 때에는 다음과 같이 uncompress를 이용한다.
$ uncompress backup.tar.Z 해주면 backup.tar가 풀려나온다.

===| GZip |=======================
GNU Zip(gzip)은 compress 명령보다 더 나은 Data Compression기능을 갖고 있으며 주로 tar로 묶여진 archive를 다시 압축할 때 사용하게 된다.
압축파일에는 ".gz"라는 확장자가 붙는다.

$ gzip -9 backup.tar 와 같이 명령을 주면 최상의 압축률(-9)로 backup.tar를 압축한 backup.tar.gz가 만들어진다.
이것을 Pipe와 Redirection을 사용하여
$ tar cvf - /home/jvm | gzip -9c > backup.tar.gz 와 같이 해주어도 된다.
(먼저 tar file을 tar의 표준출력(-)으로 보내고, 이것은 gzip과 pipe되어 들어오는 tar file을 압축하여 그 결과를 backup.tar.gz로 redirect시킴으로써 file로 저장된다. gzip의 -c option은 출력을 redirect하기 위해 표준출력으로 보낸다.)

압축을 해제하기 위한 명령은 gunzip이다. 이것은 gzip -d와 동일하다.
$ gunzip backup.tar.gz 명령을 통해 backup.tar가 풀려나오고,
$ tar xvf backup.tar 해주면 archive가 풀려진다.
이 두 명령을 한 번에 하려면
$ gunzip -c backup.tar.gz | tar xvf - 와 같이 하면된다.
(gunzip은 bacup.tar.gz의 압축을 해제하고, 그 결과를 표준출력으로서 tar에 보낸다. -는 tar의 표준출력.)
이제 흔히 볼 수는 없지만 확장자가 .taz이거나 .tgz인 archive들을 어디선가 만날 수 있다.
Linux/Unix에서는 file을 하나의 archive로 인식하기 위하여 어떤 특정한 확장자를 꼭 붙여줄 필요가 없다. 단지 알아보기 편하도록 tar로 묶으면 확장자 .tar를 붙이고, 이것을 압축하면 .tar.Z나 .tar.gz와 같은 확장자가 붙게 된 것이다.
그렇지만 MS-Dos System에서는 이러한 이중확장자를 사용할 수 없었기 때문에 .tar.Z와 동일한 .taz확장자와 .tar.gz와 동일한 .tgz가 사용되었다. 이러한 압축을 푸는 방식은 물론 .tar.Z와 .tar.gz와 동일하다.


===| bzip2 |=======================
bzip2는 Lossless Data Compression Algorithm으로
Burrows-Wheeler Transform(Block-Sorting Compression)을 써서 자주 반복되는 Character String을 같은 Character String로 변환한 다음 MTF(move-to-front) Transform, Huffman Coding을 차례대로 적용하는 구조이다. gzip이나 zip에 비해 압축률이 좋지만 느리다.(13MByte 정도 크기의 text file을 압축하면 354kByte가 되었다고 하니 놀랄만한 압축률이다.)
bzip2 자체적으로는 다중파일을 다루거나 분할압축, 암호화 등의 기능이 없다. 그러한 기능은 tar와 같은 다른 Utility가 대신하게 된다. 특징이나 사용할 수 있는 option은 gzip과 거의 같다.
압축파일에는 ".bz2"라는 확장자가 붙는다.

$ bzip2 backup.tar 와 같이 명령을 주면 backup.tar를 압축한 backup.tar.bz2가 만들어진다.
이것을 Pipe와 Redirection을 사용하여
$ tar cvf - /home/jvm | bzip2 > backup.tar.gz 와 같이 해주어도 된다.

bzip2는 압축만 할 수 있고 archive 기능은 가지고 있지 않다.
또한 위에서 다중파일을 다루지 못한다고 하였는데 여러 file들을 각각 동시에 압축하는 것은 가능하다.
예를 들어 file1, file2, file3 가 있는 directory에서
$ bzip2 * 와 같이 명령을 주면 file1.bz2, file2.bz2, file3.bz2 가 생성된다.
$ bunzip2 * 해주면 file1, file2, file3가 동시에 풀려져 나온다.

압축을 해제하기 위한 명령은 bunzip2이다. 이것은 bzip2 -d와 동일하다.
$ bunzip2 backup.tar.gz 명령을 통해 backup.tar가 풀려나오고,
$ tar xvf backup.tar 해주면 archive가 풀려진다.
이 두 명령을 한 번에 하려면
$ bunzip2 -c backup.tar.gz | tar xvf - 와 같이 하면된다.

[Tip]
BSD와 GNU Version tar는 compress와 gzip압축을 다룰 수 있는 option(Z / z)와
bzip2압축을 다룰 수 있는 option(j)가 patch되어 있다.
따라서 pipe를 사용하지 않고 한 번의 명령으로 압축이나 해제를 할 수 있다.

$ tar czvf  archive-name.tar.gz * 라고 하면 하위 디렉토리를 포함한 모든 파일을 tar로 묶어서(.file은 제외) gzip으로 압축하라는 의미이다.
(Z option에 archive-name.tar.gz 대신에 archive-name.tar.Z를 사용하면 compress로 압축.)
$ tar xzvf archive-name.tar.gz와 같이 z option을 사용하여 tar.gz을 한 번에 압축해제 가능.
(Z option에 archive-name.tar.gz 대신에 archive-name.tar.Z를 입력하면 compress 압축해제.)
하위 디렉토리를 포함한 모든 파일을 tar로 묶어서(.file은 제외) bzip2로 압축하려면
$ tar cjvf  archive-name.tar.bz2 *
tar.bz2를 한 번에 압축해제 시키려면
$ tar xjvf archive-name.tar.bz2
결론적으로 여러 Data Compression Software들이 있지만 tar 하나만 잘 활용하면 .tar, .tar.Z, .taz, .tar.gz, .tgz, .tar.bz2 와 같은 확장자를 가진 모든 압축파일을 문제없이 사용할 수 있다.

<추가>
tar의 info page를 찾아보다가 그동안 정확히 알고 있지 못하던 내용을 새로이 보게되어 추가한다.
tar에서 option을 주는 방법은 Long option / Short option / Old style option 세가지가 있다.
--verbose 이렇게 사용하는 것은 Long option,
-v 이렇게 쓰는 것은 Short option이고 Old style option은 Short option과 마찬가지로 Single letter이다.
그러나 단독으로 사용할 수는 없고 공백없이 option letter들을 붙여쓴다.
위에서 tar에 대한 예로서 사용한 명령들은 다 Old style option을 사용하였다.
tar --create --file=archive.tar file1
tar -cf archive.tar file1
tar cf archive.tar file1
이 세 명령은 모두 동일하다. 그렇지만 조심해야할 경우가 있다.
tar -cfz archive.tar.gz file1
tar cfz archive.tar.gz file1
이 두 명령은 전혀 다르다. Old style option의 경우 f option에 대한 value로서 archive.tar.gz를 사용하고,
gzip압축을 위한 option으로서 z를 인식하게 된다. 이와 같은 기대를 하고 tar -cfz archive.tar.gz file1 을
사용하면 전혀 의외의 결과를 얻게된다. 왜냐하면 이 경우 z가 f option에 대한 value로 받아들여져 버리기
때문이다. 하지만 다음과 같이 사용함으로써 이 문제를 피할 수 있다.
tar -czf archive.tar.gz file1
tar -cf archive.tar.gz -z file1
tar cf archive.tar.gz -z file1
Old style option은 구버전의 tar와의 호환성을 위해 유지되고 있다.
Long option의 경우 단어 자체를 사용하므로 직관적이나 길어서 불편하다.
개인적으로는 Old style option이 편하긴 하지만 아무래도 Short option 형태를 사용하는 것이 나을 것도 같다.
다만 f option의 경우처럼 value가 바로 따라오는 syntax를 가진 경우를 조심해야한다.

2008년 5월 18일 일요일

Kubuntu 8.04 (KDE 4 Remix)를 Laptop에 설치

이미 Ubuntu의 새버전이 나온 소식은 알고 있었지만 시간적으로나 공간적으로나 여유가 없었다.
그렇지만 마침 하드디스크 공간부족 문제가 좀 나아졌고,
역시나  Desktop이나 Laptop 중 하나에 Linux가 필요해서 내친 김에
Kubuntu KDE 4 Remix 버전을 다운 받아 Laptop에 설치했다.
설치에 있어서 특별히 인상적인 변화는 [Install inside Windows]옵션이다.
Linux설치를 위한 Partition 조절 등의 사전작업이 필요가 없어졌다.
물론 이 옵션을 통해 설치된 Linux System이 boot된 Windows 안에서 돌아가게 되는 것은 아니다.
Windows File System 안에 설치되기는 하지만 Multibooting하도록 구성된다.
Windows 상에서 설치 이미지를 만들어주고 재시작하여 Kubuntu를 선택하면 설치를 진행하여 완료하게 된다.
역시나 (K)ubuntu, 그다지 물어보는 것이 없다. 지정할 것도 별로 없다.
그냥 알아서 설치 끝이다.
상당히 많은 사람들이 이러한 (K)ubuntu의 특징이랄까, 정책이랄까 하는 점을 좋아하는 것같은데
사실 나로서는 (K)ubuntu 배포판에서 가장 마음에 들지 않는 점이다.
일단 거의 지맘대로 설치되고 나서야 내 입맛에 맞게 바꿀 수 있다는 것이 상당히 마음에 안든다.
아마 Linux를 처음 설치해볼 무렵부터 설치과정 중에 불필요한 것들은 최대한 제거하는 점에 많은 노력을 기울여 왔었기 때문일 것이다.(설치할 Package 선별하는 데에만 가볍게 한 두 시간을 넘겼던 적도 있다. 말이 선별이지 1000개가 훨씬 넘는 Package들의 이름만 한 번씩 읽어보는 것도 간단한 일은 아니다.)

하여간에 별다른 문제 없이 설치를 마치고 한층 예뻐진 KDE4의 로그인 화면을 보니 기분이 나아졌다.
그런데 로그인 후 거의 방황을 하게된다. 원하는 설정을 어떻게 해야할 지 떠오르지 않는다.
뭐가 설치되었는 지 아직 정확히 알 수가 없으니 어떠한 설정도구를 사용해야 할 지 알 수가 없다.
또한 여기에서 느낄 수 있는 것은 SuSE Linux의 그림자라고 할 수 있는 것이었다.
아는 사람은 공감하겠지만 SuSE에는 YAST라는 통합설정도구가 있어서 이 안에서 모든 시스템 설정이 가능하다. 여기에 익숙해진 사람은 YAST가 없는 System에 가면 한 동안 길잃은 미아가 될 수밖에 없다.
Adept Package Manager를 이용해 몇가지 필요한 것들을 추가하고 나니 조금은 미로에서 벗어날 수 있었다.
그렇지만 의도대로 설정되지 않는 것이 아직 너무 많다.
그리고 아직 KDE4 Remix버젼은 완전하지 못한 것인지 Tray에 뜨는 Applet들에 문제가 좀 있다.
지금 팔걷어 부치고 삽질할 형편은 아니니 천천히 손을 봐줘야 하겠다.

Mr. Dust님의 Blog Posting "우분투 한국 커뮤니티의 변화"에 보면 이렇게 쓰신 부분이 있다
[... "리눅스를 사용하기 위해서는 무언가를 배워야한다." 라는 개념을 버리고, "단지 사용하는데에만, 얼마나 편하게 사용하느냐에 집중한다." 라는 것이다.  ...]
사실 이 의견은 일리가 있기는 하지만 개인적으로 어느 정도는 괘변적으로 들린다.
아마도 Dust님과 나의 발상의 차이에서 오는 것일테지만 (K)ubuntu는 그다지 특이하게 사용하기 편리해서 좋은 배포본은 아니라고 생각한다. 주어지는 대로 쓰기로 하면 Gentoo 같은 배포본만 아니라면 사용의 편의성은 큰 차이가 없다. 사실 나로서는 (K)ubuntu는 상당부분 불편하기 짝이 없다고까지 느낀다.
내가 경험한 (K)ubuntu 배포본의 장점은 그 속도에 있다고 본다.
확실히 (K)ubuntu는 빠르다. 이 점때문에 많은 개발자들이 Ubuntu에 열광하지 않았을까 생각한다.




 

2007년 11월 6일 화요일

나의 노트북 이야기


다음 달이면 산 지 2년이 되는 Laptop이다.

Asus A6Va--Q00VA (view larger image)

Specifications:

  • Intel Pentium M processor 740 1.73GHz
  • HD 80 GB
  • 15.4" (WXGA) Colour Shine
  • 128Mb ATI Mobility Radeon X700
  • Optical Drive 8x DVD-RW Dual
  • 1024Mb DDR2 533MHz (512x2)
  • Wireless IEEE 802.11b/g
  • 4x USB 2.0, 1xIEEE 1394
  • Video Camera built-in (1.3 million pixels) and Microphone
  • Built in Bluetooth
  • Weight: 2.85kg

RAM은 원래 512Mb이 들어있던 것을 1024Mb로 늘렸다.

작년 말에 비디오칩 고장으로 한달여 AS를 다녀온 것 말고는 항상 나의 곁을 지켜주었다.
Harddisk가 좀 작은 편이라거나, Graphic Driver의 호환성이 그다지 좋지 않다라든지 하는
자잘한 불만이 있기는 하지만 대부분의 해외 Review에서 볼 수 있듯이 상당히 "solid"한 제품이다.
1030 Euro 정도 줬는데 지금이야 그 돈이면 훨씬 더 좋은 물건을 살 수 있지만 당시 이만한 물건을
이 정도 가격에 구한 것은 최선의 선택이었다고 할 수 있다.

이 노트북에서 사용한 운영체제들은 처음에 설치되어 온 Windows XP Home,
나중에 새로이 설치한 Windows XP Pro, Windows FLP, Windows Vista Business와
OpenSuSE Linux 10.1, 10.2, 10.3, Kubuntu 7.04 등이 있다.
지금은
Windows XP Pro와 OpenSuSE 10.3을 Multibooting으로 사용하고 있다.

소음에 민간한 나에게 그다지 소음에 대해 자주 신경쓰도록 하지는 않지만
Windows 상에서는 Fan이 비교적 자주 돌고, 일단 Fan이 도는 소리는 좀 거슬리는 편이다.
일예로 아마 Office 2007이 워낙 자원을 많이 사용하는 편이라서 그럴 거라 생각하지만
MS Word를 사용할 때 Fan이 자주 돌면 꽤나 신경이 쓰인다.
CPU 온도도 60도 이상에서 노는 일이 잦다.

반면에 Linux에서는 훨씬 쾌적하게 느낀다. 현재 CPU 온도는 50도이다.
온도가 낮게 유지되니 당연히 Fan도 자주 돌지 않는다.

그런데 Laptop에서 Linux를 Main Operating System으로 사용하지 못하게끔 하는 몇 가지 문제가 있었다.
그 중 첫째는 Synaptics Touchpad가 Linux에서 너무 민감하게 반응하여 사용에 큰 불편이 있을 지경인데
설정도구가 없다는(사실은 있지만 제대로 작동되지 않는) 점과
Headphone을 잭에 꽂으면 소리가 전혀 나지 않는다는 점이었다.
근래 도서관에서 강의파일들을 열어봐야 할 일이 많은 데 이 문제로 인해 도서관에서는 Linux를 사용할 수 없었다.
과거형으로 적었는데 그 이유는 이 두 문제가 최근에 모두 해결되었기 때문이다.

Touchpad문제는 새로운 OpenSuSE 10.3을 설치함으로써 자연스레 해결되었고, Headphone문제는 어제 오늘
양일 간에 걸친 삽질 끝에 마침내 해결을 보았다.
원래는 나중을 위해 이 삽질기를 기록해 둘 요량으로 적은 글이 사설이 길어져 이렇게 잡담코너로 넘어와 버렸다.

이젠 Bootloader의 Default OS를 Linux로 바꿔야 할 때가 드디어 온 것 같다.



[Tip][OpenSuSE10.3] Samba Configuration on KDE


KDE환경에서 Samba Server 설정하기 + SWAT

GSAMBAD와 같은 Samba Server를 위한 Frontend도 이미 나와 있기도 하고,
앞서 2007/06/05 - [Linux] - SAMBA 설정과 이용에서  언급했듯이 여러가지 방법이 존재한다.
(물론 어떠한 방법이든 내부에서 최종적으로 하는 일은 동일하다.)

여기서 보이려는 방법은 나의 경우에서 가장 간편하다고 생각된 방법이다.

1. Menu에서 Personal Settings를 선택한다.


2. Internet & Network를 선택한다.


3. 아래 쪽의 Samba를 선택한다.


4.  Samba Server의 설정을 변경하려면 Administrator Mode를 선택해주어야 한다.


5. root password를 입력하고 계속한다.


6. Base Settings 항목이 나타난다. 원하는 대로 설정을 변경하고 apply를 누르면 적용된다.
    또한 여기에서 보안레벨을 정하게 되는 데 각자 환경에 따라 적절한 것을 선택한다.
    나의 경우 가장 일반적인 보안정책으로 생각되는 User를 선택하였다. (이렇게 하면 Samba Server에 접속하는
    이용자는 Server에 등록된 id와 password를 입력해야만 접속할 수 있다.)


7.  Shares항목에서는 공유되고 있는 목록을 보여준다. 목록의 기존공유를 편집하거나 새 공유 추가, 공유제거 등
    의 작업을 할 수 있다.


8. Samba를 사용할 사용자를 등록한다.


9. DOS charset을 CP949로 바꾸어 주었다.(CP949는 euc-kr을 포함하는 MS의 확장완성형 문자 인코딩)


10. 부팅시 Samba를 기동시키기 위하여 Runlevel을 수정한다.


11. smb와 nmb service가 활성화되어야 한다.


12.  SWAT는 xinetd를 통해 구동되게 된다.

만약 Firewall이 기동되어 있다면 Samba Server를 위한 Port를 열어 주어야 한다.
위 그림에 보이는 Samba Server 항목(이 안에서 여기서 설명하고 있는 대부분의 과정을 설정할 수도 있다.)에
들어가면 Firewall Settings에서 Port 열어주도록 할 수 있다.
또한 여기의 Service Start항목을 통하여 10과 11의 과정을 간단하게 설정할 수도 있다.

13.  swat service를 활성화 시킨다.


14. SWAT가 구동되면 웹브라우저에 http://localhost:901이라 입력하여 불러올 수 있다.
       (User Name과 Password를 물어오는 데 기본적으로는 root로 login한다.)


15.  SWAT에 접속한 화면이다.


16. GLOBALS 항목에서 앞서 설정했던 내용들을 볼 수 있다. 물론 여기에서 새로이 설정할 수도 있다.
      기왕에 SWAT을 사용할 거라면 위에서 설명한 3~9까지의 과정은 이곳에서 설정해도 된다.
      다만 아주 간단한  설정을 위해서라면 SWAT가 필요하지 않을 수도 있을 것이다.


17.  Username/Password를 등록한다. (다른 컴퓨터에서 이 Samba Server에 접속할 때 사용할 정보이다.)


18. Samba Server가 service되고 있는 상태를 볼 수 있다.
      설정 변경 후 여기에서 smbd/nmbd를 재시작 해줄 수 있다.


19.  동일한 네트워크에 위치하고 있는 Windows에서 네트워크 환경에 들어가면 아래와 같이
       Samba Server에 의해 공유되고 있는 자원을 볼 수 있다.
       실제로 사용하려면 17에서 설정한 정보를 사용하면 된다.



꼭 이렇게 하지 않아도 GUI환경에서 Samba Server를 필요에 맞게 설정할 수 있는 방법은 여러가지가 있다.
편리한 것을 선택하는 것은 사용자의 몫이다. SWAT만으로도 Samba Server설정에 관한 모든 것을 할 수 있다.
그러나 기본적으로 설정파일을 수정하고 console에서 필요한 service들을 구동시키는 작업을 한 번쯤은 해보고
GUI도구를 사용할 것을 권하고 싶다. 설정파일 안에 있는 내용들을 전혀 이해하지 못하는 상태에서 GUI도구가
제공해주는 편리한 기능을 제대로 사용할 수가 없기 때문이다.

[Related Article] 2007/06/05 - [Linux] - SAMBA 설정과 이용

[Tip] SAMBA 설정과 이용


SAMBA는 Windows와 Linux간의 상호 파일과 Print 시스템을 공유하는 것을 가능하게 해 준다.
Linux만으로 구성된 Network을 보는 것은 아주 드문 일이므로
이 기종 간의 Networking(Linux Server의 Resource를 Windows Client에서 사용이 가능하도록 해주고,
그 반대로도 마찬가지.)을 가능하게 해주는 SAMBA의 가치는 아주 높다고 할 수 있다.

Linux에서 대부분의 Service들은 기본적으로 Terminal에서 설정파일을 편집하고,
필요한 Command를 내려주는 방법으로 설정이 가능하다.
또한 한 편으로 이러한 작업을 손쉽게 해주는 GUI Tool들이 존재한다.
두 가지 방법 중 편리하다고 느끼는 쪽을 선택할 수 있는 것이다.

SAMBA의 경우는 하나의 가능성이 더 있는데, 바로 SAMBA Package에 포함되어 있는
SWAT(SAMBA Web Administration Tool)를 이용하는 방법이다.
SWAT을 통해 SAMBA의 모든 것을 Web-Interface에서 설정, 관리할 수 있다.
SWAT는 localhost의 tcp 901 port로 구동된다. 웹브라우저로 불러와 사용하면 된다.
각 설정 항목마다 HELP Link가 있어서 확인해가며 설정해나갈 수 있다.
Samba konfigurieren mit SWAT
삼바(TM) 설치 및 활용 가이드 열번째 판 A2

삼바 서버를 위해 구동되는 Daemon은 다음의 둘이다.
smbd      (SMB Daemon)
nmbd      (Client를 위해 NetBIOS nameserver를 지원)

inetd에 의해 Daemon을 실행시키기 위해 (이미 들어있지 않다면) 아래 내용들을
/etc/inetd.conf 에 추가시켜야 한다.
# SAMBA NetBIOS services (for PC file and print sharing)

netbios-ssn stream tcp nowait root /usr/sbin/smbd smbd

netbios-ns dgram udp wait root /usr/sbin/nmbd nmbd
이렇게 하면 시스템 시작 시 SAMBA Server가 구동된다.

Server환경은 설정 파일인 /etc/samba/smb.conf파일을 통해서 수정한다.

smb.conf example from KLDP

more..


수정을 마치고 나서는 Service를 재시작해야 변경사항이 적용된다.
# /etc/init.d/smb restart

[Related Article] 
2007/11/06 - [Linux] - [Tip][OpenSuSE10.3] Samba Configuration on KDE

2007년 11월 3일 토요일

Kaffeine과 Xine에서 한글자막 보기

Xine은 /usr/share/xine/libxine1/fonts에 들어있는 자신만의 font를 사용하므로 원하는 font를 사용하려면

TrueTypeFont를 XineFont로 바꾸어 주는 변환 프로그램인 xine-fontconv가 필요하다.

xinehq.de에 가서 xine-lib-x.x.x.tar.bz2를 받는다.(여기서 사용한 것은 1.1.8 버전이다.)

$ tar xvfj xine-lib-1.1.8.tar.bz2                          // 압축해제

$ cd xine-lib-1.1.8/misc                                   // xine-fontconv.c 가 있는 위치로 이동


$ sudo gcc xine-fontconv.c -o xine-fontconv `freetype-config --cflags --libs` -lz

[주의] ' 나 " 가 아니라 `이다.  위의 명령을 복사하여 붙여넣으면 가장 확실하다.

freetype2 libraries가 시스템에 설치되어 있어야 한다.

이렇게 하면 xine-fontconv가 생성된다.

이제 원하는 TrueTypeFont(gulim.ttf or Eunjin.ttf)를 /usr/share/xine/libxine1/fonts로 복사한다.

OpenSuSE의 경우 설치해둔 TrueTypeFont들은 /usr/share/fonts/truetype에서 찾을 수 있다.

xine-fontconv도 마찬가지로 복사하고 /usr/share/xine/libxine1/fonts로 이동한 다음

은진폰트로 예를 들면
# ./xine-fontconv Eunjin.ttf Eunjin euc-kr         // euc-kr Encoding으로 Eunjin이란 XineFont 생성



이제 카페인을 실행시키고
Settings-> xine Engine Parameters -> subtitles 선택 후 Beginner Options 에서
subtitle size를 large 정도로 변경해 준다.
그리고 encoding of the subtitles를 euc-kr로 바꾼다.


Expert Options 탭으로 이동해서 sans 라고 되어 있는 부분을 Eunjin이라고 바꿔준다.


이것으로 설정완료.

(주의.) 처음 이 Tip을 작성할 당시는 아무런 문제가 없었지만 그 후 몇 차례 Kaffeine의 update가 있었다.
아마도 그 이후로 한글자막이 정상적으로 보여지지 않고 있다. 한글이 모두 #######로 나오는 문제이다.
새로이 xine font를 생성해 보았고 다른 글꼴들도 시도해 보았지만 모두 마찬가지였다.
최신 버젼의 Kaffeine에게 일종의 Bug가 있는 것이 아닐까 추측하고 있을 뿐이다.
Mplayer를 사용하면 여전히 한글자막이 잘 보여진다.

최근의 업데이트 이후에는 정반대의 현상이 벌어지고 있다.
Mplayer에서는 한글자막이 표시되지 않고, Kaffeine에서는 잘 나온다.
역시나 버전에 따라
Bug가 서로 다르게 나타나는 것으로 보인다.
한동안 S
Mplayer만 썼더니 Kaffeine이 어색하다.

===================================================================

<Xine 한글 자막 설정>

    Xine에서 한글 자막을 보려면 설정 파일을 직접 수정해야한다.

    설정 파일은 ~/.xine/config

    굵은 글씨로 써진 부분을 수정하면 된다.

        # subtitle size
        # { tiny  small  normal  large  very large  huge }, default: 1
        subtitles.separate.subtitle_size:large

        # subtitle vertical offset
        # numeric, default: 0
        #subtitles.separate.vertical_offset:0

        # font for subtitles
        # string, default: sans
        subtitles.separate.font:Eunjin

        # encoding of the subtitles
        # string, default: euc-kr
        subtitles.separate.src_encoding:euc-kr

2007년 10월 29일 월요일

JBD error message "barrier-based sync failed"

일반적으로 근래의 배포폰들은 처음 설치하면 Boot Splash는 silent로 설정이 된다.
이렇게 설정되면 예전의 text가 주루룩 흘러내려가는 Boot screen은 보여주지 않고 MS Windows처럼
Bootlogo가 보여지게 된다.
내 개인적으로는 이러한 형태의 silent boot를 전혀 좋아하지 않는다.
우선은 Booting 과정에서의 문제를 전혀 파악할 수 없고(사실 이 부분은 최근의 System들이 너무 성능이
좋아지는 바람에 바람과 같은 속도로 주주룩 지나가는 내용을 보고서 정확한 문제를 파악하는 것은
불가능하기는 하다. 어차피 Booting 완료 후 Log를 봐야만 정확한 내용을 알 수 있다.)
Bootlogo를 보고 있으면 Booting 시간이 지루하게 느껴진다는 점 때문이다.
그래서 항상 Boot Splash는 verbose로 설정한다.
나름대로 구세대 Linuxer라서인지 Boot text가 흘러내려가는 화면이어야만 제대로 Linux가
Boot되고 있다는 느낌이 들어서 좋다.
최근에 특별한 원인을 알 수 없는 System 이상으로 Desktop에 Linux를 두 번이나 새로이 설치해야만 했다.
여러 증상들로 보아 노후한 Hardware들로 인한 문제들인 것 같기는 한데 Diagnostic Tool이나
Testing Tool들을
돌리면  별다른 문제가 발견되지가 않으니 골치가 아프다.
분명히 문제가 있는데 찾아낼 수가 없으니 말이다.

결국 마지막에는 두 개의 Harddisk 중 OS가 위치하는 것을 Low-level Format하고
OpenSuSE에서 지원하는 RAID-1(Mirroring)을 이용하여 설치하였다.

Mirroring을 위해 Disk 공간을 두 배로 할당하는 희생을 치른 결과 앞에 설치했던 경우보다는
안정적으로 돌아가게 되긴 했지만 아직도 가끔 System이 멈춰 버리는 일이 있다.

다수의 Harddisk를 이용한 제대로 된 RAID를 구성한 것이 아니라서 그런가보다 생각하지만
현재로서는 Harddisk 두 개를 완전히 비울 수 있는 여건이 되지가 않는다.
근본적인 원인이 Hardware에 있다는 믿음은 있지만
일단 OS차원에서도 문제가 있어서는 안되겠기에 지속적으로
Boot message를 점검하고 있다.
사소한 문제들은 간단히 Service를 제거하는 정도의 조작으로 해결이 되었지만
잘 모르는 내용의 Error가 여전히 있었다.

JBD error message "barrier-based sync failed" 라는 것이었다.
File System을 check하는 부분에서 나온 것 같아 검색을 해보니
novell support page에 해결법이 나와 있었다.

more..



[Related Article]
2007/02/16 - [Linux] - [scrap] 리눅스 부팅
2007/08/24 - [Linux] - Hardware Monitoring Tools for Linux


2007년 10월 28일 일요일

[OpenSuSE 10.2] Latest Nvidia Driver Intallation


[Source] Nvidia Installer HOWTO for SUSE LINUX users

People who aren't afraid of recompiling the nvidia kernel module
or even reinstalling the nvidia driver each time the kernel has been updated
and want or need to use the latest and greatest nvidia driver
can use the following steps 1-3.
The others should use the instructions above using YaST and skip the steps below.

1) Kernel sources must be installed and configured.
Usually this means installing the 'kernel-source', 'make' and 'gcc' packages with YaST2.

2) Use the nvidia installer for 100.14.19.

3) Configure X.Org with
sax2 -r -m 0=nvidia (0 is a digit, not a letter!)

NOTE: There is no need to try to enable 3D support.
It's already enabled, when the nvidia driver is running.
IMPORTANT: You need to
recompile and install the nvidia kernel module after each kernel update.
sh NVIDIA-Linux-x86-100.14.19-pkg1.run -K

2007년 10월 9일 화요일

[Tip] Bootsector 복사

Windows 2000 이후의 MS Windows와 Linux를 하나의 System에 함께 설치하여 사용해야할 필요가 있을 수 있다.

Windows의 NTLoader와 Linux의 GRUB은 모두 Multiboot 환경을 지원하는 Bootloader이므로, 어느 것으로든 Multiboot환경의 Main Bootloader를 삼을 수 있다.

더 간단한 쪽은 GRUB을 Main Bootloader로 사용하는 것이다.

Windows가 이미 설치되어 있는 System에 Linux를 설치하고 GRUB을 MBR에 심어 Main Bootloader로 사용한다면 특별히 손을 봐줘야만 하는 작업은 거의 없다. 자동으로 Multiboot 환경이 GRUB에 구현된다. 세부설정만 입맛에 맞게 수정해주면 족하다. 만약 반대의 순서로 설치한다면 NTLoader가 MBR을 덮어쓰면서 GRUB의 설정이 날아간다. 따라서 이 경우는 차후에 GRUB을 다시 MBR에 복원하는 작업이 필요하다.(참고: SuSE Rescue System을 사용하여 GRUB복구하기)

만약 Windows NTLoader를 Main Bootloader로 사용하고자 한다면 약간의 수작업이 필요하다.

여러가지 경우의 수가 있지만  Linux를 설치하면서 GRUB은 MBR에가 아니라 Boot Partition에 설치하기만 한다면 어느 운영체제를 먼저 설치하느냐는 상관이 없다. 다만 두 운영체제의 설치가 끝난 다음 Linux의 bootsector를 복사해 NTLoader에 붙여주면 된다.(이렇게 한 줄로 써놓았지만 현재 MBR에는 Windows Entry만 있는 NTLoader가 자리잡고 있는 상황이므로, 설치된 Linux로 들어가서된 bootsector를 복사하고 그것을 다시 Windows로 가져오는 것은 약간 번거로울 수 있다. 우선은 설치시디를 이용해서 부팅해 들어간 다음 작업을 해야할 것이다. bootsect.lnx를 가져오는 작업은 Windows로  재부팅하여 Ext2 IFS for Windows를 이용하면 편리하다.)

bootsector를 복사하는 명령은 다음과 같다.

# dd if=/dev/hda7 of=/bootsect.lnx bs=512 count=1
//**root권한이 필요하다. /dev/hda7는 Linux의 boot partition.**//
이렇게 복사한 bootsect.lnx를 Windows의 C:\로 복사해주고 다음의 방법으로 Windows Bootloader에 붙여준다.
boot.ini의
[operating systems] 항목 마지막 줄에
C:\bootsect.lnx="Linux" 추가.

2007년 10월 8일 월요일

[Tip] skim에서 한영키 사용하기

이 Tip은 OpenSuSE 10.2를 기반으로 작성하였으나 10.3으로 새로 설치한 뒤에도
그대로 적용하여 사용하고 있다.

skim은 SCIM(Smart Common Input Method) platform의 Frontend이다.
SCIM이 gtk2 기반인데 반해, skim은 qt를 기반으로 하고 있다.

OpenSuSE 10.2를 설치할 때 필요한 팩키지들
(scim, scim-hangul, scim-input-pad, scim-tables, scim-tables-ko,
scim-tables-skim, scim-hangul-skim, scim-qtimm, skim)이 모두 설치되었다면
별도의 설정없이 skim이 뜨고 한글을 입력할 수 있는 상태가 된다.
(한글 뿐 아니라 전세계 거의 모든 문자의 입력이 가능한 상태가 된다.)
# yast -i scim scim-hangul scim-input-pad scim-tables scim-tables-ko
scim-tables-skim scim-hangul-skim scim-qtimm skim
// 이와 같이 하나의 명령으로 필요한 모두를 설치할 수도 있다.
이 상태로도 사용상 문제는 없지만 속도를 위한 최적화 설정은 다음과 같다.
skim 트레이 아이콘 오른쪽 클릭 - configure에 들어간다.
Frontend 부분에 General SCIM -> Others 탭의 내용을
패널프로그램 scim-panel-kde로, Config Module을 Kconfig 로 설정.
Advanced 를 클릭하여 유니코드 로케일 지원 -> 고치기 버튼을 클릭하여
(만약 없다면) ko_KR.UTF-8 을 더해준다.
(실제로 OpenSuSE의 경우 모든 Unicode Locale들이 이미 들어있으므로 이 추가과정은 필요치 않다.)

이 상태에서 한영전환은 Shift+Space로 하게 된다.
이젠 한영키를 사용하기 위한 설정이다.
우선 xev명령을 사용하여 한영키와 한자키의 keycode를 알아내야 한다.
내 경우는 113과 116이다.

~/.kde/Autostart/hangul와 같은 파일을 새로이 만든다.
#!/bin/bash
xmodmap -e "keycode 113 = Hangul"
xmodmap -e "keycode 116 = Hangul_Hanja"
저장한 다음 실행권한을 준다.
$ chmod a+x ~/.kde/Autostart/hangul

System을 재부팅한후 skim의 configure -> General SCIM -> Toggle on_off 의
... 버튼을 눌러 나오는 창에서 다시 ... 버튼을 누른 후,
한영키를 누르고, 더하기 버튼을 누르면 완료.

2007년 10월 4일 목요일

[Tip] Wine을 통해 NetFolder 웹하드 이용하기

완벽하지는 않아도 Linux에서 Windows용 Software를 사용하는 것이 가능하다.
이를 위해 Windows Emulator인 Wine이 필요하다.
하지만 Wine은
"Wine Is Not an Emulator"에서 온 이름이니 Emulator라 불러서는 안될 것 같기도 하다.
Wine Project Homepage에서는 아래와 같이 설명하고 있다.
Wine is an Open Source implementation of the Windows API on top of X, OpenGL, and Unix.
Think of Wine as a compatibility layer for running Windows programs.
현재 SourceForge에 올라와 있는 최신판 SuSE빌드는
wine-0.9.45-SuSELinux102.i586.rpm 이다. 배포본별로 rpm이 제공되고 있다.
Wine을 통해 할 수 있는 일은 많다.
Internet Explorer를 설치하고 ActiveX를 사용하는 일조차 가능하게 해준다.(IEs4Linux, ActiveX 사용하기)
또한 Wine의 상용버전들도 존재한다.
MS Office2003, XP, 2000 and 97와 Adobe Photoshop 7등을 Linux에서 사용할 수 있게 해주는 Crossover와 예전에 WineX로 알려졌었고 DirectX API의 구현에 촛점을 맞춰서 Windows Game을 Linux에서 돌아가게 해주는 Cedega가 그것이다.
Linux에서 eMule이나 BitTorrent를 사용하는 것에는 거의 제약이 없다.
aMule이나 Mldonkey, KTorrent 등의 Linux용 client program들이 있기 때문이다.
그러나 우리나라의 웹하드 서비스들은 특히나 하나같이 오직 MS Windows 기반의
자체 다운로드도구를 사용하도록 하고 있기 때문에 Linux 사용자들에게는 그림의 떡과도 같았다.

Wine을 사용하여 이러한 웹하드 다운로드도구를 Linux에 설치해보자.
여기에서 설치하려는 웹하드 서비스는 NetFolder이다.
물론 설치하기 전에 NetFolder_Setup파일도 미리 다운로드 해둔다.


~/wine에 두 파일(Wine과 NetFolder의 설치파일)을 두고 설치한다.
$ cd ~/wine
$ sudo rpm -ivh wine-0.9.45-SuSELinux102.i586.rpm
한글이 깨지지 않도록 하기위해서 다음 명령을 주고 NetFolder_Setup을 설치한다.
$ export LANG=ko_KR
$ wine NetFolder_Setup.exe
설치가 완료되면 프로그램이 실행되고 로그인하면 다운로드가 가능하다.

실행파일은 ~/.wine/drive_c/Program Files/NetFolder/에 위치한다.
실행은 다음과 같이 한다.
$ wine ~/.wine/drive_c/Program Files/NetFolder/NetFolder.exe
항상 이렇게 긴 명령을 입력해서 실행하는 것은 너무 불편하므로 바로가기를 만들어 두면 좋은데
위의 실행파일을 바로 link하면 한글이 깨져나오고 프로그램이 정상적으로 작동하지 않는다.
다음과 같은 내용이 들어가는 shell script를 작성하고 실행가능하게 해준 다음
link하면 제대로 작동한다.
#!/bin/sh
export LANG=ko_KR
wine ~/.wine/drive_c/Program Files/NetFolder/NetFolder.exe

p.s. 잠깐 사용해 보니 적어도 내가 테스트 한 환경에서는 안정성에 문제가 있었다.
다운로드가 시작은 잘 되지만 다른 작업을 하다보면 프로그램이 잘 죽는다.
특히나 최대-최소 전환 등 화면전환이 일어나는 경우 어김없이 사라져 버린다.
Wine은 계속 업데이트되고 있으므로 새로운 버전에서는 이러한 문제가 곧 사라질 수도 있다.
그렇지만 현재상태로 이래가지고선 장시간 다운로드를 걸어놓을 수가 없으니
차라리 가상머신에 윈도우스를 설치해서 쓰는 편이 나을 것 같다.
다운로드만을 하려고 가상머신을 돌리는 것이 심히 비효율적이긴 하지만 Linux만 설치되어 있는

시스템에서 donkey나 torrent에는 없고 국내웹하드에만 있는 자료들을 구하려면 어쩔 수가 없는 것 같다.



2007년 9월 28일 금요일

[Scrap] 리눅스 서버의 보안설정

리눅스 서버의 보안설정 모음(I)      
일반적인 시스템 보안 설정 및 최적화

리눅스베이 (master@ilinuxbay.com)     |   2003.08.10

▮ root 접속시간 설정
/etc/profile에 "TMOUT=300" 으로 초단위 접속 시간을 설정한다.
설정 시간 동안 아무 작업도 하지 않으면 자동 로그아웃 된다.

▮ /etc/securetty
이 파일은 root가 로그인할 수 있는 터미널 장치(TTY)와 가상 콘솔(VC)을 정의 한다.
login 프로그램은 이 파일을 참조하여 프로세스를 처리한다.
사용하지 않을 장치에 한하여 삭제하거나 주석 처리한다. 그러면 root는 해당 장치로 로그인 할 수 없을 것이다. 추천사항으로 하나의 vc/1과 tty1만을 허용하는 것을 추천한다.

▮ Ctrl-Alt-Del 키를 사용한 부팅 막기
/etc/inittab 파일의 다음 부분을 주석 처리한다
ca::ctrlaltdel:/sbin/shutdown -t3 -r now

▮ /etc/service 파일
[root@ezo]# chattr +i /etc/service

▮ shell 설정
/etc/profile에서 시스템의 모든 사용자에 대해 HISTSIZE를 설정한다.
이는 .bash_profile 파일이 가질 수 있는 명령어수를 지정한다.
HISTSIZE=10
다음과 같이 설정하여 침입자가 현재 시스템에 로그인 되어 있지 않은 사용자의 .bash_profile 파일을 사용하지 못하게 한다.
HISTFILESIZE=0

▮ 파일 시스템 마운트 제어
/etc/fstab에 몇가지 옵션을 주어 설정하고 제어 할 수 있다.
일단 LABEL=/boot와 같은 이름을 /dev/hda1와 같이 파티션 장치명으로 바꾸어 준다.
이는 관리차원과 쿼터를 사용하게 될 때 문제가 될 수 있는 부분을 없애기 위함이다.
/boot 파티션 읽기 전용으로 설정
/dev/hda1 /boot ext3 default,ro 1 2
적용하려면
mount /boot -oremount
확인
cat /proc/mount

▮ chmod로 파일의 권한 변경
아래의 파일들은 침입자가 악용할 수 있는 파일들 이므로 root이외의 권한은 제거한다.
이외에도 설치한 패키지에 따라 권한을 제거해야 할 파일들이 있다.
wget, finger, nslookup그리고 gcc같은 컴파일러 패키지들은 설치 여부에 따라 존재하지 않을 수도 있다.
예] chmod 700 /usr/bin/whereis /usr/bin/consolehelper /usr/bin/pstree
/usr/bin/which /usr/bin/who /usr/bin/w /usr/bin/top
/usr/bin/find /bin/mail /bin/ps /usr/bin/wget /usr/bin/finger
/usr/bin/nslookup /usr/bin/gcc /usr/bin/cc
/usr/bin/c++ /usr/bin/make

2007년 9월 17일 월요일

Tuning LAMP systems, Part 2: Optimizing Apache and PHP

[Source] IBM developerWorks Tuning LAMP systems, Part 2

Tuning LAMP systems, Part 2: Optimizing Apache and PHP

What slows Apache down, and how to get the most out of PHP

Level: Intermediate

Sean A. Walberg (sean@ertw.com), Senior Network Engineer

30 Apr 2007

Applications using the LAMP (Linux®, Apache, MySQL, PHP/Perl) architecture are constantly being developed and deployed. But often the server administrator has little control over the application itself because it's written by someone else. This series of three articles discusses many of the server configuration items that can make or break an application's performance. This second article focuses on steps you can take to optimize Apache and PHP.

Linux, Apache, MySQL, and PHP (or Perl) form the basis of the LAMP architecture for Web applications. Many open source packages based on LAMP components are available to solve a variety of problems. As the load on an application increases, the bottlenecks in the underlying infrastructure become more apparent in the form of slow response to user requests. The previous article showed you how to tune the Linux system and covered the basics of LAMP and performance measurement. This article focuses on the Web server components, Apache and PHP.

Tuning Apache

Apache is a highly configurable piece of software. It has a lot of features, but each one comes at a price. Tuning Apache is partially an exercise in proper allocation of resources, and involves stripping down the configuration to only what's needed.

Configuring the MPM

Apache is modular in that you can add and remove features easily. Multi-Processing Modules (MPMs) provide this modular functionality at the core of Apache -- managing the network connections and dispatching the requests. MPMs let you use threads or even move Apache to a different operating system.

Only one MPM can be active at one time, and it must be compiled in statically with --with-mpm=(worker|prefork|event) .

The traditional model of one process per request is called prefork. A newer, threaded, model is called worker, which uses multiple processes, each with multiple threads to get better performance with lower overhead. The final, event MPM is an experimental module that keeps separate pools of threads for different tasks. To determine which MPM you're currently using, execute httpd -l.

Choosing the MPM to use depends on many factors. Setting aside the event MPM until it leaves experimental status, it's a choice between threads or no threads. On the surface, threading sounds better than forking, if all the underlying modules are thread safe, including all the libraries used by PHP. Prefork is the safer choice; you should do careful testing if you choose worker. The performance gains also depend on the libraries that come with your distribution and your hardware.

Regardless of which MPM you choose, you must configure it appropriately. In general, configuring an MPM involves telling Apache how to control how many workers are running, whether they're threads or processes. The important configuration options for the prefork MPM are shown in Listing 1.


Listing 1. Configuration of the prefork MPM
                
StartServers 50
MinSpareServers 15
MaxSpareServers 30
MaxClients 225
MaxRequestsPerChild 4000

In the prefork model, a new process is created per request. Spare processes are kept idle to handle incoming requests, which reduces the start-up latency. The previous configuration starts 50 processes as soon as the Web server comes up and tries to keep between 10 and 20 idle servers running. The hard limit on processes is dictated by MaxClients. Even though a process can handle many consecutive requests, Apache kills off processes after 4,000 connections, which mitigates the risk of memory leaks.

Configuring the threaded MPMs is similar, except that you must determine how many threads and processes are to be used. The Apache documentation explains all the parameters and calculations necessary.

Choosing the values to use involves some trial and error. The most important value is MaxClients. The goal is to allow enough worker processes or threads to run without causing your server to swap excessively. If more requests come in than can be handled, then at least those that made it through get service; the others are blocked.

If MaxClients is too high, then all clients experience poor service because the Web server tries to swap out one process to allow another one to run. Too low a setting means you may deny services unnecessarily. Checking the number of processes running at high loads and the resulting memory footprint of all the Apache processes gives you a good idea of how to set this value. If you go over 256 MaxClients, you must also set ServerLimit to the same number; read the MPM's documentation carefully for the associated caveats.

Tuning the number of servers to start and keep spare depends on the role of the server. If the server runs only Apache, you can use modest values as shown in Listing 1, because you're able to make full use of the machine. If the system is shared with a database or other server, then you should limit the number of spare servers being run.

Compiling your own software

When I got started with UNIX®, I insisted on compiling my own software for everything I put on my systems. Maintaining updates eventually caught up with me, so I learned how to build packages to ease this task. Eventually, I realized that most of the time I was duplicating the effort the distribution was doing; now, for the most part, I stick with whatever is provided by my distribution of choice when I can, and roll my own packages when I must.

Similarly, you may find that maintainability of vendor packages outweighs the benefits of going with the latest and greatest code. Sometimes performance tuning and systems administration have conflicting goals. You may have to consider vendor support if you're using a commercial Linux or relying on third-party support.

If you strike out on your own, learn how to build packages that work with your distribution and how to integrate them into your patching system. This will ensure that the software, along with any tweaks you make, are built consistently and can be used across multiple systems. Also keep on top of software updates by subscribing to the appropriate mailing lists and Rich Site Summary (RSS) feeds.


Using options and overrides efficiently

Each request that Apache processes goes through a complicated set of rules that dictates any restrictions or special instructions the Web server must follow. Access to a folder can be restricted by IP address to a certain folder, or a username and password can be configured. These options also include the handling of certain files, such as if a directory listing is provided, how certain filetypes are to be handled, or whether the output should be compressed.

These configurations take the form of containers in httpd.conf such as <Directory> to specify that the configuration to follow refers to a location on disk, or <Location> to indicate that the reference is to a path in the URL. Listing 2 shows a Directory container in action.


Listing 2. A Directory container being applied to the root directory

                
<Directory />
AllowOverride None
Options FollowSymLinks
</Directory>

In Listing 2, the configuration enclosed in the Directory and /Directory tags is applied to the given directory and everything under it — in this case, the root directory. Here, the AllowOverride tag dictates that users aren't allowed to override any options (more on this later). The FollowSymLinks option is enabled, which lets Apache look past symlinks to serve the request, even if the file is outside the directory containing Web files. This means that if a file in your Web directory is a symlink to /etc/passwd, the Web server happily serves the file if asked. With -FollowSymLinks used instead, this feature is disabled, and the same request causes an error to be returned to the client.

This last scenario is a cause for concern on two fronts. The first is a performance matter. If FollowSymLinks is disabled, then Apache must check each component of the filename (directories and the file itself) to make sure they're not symbolic links. This incurs extra overhead in the form of disk activity. A companion option called FollowSymLinksIfOwnerMatch follows the symbolic link if the owner of the file is the same as that of the link. This has the same performance hit as disabling following of symlinks. For best performance, use the options in Listing 2.

Security-conscious readers should be alert by now. Security is always a trade-off between functionality and risk. In this case, the functionality is speed, and the risk is allowing unauthorized access to files on the system. One of the mitigations is that LAMP application servers are generally dedicated to a particular function, and users can't create the potentially dangerous symbolic links. If it's vital to have symbolic link-checking enabled, you can restrict it to a particular area of the file system, as in Listing 3.


Listing 3. Restricting FollowSymLinks to a user's directory
                
<Directory />
Options FollowSymLinks
</Directory>

<Directory /home/*/public_html>
Options -FollowSymLinks
</Directory>

In Listing 3, any public_html directory in a user's home directory has the FollowSymLinks option removed for it and any child directories.

As you've seen, options can be configured on a per-directory basis through the main server configuration. Users can override this server configuration themselves (if permitted by the administrator by the AllowOverrides statement) by dropping a file called .htaccess into a directory. This file contains additional server directives that are loaded and followed on each request to the directory where the .htaccess file resides. Despite the earlier discussion about not having users on the system, many LAMP applications use this functionality to control access and for URL rewriting, so it's wise to understand how it works.

Even though the AllowOverrides statement prevents users from doing anything you don't want them to, Apache must still look for the .htaccess file to see if there is any work to be done. A parent directory can specify directives that are to be processed by requests from child directories, which means Apache must also search each component of the directory tree leading to the requested file. Understandably, this causes a great deal of disk activity on each request.

The easiest solution is to not allow any overrides, which eliminates the need for Apache to check for .htaccess. Any special configurations are then placed directly in httpd.conf. Listing 4 shows the additions to httpd.conf to enable password checking for a user's project directory, rather than putting in a .htaccess file and relying on AllowOverrides.


Listing 4. Moving .htaccess configuration into httpd.conf

                
<Directory /home/user/public_html/project/>
AuthUserFile /home/user/.htpasswd
AuthName "uber secret project"
AuthType basic
Require valid-user
</Directory>

If the configuration is moved into httpd.conf and AllowOverrides is disabled, disk usage can be reduced. A user's project may not attract many hits, but consider how powerful this technique is when applied to a busy site.

Sometimes it's not possible to eliminate use of .htaccess files. For example, in Listing 5, where an option is restricted to a certain part of the file system, overrides can also be scoped.


Listing 5. Scoping .htaccess checking
                
<Directory />
AllowOverrides None
</Directory>

<Directory /home/*/public_html>
AllowOverrides AuthConfig
</Directory>

After you implement Listing 5, Apache still looks for .htaccess files in the parent directories, but it stops in the public_html directory because the rest of the file system has the functionality disabled. For example, if a file that maps to /home/user/public_html/project/notes.html is requested, only the public_html and project directories are searched.

One final note about per-directory configurations is in order. Any document about tuning Apache will tell you to disable DNS lookups through the HostnameLookups off directive because trying to reverse-resolve every IP address connecting to your server is a waste of resources. However, any limitations based on hostname force the Web server to perform a reverse lookup on the client's IP address and a forward lookup on the result of that to verify the authenticity of the name. Therefore, it's wise to avoid using access controls based on the client's hostname and to scope them as described when they're necessary.

Persistent connections

When a client connects to a Web server, it's allowed to issue multiple requests over the same TCP connection, which reduces the latency associated with multiple connections. This is useful when a Web page refers to several images: The client can request the page and then all the images over one connection. The downside is that the worker process on the server has to wait for the session to be closed by the client before it can move on to the next request.

Apache lets you configure how persistent connections, called keepalives, are handled. KeepAlive 5 at the global level of httpd.conf allows the server to handle 5 requests on a connection before forcing the connection closed. Setting this number to 0 disables the use of persistent connections. KeepAliveTimeout, also at the global level, determines how long Apache will wait for another request before closing the session.

Handling persistent connections isn't a one-size-fits-all configuration. Some Web sites fare better with keepalives disabled (KeepAlive 0), and some experience a tremendous benefit by having them on. The only solution is to try both and see for yourself. It's advisable, though, to use a low timeout such as 2 seconds with KeepAliveTimeout 2 if you enable keepalives. This ensures that any client wishing to make another request has ample time, and that worker processes aren't idling while waiting for another request that may never come.

Compression

The Web server can compress the output before it's sent back to the client. This results in a smaller page being sent over the Internet at the expense of CPU cycles on the Web server. For those servers that can afford the CPU overhead, this is an excellent way of making pages download faster — it isn't unheard of for pages to be a third of their size after compression.

Images are generally already compressed, so compression should be limited to text output. Apache provides compression through mod_deflate. Although mod_deflate can be simple to turn on, it includes many complexities that the manual is eager to explain. This article doesn't cover the configuration of compression except to provide a link to the appropriate documentation (see the Resources section.)


Tuning PHP

PHP is the engine that runs the application code. You should install only the modules you plan to use and have your Web server configured to use PHP only for script files (usually those ending in .php) and not all static files.

Opcode caching

When a PHP script is requested, PHP reads the script and compiles it into what's called Zend opcode, a binary representation of the code to be executed. This opcode is then executed by the PHP engine and thrown away. An opcode cache saves this compiled opcode and reuses it the next time the page is called. This saves a considerable amount of time. Several opcode caches are available; I've had a great deal of success with eAccelerator.

Installing eAccelerator requires the PHP development libraries on your computer. Because different Linux distributions place files in difference places, it's best to get the installation instructions directly from the eAccelerator Web site (see the Resources section for a link). It's also possible that your distribution has already packaged an opcode cache, and you just have to install it.

Regardless of how you get eAccelerator on your system, there are a few configuration options to look at. The configuration file is usually /etc/php.d/eaccelerator.ini. eaccelerator.shm_size defines the size of the shared memory cache, which is where the compiled scripts are stored. The value is in megabytes. Determining the proper size depends on your application. eAccelerator provides a script to show the status of the cache, which includes the memory usage; 64 megabytes is a good start (eaccelerator.shm_size="64"). You may also have to tweak your kernel's maximum shared memory size if the value you choose isn't accepted. Add kernel.shmmax=67108864 to /etc/sysctl.conf, and run sysctl -p to make the setting take effect. The value for kernel.shmmax is in bytes.

If the shared memory allocation is exceeded, eAccelerator must purge old scripts from memory. By default, this is disabled; eaccelerator.shm_ttl = "60" specifies that when eAccelerator runs out of shared memory, any script that hasn't been accessed in 60 seconds should be purged.

Another popular alternative to eAccelerator is the Alternative PHP Cache (APC). The makers of Zend also have a commercial opcode cache that includes an optimizer to further increase efficiency.

php.ini

You configure PHP in php.ini. Four important settings control how much system resources PHP can consume, as listed in Table 1.


Table 1. Resource related settings in php.ini
Setting Description Recommended value
max_execution_time 
How many CPU-seconds a script can consume 30
max_input_time How long (seconds) a script can wait for input data 60
memory_limit How much memory (bytes) a script can consume before being killed 32M
output_buffering How much data (bytes) to buffer before sending out to the client 4096

These numbers depend mostly on your application. If you accept large files from users, then max_input_time may have to be increased, either in php.ini or by overriding it in code. Similarly, a CPU- or memory-heavy program may need larger settings. The purpose is to mitigate the effect of a runaway program, so disabling these settings globally isn't recommended. Another note on max_execution_time: This refers to the CPU time of the process, not the absolute time. Thus a program that does lots of I/O and few calculations may run for much longer than max_execution_time. It's also how max_input_time can be greater than max_execution_time

The amount of logging that PHP can do is configurable. In a production environment, disabling all but the most critical logs saves disk writes. If logs are needed to troubleshoot a problem, you can turn up logging as needed. error_reporting = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR turns on enough logging to spot problems but eliminates a lot of chatter from scripts.


Summary

This article focused on tuning the Web server, both Apache and PHP. With Apache, the general idea is to eliminate extra checks the Web server must do, such as processing the .htaccess file. You must also tune the Multi-Processing Module you're using to balance the system resources used with the availability of idle workers for incoming requests. The best thing you can do for PHP is to install an opcode cache. Keeping your eye on a few resource settings also ensures that scripts don't hog resources and make the system slow for everyone else.

The next and final article in this series will look at tuning the MySQL database. Stay tuned!


Resources

more..