linux find 사용기

Linux 2018. 8. 23. 11:49
SMALL

리눅스에서 파일 검색을 하기 위한 명령어 find를 소개합니다.

저는 리눅스 상에서 주로 개발해서 자주 사용하는 명령어 입니다.



명령어 : find 파일 찾을 위치 지정 -name 찾을 파일 이름

    ex  : find ./ -name aaa.txt


위에 ex를 설명해드리면 ./(현재 폴더 부터, 하위 폴더 포함) aaa.txt 파일을 찾아줘!!! 입니다.




다음으로 파일 내부 문자열을 검색하는 명령어 grep 입니다.


사실 grep은 여러군데서 사용하고 있는 것이기 때문에, 파일 내부 문자열 검색만을 위해서 쓰이고 있지는 않습니다.

grep의 man을 보시면 -print lines matching a pattern 으로 나와있어요.


이번 포스팅에서는 grep을 통해서 파일 내부의 문자열을 검색해서, 

찾고자 하는 문자열과 동일한 문자열을 가진 파일을 찾아주는 것으로 


명령어 : grep -r "찾을 문자열" ./*

     ex : grep -r "aaa" ./*

        

위의 ex를 설명드리면 ./(현재 폴더 아래 모든 파일에서) aaa라는 문자열이 있는지 찾아라!! 하위 디렉토리 모두에서(-r) 입니다.

여기서 r은 recursive 의미입니다.



출처: http://ngee.tistory.com/83 [ngee]

LIST

'Linux' 카테고리의 다른 글

리눅스 명령어 모음  (0) 2015.06.24
리눅스 파일 찾기 (파일명 검색)  (0) 2015.06.24
linux 파일만들기, 파일옮기기,이동,복사하기  (0) 2015.03.19
ubuntu apt 패키지 삭제  (0) 2015.03.17
linux hdd mount 하기  (0) 2015.03.16
블로그 이미지

SeoHW

,

리눅스 명령어 모음

Linux 2015. 6. 24. 10:26
SMALL

Linux 명령어

 

uname -a     버젼정보보기

pwd          현재위치보기

nl <파일>     numberline

vi -> :set nu   라인넘버보기

ls --help

mkdir -p <디렉토리/디렉토리>     하위디렉토리포함 만들기

rmdir <디렉토리>     디렉토리지우기

touch <파일>     파일만들기 또는 현재날자로 수정

clear         화면지우기

cp -f <파일> <파일>      //-f:묻지않음, -r:하위디렉토리포함

rm -rf <디렉토리>     디렉토리지우기

mv <디렉토리> .      이동

ln <파일1> <파일2>     hardlink 2->1

ln -s <파일1> <파일2> softlink 2->1

echo $PATH      PATH보기

PATH=$PATH:\root/디렉토리     path추가

who am I     내정보보기

cat -n <파일>     라인번호

more, less      b: back, /단어: 검색

cat file1 > file2     redirection 표준출력

cat file1 >> file2     Append 추가

rpm -qa | grep <파일>     현재컴퓨터에 설치된 프로그램중 <파일>만출력

cal 월 년 | mail 주소     달력출력후 메일로 보내기

ps -ef | grep <파일>     실행중 프로세스중 <파일>만 출력

wc <파일>     라인 단어 문자 파일명

rpm -qa | wc -l     개수

bc     계산기

alias     별칭보기(ls -al == ll)

alias c='clear'     추가

history     !번호

useradd <계정>     계정추가

passwd <계정>      비밀번호

ps1='[\d  \t  \!] [\w]  \n  \\$'

    날짜 시간 명령어번호 현재경로 새로운라인

.bashrc     초기설정값저장, alias, ps1입력해서 전역변수화, 다음로그인시 설정값저장


ftp <주소>

ftp> pwd: server경로,     !pwd: client경로, !ls

ftp>get <파일>    다운로드

ftp>mget <*>    여러파일 다운로드

ftp>? <명령어>     설명

ftp>bye     끝

ftp>put <파일>     업로드

ftp>mput <a*>     여러파일 업로드

ftp>prompt      Interactive mode off/on


chsh -l     내시스템이 사용중인 쉘종류

cat -n /etc/shells

echo $SHELL     현재사용중인 쉘

env     환경변수 보기

chsh     /bin/ash(쉘종류)     shell change

gzip -1v <파일>     숫자클수록 압축률상승 속도저하

gunzip <파일>     파일명.gz 압축하기

tar xvfz <파일.tar.gz>     풀기


mount     현재마운트된 상태

df -h     파티션정보, 마운트정보

mount -t ext3 </dev/hda8> </apm>

mount -t iso9660 /dev/cdrom /mnt/cdrom/        cdrom마운트

umount </apm>

mkfs -t ext3 </dev/hda8>     파티션포멧

/etc/fstab     filesystem정보담긴 파일

/etc/inittab     runlevel 설정파일

  id:5:initdefault:     3:일반텍스트모드, 5:xwindow모드부팅

/etc/grub.conf     groub설정파일

vi -> se nu     번호붙이기


※ Kernel Compile

1. 커널 다운로드후 /usr/src  이동후 압축해제

2. /linux 이동

3. make mrproper     커널환경초기화

4. make xconfig/menuconfig

5. make dep     의존성 구축

6. make clean    필요없는 모듈제거

7. make bzImage     새로운 커널 이미지마듬

8. make modules

9. make modules_install

10. arch/i386/boot/bzImage  -> /boot로 이동

11. grub에서 설정


rpm -qa | grep ftp | wc -l

rpm -e --nodeps  <package name> 의존성무시 강제삭제

rpm -ivh <package name>   설치

rpm -Uvh     업그레이드

(core 먼저설치, standalone 나중설치)

 

/proc    시스템정보   meminfo, cpuinfo, swaps, interrupts, IRQ정보

top    현재 프로세스 사용상태 실시간

ps -A   실행중 프로세스     -ef 자세히

pstree

killall <프로세스이름>   프로세스 죽이기


useradd <계정>

passwd <계정>

/etc/passwd

/etc/shadow

finger <계정>   정보보기

chfn <계정>    정보수정

usermod -s(쉘변경) /bin/zsh(쉘위치) <계정> ;   -g(그룹변경) <그룹명> <계정>

userdel -r <계정>     homedirectory삭제

/etc/group

groupadd <그룹명>

/etc/default/useradd     홈디렉토리변경가능

useradd -G <그룹> <계정>

groups <계정>     이계정의 소속그룹 확인

chgrp <그룹명> <디렉토리>     디렉토리 소유그룹을 <그룹명>으로 변경

chown <계정명> <파일명>

chown <계정.그룹> <파일> 계정,그룹동시변경 가능

chmod 777 <파일>   r:4, w:2, x:1

 

gcc -o <만들파일이름> <소스파일.c>

./configure   (--prefix=/디렉토리)   (기본=/usr/local)

make   컴파일

make clean   에러발생시

make install

 

shutdown -h now   (-r: reboot)


host -l <domain name>   그 도메인의 IP주소출력

traceroute microsoft.com

 

find / -name "filename"    (-perm, -user)

find . -name "*.txt" | xargs grep [-option] hello   -> hello문자열을 포함한 파일 찾기

[option]

-l: 파일리스트만 보여주기, -i: 찾는 문자열 대소문자 구분하지 않기, -r: find쓰지 않고 특정디렉토리 이하 모두 검색

 

which <명령어>

whereis <명령어>

 

/var/log/dmesg     ->커널이 부팅시 하드웨어 검색하는 메세지

/var/log/messages   ->커널과 시스템에 관련된 로그 메세지

 

service networ [옵션]

redhat-config-network

ifconfig

vi /etc/sysconfig/network     기본 호스트에 대한 정보

vi /etc/sysconfig/network-scripts/ifcfg-eth0     이더넷카드설정

vi /etc/resolv.conf          DNS설정

 

/etc/init.d/network restart   (또는 /etc/rc.d/init.d/network)   네트워크재시작

LIST

'Linux' 카테고리의 다른 글

linux find 사용기  (0) 2018.08.23
리눅스 파일 찾기 (파일명 검색)  (0) 2015.06.24
linux 파일만들기, 파일옮기기,이동,복사하기  (0) 2015.03.19
ubuntu apt 패키지 삭제  (0) 2015.03.17
linux hdd mount 하기  (0) 2015.03.16
블로그 이미지

SeoHW

,
SMALL

현재 디렉토리에서, pl 확장자를 가진 모든 파일 찾기

find -name '*.pl'


(현재 디렉토리 밑의 하위 디렉토리까지 다 찾습니다.)


루트에서부터, 즉 전체 하드에서, pl 확장자를 가진 모든 파일 찾기

find / -name '*.pl'




전체 하드 디스크에서, 파일명이 ab 로 시작하는 모든 파일 찾기

find / -name 'ab*'




전체 하드 디스크에서, 파일명이 .bash 로 시작하는 모든 파일 찾기

find / -name '.bash*'




전체 하드 디스크에서, 파일명이 .bash 로 시작하는 모든 파일 찾기
+ ls 명령 형식으로 출력

find / -name '.bash*' -ls


뒤에 -ls 라는 옵션을 붙이면 됩니다.




디렉토리명 찾기


전체 하드 디스크에서, 디렉토리 이름이 et 로 시작하는 모든 디렉토리 찾기

find / -name 'et*' -type d



주의! 옵션 순서를 바꾸면 에러가 납니다.

LIST

'Linux' 카테고리의 다른 글

linux find 사용기  (0) 2018.08.23
리눅스 명령어 모음  (0) 2015.06.24
linux 파일만들기, 파일옮기기,이동,복사하기  (0) 2015.03.19
ubuntu apt 패키지 삭제  (0) 2015.03.17
linux hdd mount 하기  (0) 2015.03.16
블로그 이미지

SeoHW

,
SMALL

mv

mv는 이름변경 이동을 담당하는 명령어이다.

 

형식) mv 원본파일 대상파일

 

예를들어 test.txt 라는 파일이 있다고 치고 나는 /home 디렉토리로 옮기고싶다.

하면 mv test.txt /home 이런식으로 적으면 test.txt 파일이 /home 디렉토리로 이동하게 된다.

( 물론 원래 현재 디렉토리에 있던 test.txt은 없어지게 된다. ) 

 

만약에 mv test.txt test1.txt 라고 하면,

test1.txt 라는 파일은 원래 없기때문에 자연스럽게 test.txt란 파일은 사라지고 test1.txt로 남게된다.

즉, 이름 변경이 가능하다는 뜻이다.

 

 

cp

 

cp는 파일이나 디렉토리를 다른 파일 또는 다른 디렉토리로 복사(Copy)를 수행한다.

 

형식) cp 원본파일 대상파일

 

예를들어 test.txt 라는 파일이 있다고 치고 /home 디렉토리에 복사해서 내용이 같은 파일을

복사하고 싶다면 cp test.txt /home 이런식으로 적으면 test.txt 파일은 그대로 있되

/home 디렉토리에도 또다른 test.txt 파일이 내용똑같은 상태에서 저장하게 된다.

 

또는 cp test.txt test2.txt 이런식으로 하면 test.txt 내용이 똑같이 복사된 test2.txt를

생성하게 된다.

 

옵션)

-a : 원본 파일의 속성, 링크 파일 정보를 유지하며 복사

-b : 파일이 존재할 경우 기존 파일을 백업

-d : 복사할 원본이 심볼릭 링크일 때 심볼릭 링크 자체를 복사

-f : 복사할 대상이 있으면 강제로 지우고 복사

-i : 복사할 대상이 있으면 강제로 지우고 복사

-r : 디렉토리 복사할 때 사용

-v : 복사 과정 자세히 출력

-u : 복사할 대상의 변경 날짜가 같거나 더 최근 것이면 복사하지 않음

 

옵션 예 ) cp -r 디렉토리명1 디렉토리명2

 

 

자, 그럼 실습을 통해 이해하기 쉽게 알아보자.

 

 

 

mv 명령 실습

 

 

 

 

 

cp 명령 실습

 

 

 

 

내용 저장시 당연히 콜론상태에서 wq 해줘야하는거 잊지않기

 

옵션을 이용해서 응용해 스스로 실습하는 시간을 가져보길 바란다.

LIST

'Linux' 카테고리의 다른 글

리눅스 명령어 모음  (0) 2015.06.24
리눅스 파일 찾기 (파일명 검색)  (0) 2015.06.24
ubuntu apt 패키지 삭제  (0) 2015.03.17
linux hdd mount 하기  (0) 2015.03.16
ubuntu Postgresql password변경  (0) 2015.03.10
블로그 이미지

SeoHW

,

ubuntu apt 패키지 삭제

Linux 2015. 3. 17. 14:50
SMALL

우분투(Ubuntu)에서 패키지를 관리하는 명령어가 몇가지 있습니다. 그 중 가장 기본이 되는 것이 apt-get입니다. 많은 옵션이 있는데, 자주 쓰는 몇가지를 정리해보겠습니다.

apt-get update

패키지 목록을 갱신합니다.

apt-get upgrade

모든 패키지를 최신 버전으로 업그레이드합니다.

apt-get install abc

abc 패키지를 설치합니다.

apt-get remove abc

abc 패키지를 삭제합니다. 설정파일은 삭제하지 않습니다.

apt-get purge abc

abc 패키지를 삭제합니다. remove와 다르게 설정파일도 삭제합니다.

참고로 패키지 검색은 apt-cache로 합니다. abc라는 단어를 포함한 패키지를 검색하려면 

apt-cache search abc

와 같이 하면 됩니다.

apt-get 명령어의 사용법과 옵션은

apt-get -h

으로 알아낼 수 있습니다. 결과는 다음과 같습니다.

apt 0.8.16~exp12ubuntu10.12 for i386 compiled on Jul 16 2013 18:00:58
Usage: apt-get [options] command
       apt-get [options] install|remove pkg1 [pkg2 ...]
       apt-get [options] source pkg1 [pkg2 ...]

apt-get is a simple command line interface for downloading and
installing packages. The most frequently used commands are update
and install.

Commands:
   update - Retrieve new lists of packages
   upgrade - Perform an upgrade
   install - Install new packages (pkg is libc6 not libc6.deb)
   remove - Remove packages
   autoremove - Remove automatically all unused packages
   purge - Remove packages and config files
   source - Download source archives
   build-dep - Configure build-dependencies for source packages
   dist-upgrade - Distribution upgrade, see apt-get(8)
   dselect-upgrade - Follow dselect selections
   clean - Erase downloaded archive files
   autoclean - Erase old downloaded archive files
   check - Verify that there are no broken dependencies
   changelog - Download and display the changelog for the given package
   download - Download the binary package into the current directory

Options:
  -h  This help text.
  -q  Loggable output - no progress indicator
  -qq No output except for errors
  -d  Download only - do NOT install or unpack archives
  -s  No-act. Perform ordering simulation
  -y  Assume Yes to all queries and do not prompt
  -f  Attempt to correct a system with broken dependencies in place
  -m  Attempt to continue if archives are unlocatable
  -u  Show a list of upgraded packages as well
  -b  Build the source package after fetching it
  -V  Show verbose version numbers
  -c=? Read this configuration file
  -o=? Set an arbitrary configuration option, eg -o dir::cache=/tmp
See the apt-get(8), sources.list(5) and apt.conf(5) manual
pages for more information and options.
                       This APT has Super Cow Powers.
LIST

'Linux' 카테고리의 다른 글

리눅스 파일 찾기 (파일명 검색)  (0) 2015.06.24
linux 파일만들기, 파일옮기기,이동,복사하기  (0) 2015.03.19
linux hdd mount 하기  (0) 2015.03.16
ubuntu Postgresql password변경  (0) 2015.03.10
ubuntu JDK install  (0) 2015.03.05
블로그 이미지

SeoHW

,

linux hdd mount 하기

Linux 2015. 3. 16. 13:42
SMALL

linux hdd mount 하기


디스크가 인식되었는지 확인합니다.
$ sudo fdisk -l


파티션 할당합니다.
$ sudo fdisk /dev/sdb1

m 눌러서 명령을 봅니다.

n 눌러서 파티션을 추가합니다.

p 파티션 생성

파티선 생성이 끝나면

 

w 눌러서 저장합니다.

리부팅 합니다.

파티션을 포맷합니다.  (파티션을 하나로 잡았을경우)
$ sudo mkfs.ext3 /dev/sdb1

마운트할 디렉토리를 만듭니다.
$ sudo mkdir /pub

마운트 합니다.
$ sudo mount /dev/sdb1 /pub


자동 마운트 설정을 추가합니다.
$ sudo vi /etc/fstab

다음 부분 추가합니다.
/dev/sdb1 /pub ext3 defaults,errors=remount-rw 0 1

 

 

 

 

* 요즘은 UUID로 입력한는 경우가 많습니다

 

UUID 확인

$ ls -l /dev/disk/by-uuid

 

자동 마운트 설정을 추가합니다.
$ sudo vi /etc/fstab

다음 부분 추가합니다.
UUID='UUID' /마운트할/폴더명 ext3 defaults 0 1

LIST
블로그 이미지

SeoHW

,
SMALL

ubuntu Postgresql password변경


sudo -u postgres psql postgres

# \password postgres

Enter new password: 사용할 비밀번호


LIST

'Linux' 카테고리의 다른 글

ubuntu apt 패키지 삭제  (0) 2015.03.17
linux hdd mount 하기  (0) 2015.03.16
ubuntu JDK install  (0) 2015.03.05
Tomcat의 logging.properties 및 디렉토리설정  (0) 2015.02.12
Ubuntu Tomcat install  (0) 2015.02.12
블로그 이미지

SeoHW

,

ubuntu JDK install

Linux 2015. 3. 5. 16:42
SMALL

1. apt-get 으로 openjdk 설치

 

기본적으로 Ubuntu에서 지원하는 apt를 가지고 설치를 할 수 있습니다.

apt 로 설치할 수 있는 항목은 openjdk입니다.

 

Ubuntu Desktop 버전에서는 우분투 소프트웨어 센터에서 UI 화면을 보면서 설치할 수 있습니다.

 

터미널에서는 아래와 같이 명령을 주면 됩니다.

 

$ sudo apt-get install openjdk-7-jdk

 

openjdk 도 jdk 역할을 하지만, oracle에서 제공하는 jdk를 사용하는 분들은 아래와 같이 진행하면 됩니다.

 

 

2. apt-get 으로 oracle-java7 jdk 설치하기

 

apt-get 으로 oracle에서 제공하는 jdk를 설치하려면 아래와 같이 하면 됩니다.

 

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java7-installer

 

.

LIST

'Linux' 카테고리의 다른 글

linux hdd mount 하기  (0) 2015.03.16
ubuntu Postgresql password변경  (0) 2015.03.10
Tomcat의 logging.properties 및 디렉토리설정  (0) 2015.02.12
Ubuntu Tomcat install  (0) 2015.02.12
Linux 방화벽 포트열기  (0) 2015.02.12
블로그 이미지

SeoHW

,
SMALL

 

 

 Tomcat 의 log 관련설정법입니다.

 

많은 개발자들이 개발환경으로 Tomcat 을 많이 사용하고 있습니다. 그리고 log 처리는 log4j를 사용합니다.

그러나 JDK에서 기본으로 제공하는 Logging 클래스도 꽤 쓸만한 기능을 제공하고 있습니다.


java.util.logging 추상 클래스가 바로 그것인데요, 이 클래스를 상속받아 구현한 클래스를 줄여서 JULI 라고 부릅니다. 

 

운영시에야 효율을 위해 최소한의 로그를 남기는것이 좋겠지만, 반대로 개발시에는 최대한의 많은 로그를 남기는것이 디버깅에 효과적입니다.

 

1. logging.properties의 위치

 a) 기본적인 Global 설정은 tomcat 디렉토리의 conf 입니다.

  - 이곳에 파일을 두고 설정하면 해당 컨테이너에 등록되는 모든 Application설정을 한방에 할수 있습니다.

 b) Application 별로 설정하고 싶다면, /WEB-INF/classes/ 밑에 logging.properties 를 두면 됩니다.

 

2. 설정방법

- 기본적으로 제공하는 핸들러는 java.util.logging.FileHandler 와 java.util.logging.ConsoleHandler 가 있습니다.

- java.util.logging.ConsoleHandler 는 기본출력 (catalina.out)으로 출력하는 핸들러이고,

- java.util.logging.FileHandler 는 날짜별로 롤링되는 특정파일에 출력하는 핸들러입니다.

- level 은 다음과 같이 ALL, FINEST, FINER, FINE, CONFIG, INFO, WARNING, SEVERE를 지원하며

- 오늘쪽으로 갈수록 로그량이 적습니다.

 

3. 설정예제

- org.apache.tomcat.util.net.TcpWorkerThread 클래스에 대해서 로그를 추가하고 싶을때

ex)
org.apache.tomcat.util.net.TcpWorkerThread.level = ALL
org.apache.tomcat.util.net.TcpWorkerThread.handler = java.util.logging.ConsoleHandler

 

- org.apache.tomcat.util.net 하위 클래스에 대해서 로그를 추가하고 싶을때

ex)
org.apache.tomcat.util.net.level = ALL
org.apache.tomcat.util.net.handler = java.util.logging.ConsoleHandler

 

이런식으로 로깅하고 싶은 클래스 또는 패키지를 지정해서 .level = XXX , .handler = java.util.logging.ConsoleHandler 를 달아주기만 하면 됩니다.

 

참 쉽죠~?


출처 - http://cafe.naver.com/hermeneus.cafe?iframe_url=/ArticleRead.nhn%3Farticleid=98&

 

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

 

 

tomcat 로그 저장 위치 변경 하기

 

tomcat logs 디렉토리(${catalina.base}/logs)에 저장되는 로그는 아래와 같은 곳에서 설정이 가능합니다.

 

- catalina.out 

  ${catalina.base}/bin/catalina.sh

 

- host-manager, localhost, manager

  ${catalina.base}/conf/logging.properties

 

- localhost_access_log

  ${catalina.base}/conf/server.xml

 

 

로그 저장 위치를 원하는 곳으로 변경 하는 방법은 두가지로 생각해 볼 수 있습니다.

 

첫번째는 logging.properies, catalina.sh, server.xml 등에서 디렉토리를 변경하는 방법이고

두번째는 ${catalina.base}/logs 디렉토리를 원하는 디렉토리로 soft link 시키는 방법입니다.

 

 

1. 각 설정에서 logging 디렉토리 변경

# vi /usr/local/tomcat/conf/logging.properties

 

변경 전

 

1catalina.org.apache.juli.FileHandler.level = FINE

1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs

1catalina.org.apache.juli.FileHandler.prefix = catalina.


변경 후

 

1catalina.org.apache.juli.FileHandler.level = FINE

1catalina.org.apache.juli.FileHandler.directory = /var/log/tomcat

1catalina.org.apache.juli.FileHandler.prefix = catalina.

 

 

# vi /user/local/tomcat/bin/catalina.sh

 

변경 전

 

if [ -z "$CATALINA_OUT" ] ; then

  CATALINA_OUT="$CATALINA_BASE"/logs/catalina.out

fi

 

변경 후

if [ -z "$CATALINA_OUT" ] ; then

  CATALINA_OUT=/var/log/tomcat/catalina.out

fi

 

 

 

# vi /user/local/tomcat/conf/server.xml

 

변경 전

 

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt"

pattern="%h %l %u %t &quot;%r&quot; %s %b" />

 

 

변경 후

 

<Valve className="org.apache.catalina.valves.AccessLogValve" directory="/var/log/tomcat" prefix="localhost_access_log." suffix=".txt"

pattern="%h %l %u %t &quot;%r&quot; %s %b" />

 

 

 

2. ${catalina.base}/logs 디렉토리를 원하는 디렉토리로 soft link 

# ln -s /var/log/tomcat /usr/local/tomcat/logs

LIST

'Linux' 카테고리의 다른 글

ubuntu Postgresql password변경  (0) 2015.03.10
ubuntu JDK install  (0) 2015.03.05
Ubuntu Tomcat install  (0) 2015.02.12
Linux 방화벽 포트열기  (0) 2015.02.12
리눅스 vi 명령어모음  (0) 2015.02.12
블로그 이미지

SeoHW

,

Ubuntu Tomcat install

Linux 2015. 2. 12. 14:41
SMALL

How To Install Apache Tomcat 7 on Ubuntu 14.04 via Apt-Get

Author: Mitchell Anicas Published: Apr 18, 2014 Updated: May 30, 2014

About Apache Tomcat

Apache Tomcat is an application server that is used to serve Java applications to the web. Tomcat is an open source implementation of the Java Servlet and JavaServer Pages technologies, released by the Apache Software Foundation.

This tutorial covers the basic installation and some configuration of Tomcat 7.0.x, the latest stable version at the time of writing, on your Ubuntu 14.04 VPS.

There are two basic ways to install Tomcat on Ubuntu:

  • Install through apt-get. This is the simplest method.

  • Download the binary distribution from the Apache Tomcat site. This guide does not cover this method; refer to Apache Tomcat Documentation for instructions.

For this tutorial, we will use the simplest method: apt-get. Please note that this will install the latest release of Tomcat that is in the official Ubuntu repositories, which may or may not be the latest release of Tomcat. If you want to guarantee that you are installing the latest version of Tomcat, you can always download the latest binary distribtion.

Step One — Prerequisites

Before you begin with this guide, you should have a separate, non-root user account set up on your server. You can learn how to do this by completing steps 1-4 in the initial server setup for Ubuntu 14.04. We will be using the demo user created here for the rest of this tutorial.

Step Two - Install Tomcat

The first thing you will want to do is update your apt-get package lists:

sudo apt-get update

Now you are ready to install Tomcat. Run the following command to start the installation:

sudo apt-get install tomcat7

Answer yes at the prompt to install tomcat. This will install Tomcat and its dependencies, such as Java, and it will also create the tomcat7 user. It also starts Tomcat with its default settings.

Tomcat is not completely set up yet, but you can access the default splash page by going to your domain or IP address followed by :8080 in a web browser:

http://your_ip_address:8080

You will see a splash page that says "It works!", in addition to other information. Now we will go deeper into the installation of Tomcat.

Step Three - Installing Additional Packages

Note: This section is not necessary if you are already familiar with Tomcat and you do not need to use the web management interface, documentation, or examples. If you are just getting into Tomcat for the first time, please continue.

With the following command, we will install the Tomcat online documentation, the web interface (manager webapp), and a few example webapps:

sudo apt-get install tomcat7-docs tomcat7-admin tomcat7-examples

Answer yes at the prompt to install these packages. We will get into the usage and configuration of these tools in a later section. Next, we will install the Java Development Kit.

Step Four - Install Java Development Kit (Optional)

If you are planning on developing apps on this server, you will want to be sure to install the software in this section.

The Java Development Kit (JDK) enables us to develop Java applications to run in our Tomcat server. Running the following command will install openjdk-7-jdk:

sudo apt-get install default-jdk

In addition to JDK, the Tomcat documentation suggests also installing Apache Ant, which is used to build Java applications, and a source control system, such as git. Let's install both of those with the following command:

sudo apt-get install ant git

For more information about Apache Ant, refer to the official manual. For a tutorial on using git, refer to DigitalCloud's Git Tutorial.

Step 5 - Configure Tomcat Web Management Interface

In order to use the manager webapp installed in Step 3, we must add a login to our Tomcat server. We will do this by editing the tomcat-users.xml file:

sudo nano /etc/tomcat7/tomcat-users.xml

This file is filled with comments which describe how to configure the file. You may want to delete all the comments between the following two lines, or you may leave them if you want to reference the examples:

<tomcat-users>
</tomcat-users>

You will want to add a user who can access the manager-gui and admin-gui (the management interface that we installed in Step Three). You can do so by defining a user similar to the example below. Be sure to change the password and username if you wish:

<tomcat-users>
    <user username="admin" password="password" roles="manager-gui,admin-gui"/>
</tomcat-users>

Save and quit the tomcat-users.xml file. To put our changes into effect, restart the Tomcat service:

sudo service tomcat7 restart

Step 6 - Access the Web Interface

Now that we've configured an admin user, let's access the web management interface in a web browser:

http://your_ip_address:8080

You will see something like the following image:

As you can see, there are four links to packages you installed in Step Three:

  • tomcat7-docs: Online documentation for Tomcat. Accessible via http://your_ip_address:8080/docs/
  • tomcat7-examples: Tomcat 7 Servlet and JSP examples. You can click through the example webapps to get a basic idea of how they work (and also look at the source code to see how they were implemented). Accessible via http://your_ip_address:8080/examples/
  • tomcat7-admin (manager-webapp): Tomcat Web Application Manager. This will allow you to manage and your Java applications.
  • tomcat7-admin (host-manager): Tomcat Virtual Host Manager.

Let's take a look at the Web Application Manager, accessible via the link or http://your_ip_address:8080/manager/html:

The Web Application Manager is used to manage your Java applications. You can Start, Stop, Reload, Deploy, and Undeploy here. You can also run some diagnostics on your apps (i.e. find memory leaks). Lastly, information about your server is available at the very bottom of this page.

Now let's take a look at the Virtual Host Manager, accessible via the link or http://your_ip_address:8080/host-manager/html/:

From the Virtual Host Manager page, you can add virtual hosts to serve your applications in.

Finished!

Your installation of Tomcat is complete! Your are now free to deploy your own webapps!

By Mitchell Anicas
LIST

'Linux' 카테고리의 다른 글

ubuntu JDK install  (0) 2015.03.05
Tomcat의 logging.properties 및 디렉토리설정  (0) 2015.02.12
Linux 방화벽 포트열기  (0) 2015.02.12
리눅스 vi 명령어모음  (0) 2015.02.12
Jetty 9 설치방법  (0) 2015.02.12
블로그 이미지

SeoHW

,