리눅스, 네트워크

메일서버 - 서버에 메일시스템 설치하기

베노 2025. 1. 10. 00:13

서버에 메일 시스템에서 사용하는 소프트웨어를 설치한다

우선 우리는 자바를 설치해야 한다. 우리가 사용할 메일 소프트웨어는 자바기반으로 동작하는 소프트웨어를 사용할 것이기에 자바언어를 설치해야 한다. 공식문서에 따르면 본인들은 openJDK11버전으로 테스트했는데 깔쌈하게 작동한다고 하였으니 우리도 11버전으로 사용해야 한다. 이게 좀 까다롭다

JDK는 자바의 개발 툴이 모두 묶여있는 모음집이다. 이 JDK는 여러가지의 버전이 있으며 특정 버전에서는 지원하는 함수가 있을수도 있고 없을수도 있으니 일단 공식문서로 따라가야 한다

여기서 사용하는 서버(운영체제)는 리눅스의 데비안 - 우분투를 사용할 것이다

sudo apt-get install openjdk-11-jdk

sudo : 관리자 권한으로 실행하겠다는 명령어
apt-get : 리눅스 데비안 계열의 패키지 관련 명령어
패키지명령어는 해당 프로그램 및 소프트웨어를 설치하거나 삭제할 때 자동으로 시스템이 환경설정과 나머지 설정을 자동으로 설정해준다
install : 해당 패키지를 설치한다
openjdk-11-jdk : 리눅스 데비안 계열의 패키지 서버라는것이 존재하는데 이 서버에서 여러가지 소프트웨어들이 등록되어있다. 그 서버에서 openjdk-11-jdk라는 이름을 가진 소프트웨어를 검색해 설치한다는 뜻이다

 

이러면 해당 서버에 openjdk 11버전이 설치되며 경로 및 설정 또한 자동으로 설정이 된다. 이때 설치되는 경로는 /usr/lib/jvm/java-11-openjdk-amd64에 설치된다

위 경로에 대한거는 리눅스를 공부하는 사람이라면 알고있겠지만, 만약 리눅스에 대해 기초적인게 없다면 리눅스부터 공부해야 한다,

 

그 다음 환경변수를 설정해야 한다

우리가 어떠한 프로그램(+언어)이나 소프트웨어를 설치하면 설치한 경로로 꼭 들어가서 실행해야만 작동이 된다.

하지만 매번 그 경로로 들어가서 작업하기에는 큰 어려움이 있다. 자바언어를 사용하는 프로그램 같은 경우는 그 프로그램을 아예 뜯어서 소스코드를 수정해야 하는 더러운 일이 있다. 하지만 환경변수를 이용하면 경로를 넣어줄 필요가 없고, 시스템 어디서나 접근이 가능하게끔 시스템이 알아서 해당 경로로 이동시켜 작동하게 해 준다.

 

sudo vim ./~bashrc

vim : 파일 편집기

./~ : 홈 디렉터리

bashrc : 환경변수를 수정할 수 있는 파일 명

이렇게 사용자 디렉터리 안에 bashrc라는 파일을 열면 아래왜 같이 코드들이 있을거다

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
	# We have color support; assume it's compliant with Ecma-48
	# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
	# a case would tend to support setf rather than setaf.)
	color_prompt=yes
    else
	color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
#    . /etc/bash_completion
#fi

 

이제 이 코드안에서 적어주면 되는데 아래와 같이 해당 코드 맨 아래에 작성하면 된다.

# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples

# If not running interactively, don't do anything
[ -z "$PS1" ] && return

# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace

# append to the history file, don't overwrite it
shopt -s histappend

# for setting history length see HISTSIZE and HISTFILESIZE in bash(1)
HISTSIZE=1000
HISTFILESIZE=2000

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# make less more friendly for non-text input files, see lesspipe(1)
[ -x /usr/bin/lesspipe ] && eval "$(SHELL=/bin/sh lesspipe)"

# set variable identifying the chroot you work in (used in the prompt below)
if [ -z "$debian_chroot" ] && [ -r /etc/debian_chroot ]; then
    debian_chroot=$(cat /etc/debian_chroot)
fi

# set a fancy prompt (non-color, unless we know we "want" color)
case "$TERM" in
    xterm-color) color_prompt=yes;;
esac

# uncomment for a colored prompt, if the terminal has the capability; turned
# off by default to not distract the user: the focus in a terminal window
# should be on the output of commands, not on the prompt
#force_color_prompt=yes

if [ -n "$force_color_prompt" ]; then
    if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then
	# We have color support; assume it's compliant with Ecma-48
	# (ISO/IEC-6429). (Lack of such support is extremely rare, and such
	# a case would tend to support setf rather than setaf.)
	color_prompt=yes
    else
	color_prompt=
    fi
fi

if [ "$color_prompt" = yes ]; then
    PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
unset color_prompt force_color_prompt

# If this is an xterm set the title to user@host:dir
case "$TERM" in
xterm*|rxvt*)
    PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"
    ;;
*)
    ;;
esac

# enable color support of ls and also add handy aliases
if [ -x /usr/bin/dircolors ]; then
    test -r ~/.dircolors && eval "$(dircolors -b ~/.dircolors)" || eval "$(dircolors -b)"
    alias ls='ls --color=auto'
    #alias dir='dir --color=auto'
    #alias vdir='vdir --color=auto'

    alias grep='grep --color=auto'
    alias fgrep='fgrep --color=auto'
    alias egrep='egrep --color=auto'
