우분투 16.04 서버 세팅

by DDART posted Jul 22, 2016
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

루트 비번 설정 

 

sudo passwd root
su

 

apt 패키지 DB 업데이트 및 시스템 업그레이드

 

apt-get update
apt-get upgrade

 

네트워크 시간 맞추기

 

apt-get install ntp ntpdate
date

 

타임존 변경

 

timedatectl set-timezone 'Asia/Seoul'

 

 

호스트네임 변경

 

hostnamectl set-hostname server

 

 

/etc/hosts 에 로컬주소 추가

127.0.0.1   localhost
127.0.0.1   server

 

 

 

 

LAMP 설치 (Linux Apache, MySQL/MariaDB, PHP)

 

1. Apache

 

설치

 

apt-get install apache2
apache2 -v

 

모듈 enable, disable

 

a2enmod deflate expires headers rewrite ssl
a2ensite default-ssl
a2dismod -f autoindex

 

모듈 설치 multiuser module

 

apt-get install libapache2-mpm-itk

 

보안설정

 

 vi /etc/apache2/apache2.conf

# deny file, folder start with dot
<DirectoryMatch "^\.|\/\.">
        Require all denied
</DirectoryMatch>
# 이 부분 추가 
# deny (log file, binary, certificate, shell script, sql dump file) access.
<FilesMatch "\.(log|binary|pem|enc|crt|conf|sql|sh)$">
        Require all denied
</FilesMatch>
 
# deny access.
<FilesMatch "(pp_cli|pp_cli_x64|LICENSE|README\.md|composer\.json|COPYRIGHT|CONTRIBUTING\.md|LICENSE\.txt)$">
        Require all denied
</FilesMatch>
 

 

vi /etc/apache2/conf-available/charset.conf

문자셋을 UTF-8로 바꾸고

vi /etc/apache2/conf-available/security.conf

추가보안설정한다.

 

 

2. PHP

 

설치

 

apt-get install libapache2-mod-php7.0
php -v

 

모듈

 

apt-get install php-mcrypt php-mbstring php-gd php-curl php-mysql php-cli php-apcu php7.0-xml

 

 

php.ini 수정

 

vi /etc/php/7.0/apache2/php.ini
vi /etc/php/7.0/cli/php.ini
 

date.timezone = Asia/Seoul

 

 

3. Mariadb (mysql GPL 버전, 사용법 동일)

 

설치

 

apt-get install mariadb-server

 

 

DB초기화

 

/usr/bin/mysql_secure_installation

#

 

사용자 추가

 

mysql> use mysql;
mysql> create user 사용자ID;
mysql> create user 사용자ID@localhost identified by '비밀번호';
mysql> grant all privileges on db이름.* to 사용자ID@localhost identified by '비밀번호';
mysql> flush privileges;

 

 

home 권한변경 및 웹사이트 www 디렉토리 지정

 

chmod 711 /home
chmod -R 700 /home/*

 

일반 유저계정으로

 

mkdir /home/사용자/www

 

virtual host 설정은

/etc/apache2/sites-available 디렉토리에 각각의 도메인명이름으로 conf파일을 카피등으로 생성한후 수정하고

 

<VirtualHost *:80>
    ServerName ddart.net
    DocumentRoot /home/ddart/www/ddart.net
    <Directory /home/ddart/www/ddart.net>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>


    AssignUserID ddart ddart

    ErrorLog ${APACHE_LOG_DIR}/ddart.net-error.log
    CustomLog ${APACHE_LOG_DIR}/ddart.net-access.log combined
</VirtualHost>

 

 

a2ensite 명령을 주면 sites-enabled 디렉토리에 심볼릭 링크가 걸려 설정파일이 적용된다.

 

a2ensite 도메인명

 

 


FTP 서버 설치

 

apt-get install vsftpd

 

vi /etc/vsftpd.conf

 

# 주석제거
wirte_enables=YES 

 

서비스 재시작

 

service vsftpd restart

 

 

Samba 서버 설치

 

설치

 

apt-get install samba samba-common cifs-utils

 

 

설정

 

 vi /etc/samba/smb.conf

#======================= Share Definitions =======================

[ddart]
commnet = ddart's home
path = /home/ddart
valid users = ddart
writable = yes
create mask = 0644
directory mask = 0755

 

삼바 비번 설정 및 재시작

 

smbpasswd -a ddart
service smbd restart

 

 

웹관련 파일들 ftp나 삼바 네크워크 공유로 전송

 

DB 백업파일로 DB 복구

 

백업

 

mysqldump -u아이디 -p DB명 > 백업파일.sql

 

복구

 

mysql -u아이디 -p DB명 < 백업파일.sql

 

fail2ban 설치

 

설치

 

apt-get install fail2ban

 

 

설정

 

vi /etc/fail2ban/jail.conf

 

# "ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not
# ban a host which matches an address in this list. Several addresses can be
# defined using space separator.
ignoreip = 127.0.0.1/8 192.168.0.1/16 관리PCIP/24

# External command that will take an tagged arguments to ignore, e.g. <ip>,
# and return true if the IP is to be ignored. False otherwise.
#
# ignorecommand = /path/to/command <ip>
ignorecommand =

# "bantime" is the number of seconds that a host is banned.
bantime  = 86400

 

 

웹서비스 재시작

 

service apache2 restart