fi

# some more ls aliases
alias ll='ls -alF'
alias la='ls -A'
alias l='ls -CF'

# Alias definitions.
# You may want to put all your additions into a separate file like
# ~/.bash_aliases, instead of adding them here directly.
# See /usr/share/doc/bash-doc/examples in the bash-doc package.

if [ -f ~/.bash_aliases ]; then
    . ~/.bash_aliases
fi

# enable programmable completion features (you don't need to enable
# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
# sources /etc/bash.bashrc).
#if [ -f /etc/bash_completion ] && ! shopt -oq posix; then
#    . /etc/bash_completion
#fi
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$PATH:$JAVA_HOME/bin

해당 코드는 우선 JAVA_HOME이라는 이름에 openjdk 경로를 지정해준다 위 경로는 openjdk가 설치되어있는 경로이다

이제 리눅스 시스템이 자바라는걸 바로 사용하기 위해 시스템변수인 PATH에 미리 저장했던 JAVA_HOME을 불러와서 bin폴더의 자바의 핵심적인걸 꺼내서 할당해주면 되는거다.

 

이렇게 진행 후 아래와 같이 명령어로 환경변수가 잘 적용되었는지 확인하면 된다.

사진과 같이 java -version을 하면 자바의 버전이 나오면 성공이다.

원래 이 명령어는 /usr/lib/jvm/java-11-openjdk-amd64/bin 디렉터리 안에 java라는 파일이 있는데 여기까지 들어가서 java라는 파일을 통해 버전을 확인해야 했다

 

이렇게 환경변수를 지정해주면 자바가 설치된 경로까지 안들어가도 자바관련 명령어나 필요한것들을 꺼내서 쓸 수 있다

 

 

자바 설치가 끝났다면 이제 메일 시스템을 가동하기 위한 소프트웨어를 설치하면 된다

여기서 보통의 경우는 postfix나 dovocot을 설치해서 메일 수/발신을 진행하는데 우리는 그런거 말고 다른거를 사용할 거다

 

 


Aache JAMES


이름에서 알듯이 아파치 제단에서 제작한 자바기반 메일 서버를 사용할거다

JAMES는 Java Apache Mail Enterprise Server의 약자로 자바기반으로 동작하는 메일 시스템이다.

구구절절 설명해봤다 사진이 없으면 설명하는 나도 힘들고 이해할려는 어린이들도 힘들거다

여기서 작성하는 명령어나 설정은 GUI기반이 아닌 CLI기준으로 설명한다

우선 해당 메일서버를 가동하기 위해 아파치에서 만들어준 소프트웨어를 리눅스에 다운해야 한다

하지만 GUI가 아니기 떄문에 마우스로 딸깍딸깍 할 수 없다 그래서 링크로 통해 다운받게 해줘야 해서 아래와 같은 패키지가 필요하다

sudo apt-get install curl -y
sudo apt-get install unzip -y

curl : 패키지 서버에서 curl이라는 패키지를 다운 받는다 해당 패키지는 url만 있다면 파일을 다운받을 수 있다 james는 zip파일로 서버에 공유하고 있어서 해당 zip파일의 url을 따와서 리눅스로 설치할 수 있다

unzip : 리눅스에서 zip파일을 압축을 할 수 있게 해주는 패키지이다. 압축해제라는 개념은 알고있기에 대충 넘어가겠다

 

sudo curl -O https://archive.apache.org/dist/james/server/3.7.5/james-server-spring-app-3.7.5-app.zip

링크에서 알다시피 james의 3.7.5 버전으로 다운 받으면 된다 그러면 zip파일로 파일이 하나 생길거다

 

하지만 zip파일이기 떄문에 얘를 압출을 풀어줘야 한다

sudo unzip james-server-spring-app-3.7.5-app.zip

unzip명령어로 james-server-spring-app-3.7.5-app.zip라는 압축파일을 압축해제해준다

그러면 아래와 같은 폴더와 파일이 나온다

날짜가 작년이지만, 그래도 안에 내용물은 바뀌지 않았을거다

파일 구조는 아래와 같다

bin : James를 구동시키기 위해 쉘파일들이 있다.

conf : James를 구성하기 위해 각종 설정 파일들이 있다.

lib : James를 구동과 구성하기 위해 각종 자바 라이브러리들이 있다.

log : James 구동 후 일어나는 로그들을 다 저장시켜 주는 곳이다.

sieve : 몰라요

var : 몰라요~

이렇게 구조가 이뤄져있고 하나씩 설정을 하면서 설명을 할거다

 

설정방법은 다음글에서 상세하게 하는게 좋을거같아서 글을 줄일려고 한다

메일 구동을 하기 위해 항상 투자해야하는게 꽤 많다 최근 구동을 해봤으니 난 할수있을거라는 믿음과 확신을 가지고 글을 작성할거다

아마 글이 오래 안올라오면 내가 하다가 실패한거라고 알고 있어줬음 좋겠다.

'리눅스, 네트워크' 카테고리의 다른 글

네트워크 - 서버 업그레이드  (3) 2025.07.31
네트워크 구축 1  (0) 2025.06.01
메일서버 - 이론 기반 준비  (1) 2025.01.05
메일서버 - 설정 및 구동하기  (1) 2024.04.20
메일서버 - 시작하기  (1) 2024.03.24